I have an issue when placing OCO Order. The response is: “The relationship of the prices for the orders is not correct.”
An example: I bought 0.031BTC. Using limit order and price: 68101.05. Because the order book does not have enough orders so lastExecuted price is 67901.05. Then I try to set OCO order with values:
Limit Price > Last Price > Stop Price
68185.56. > ??? > 66201.67
The result is “The relationship of the prices for the orders is not correct.”
I just bought at price 67901.05. How the last price can be lower than that? I think that is an issue in test network. Please correct me if I’m wrong or help if this is something what I don’t understand correctly.
It’s true that the Testnet doesn’t have as much orders as in the live exchange order book, as the main goal of the Testnet is testing (giving enough liquidity).
For the error itself, you could request the last price before placing the OCO order to calculate the limit and stop prices and make sure that they’ll respect the rule. You would want to this on the live exchange, so on Testnet side, same precautions should be followed.
Requesting the Last price is a good idea, but the only way to request the latest price that I have found is Websocket market stream. I didn’t find a better way to request it. Do you know is there any other options?
Hmm, I implemented it so that it requests the lastPrice using /API/v3/ticker/24hr endpoint just before setting the OCO order, and if the LastPrice from the endpoint is lower than my current stopLoss it lowers the stoploss under the lastPrice so it should be enough.
Here are my values for example:
BTCUSDT
Limit Price > Last Price > Stop Price
67234.4> 67031.43 >66111.96
I think there might be some other issue. It happens for multiple symbols at the same time and then it might be a day that it does not happen. For example, second after the previous example, the same happens for ETHUSDT
Limit Price > Last Price > Stop Price
3510.38> 3488.62 >3480.27
I’ll implement retry logic now and let’s see if it fixes the issue.