如何在交易平台上实施止损单?

时间:2019-05-24 11:07:08

标签: algorithm performance trading

我正在使用交易平台。现在,我需要实现止损订单功能


说明:

假设当前BTC / USD的市场价格为7900,您的账户中有4 BTC。

您认为,当市场价格跌破7700以下时,它将继续下跌。

您在7700下了止损市价单,以防止进一步损失。因此,如果市场价格跌至7500,您节省了4 *(7700-7500)= 800 USD

这只是停止订单的一种用例,但您明白了。


我的问题是:“有没有比以下解决方案更好的解决方案?”

这是我的实现方式:

1. The real orders are stored in the “orders” table/collection

2. All the stop orders are stored in “stop_orders” table/collection with some fields: side (BUY, SELL), stop price, limit price, amount,
    stop_direction,…

3. When a trade is formed (2 orders are matched), get the matched price and fire an event to the observer HandleStopOrders

4. With the matched price, query the “stop_orders” table/collection to find all stop orders that need to be triggered (by matching side,
    stop price, stop direction)

5. ForEach the result set of stop orders, with each stop order, create a real limit/market order and put to “orders”
    table/collection (not stop_orders)

我认为这可行,但是问题是性能。

假设我们每交易0.5秒(在波动期中,交易量更大),这意味着系统每交易0.5s必须查询“ stop_orders”,然后查询结果集。

0 个答案:

没有答案