I tried several ways.
Unfortunately, it didn't improve.
Then I changed create_new_order() method in the following.
def create_new_order(self, price, exec_type):
stopprice = price - (self.order_type_sign * self.max_range_price)
limitprice = price + (self.order_type_sign * self.interval_price)
self.tradeid_seq +=1
orders = None
if self.order_type == bt.Order.Buy:
# orders = self.buy_bracket(size=self.order_size, price=price, exectype=exec_type,
# # tradeid=self.tradeid_seq,
# stopprice=stopprice, stopexec=bt.Order.Stop,
# limitprice=limitprice, limitexec=bt.Order.Limit)
main_order = self.buy(size=self.order_size, price=price, exectype=exec_type, transmit=False)
stop_order = self.sell(price=stopprice, size=main_order.size, exectype=bt.Order.Stop,
transmit=False, parent=main_order)
limit_order = self.sell(price=limitprice, size=main_order.size, exectype=bt.Order.Limit,
transmit=True, parent=main_order)
orders = [main_order, stop_order, limit_order]
elif self.order_type == bt.Order.Sell:
# orders = self.sell_bracket(size=self.order_size, price=price, exectype=exec_type,
# # tradeid=self.tradeid_seq,
# stopprice=stopprice, stopexec=bt.Order.Stop,
# limitprice=limitprice, limitexec=bt.Order.Limit)
main_order = self.sell(size=self.order_size, price=price, exectype=exec_type, transmit=False)
stop_order = self.buy(price=stopprice, size=main_order.size, exectype=bt.Order.Stop,
transmit=False, parent=main_order)
limit_order = self.buy(price=limitprice, size=main_order.size, exectype=bt.Order.Limit,
transmit=True, parent=main_order)
orders = [main_order, stop_order, limit_order]
return orders
But, it still didn't improve.
There is cases where the order object differs from the actual state.
But then I realized that there is no id of transactions from 1845 to 1847.
Do you have any good solutions in regards to that?
NEW ORDER
( type:Sell, size:300, price:136.18999999999988, exectype:2(Limit), stopprice:146.18999999999988, limitprice:136.13999999999987 )
2020-09-11 19:36:37,706 [ INFO] *****, STORE NOTIF:, {'id': '1844', 'time': '1599820561.598982864', 'userID': 10733067, 'accountID': '101-009-10733067-005', 'batchID': '1844', 'requestID': '24724532290588330', 'type': 'LIMIT_ORDER', 'instrument': 'GBP_JPY', 'units': '-300.0', 'price': 136.19, 'timeInForce': 'GTC', 'positionFill': 'DEFAULT', 'triggerCondition': 'DEFAULT', 'reason': 'CLIENT_ORDER', 'clientExtensions': {'id': '1599755079.86117-565'}, 'takeProfitOnFill': {'price': 136.14, 'timeInForce': 'GTC', 'clientExtensions': {'id': '1599755079.86117-567'}}, 'stopLossOnFill': {'price': 146.19, 'timeInForce': 'GTC', 'clientExtensions': {'id': '1599755079.86117-566'}}}
2020-09-11 19:37:20,039 [ INFO] *****, STORE NOTIF:, Connection to v20 REST server at https://stream-fxpractice.oanda.com:443/v3/accounts/101-009-10733067-005/transactions/stream failed
2020-09-11 19:37:25,790 [ INFO] *****, STORE NOTIF:, Trying to reconnect streaming events (1 of -1)
2020-09-11 19:48:21,639 [ INFO] *****, STORE NOTIF:, {'id': '1848', 'time': '1599821264.782127550', 'userID': 10733067, 'accountID': '101-009-10733067-005', 'batchID': '1848', 'type': 'ORDER_FILL', 'orderID': '1846', 'clientOrderID': '1599755079.86117-567', 'instrument': 'GBP_JPY', 'units': '300.0', 'gainQuoteHomeConversionFactor': '1.0', 'lossQuoteHomeConversionFactor': '1.0', 'price': 136.14, 'fullVWAP': 136.14, 'fullPrice': {'type': 'PRICE', 'bids': [{'price': 136.126, 'liquidity': '250000'}], 'asks': [{'price': 136.14, 'liquidity': '250000'}], 'closeoutBid': 136.117, 'closeoutAsk': 136.149}, 'reason': 'TAKE_PROFIT_ORDER', 'pl': '15.0', 'financing': '0.0', 'commission': '0.0', 'guaranteedExecutionFee': '0.0', 'accountBalance': '3001745.978', 'tradesClosed': [{'tradeID': '1845', 'units': '300.0', 'price': 136.14, 'realizedPL': '15.0', 'financing': '0.0', 'guaranteedExecutionFee': '0.0', 'halfSpreadCost': '2.1'}], 'halfSpreadCost': '2.1'}
2020-09-11 19:48:21,640 [ INFO] *****, STORE NOTIF:, {'id': '1849', 'time': '1599821264.782127550', 'userID': 10733067, 'accountID': '101-009-10733067-005', 'batchID': '1848', 'type': 'ORDER_CANCEL', 'orderID': '1847', 'clientOrderID': '1599755079.86117-566', 'reason': 'LINKED_TRADE_CLOSED'}
2020-09-11 19:48:21,640 [ INFO] *****, STORE NOTIF:, Received external transaction ORDER_CANCEL with id 1849. Skipping transaction.
After this, the status of the previous new order(s) in the following.
Main Order: Accepted
TP Order: Submitted
SL Order: Submitted
Naturally, the main order have already been executed in the market.