Sell limit closed before the price is reached

Hi everyone,
I’m new to this world and I’m trying to understand some things…

I have two questions inherent in the same problem:

Question 1:
I noticed several times that creating a SELL LIMIT order with Python:

from binance.client import Client

client = Client('API KEY', 'APY SECRET', testnet=True)

sell_order = client.create_order(
symbol=self.crypto_to_trade,
side='SELL',
type='LIMIT',
timeInForce=time_in_force,
quantity=qty,
price=price
)

Often these Sell Limits are closed even if the market price has not arrived at the price indicated for the limit.

Looking into the price historian:

bars = client.get_historical_klines(self.trade_crypto, interval, timestamp, limit=1000)

I noticed that the Sell Limits close when the price is reached by high-price values.
Is this behavior a testnet bug? Or do it also occur in the real environment?

Question 2:
I noticed the same error a few times on the BUY MARKET, buying at a certain price, I found my order executed at a much higher market price:

bought when the market was at: 36400.67
Buy returns a purchase price to: 40620.87

I wonder if all this is normal or if it is a testnet bug, which never occurs in the real environment?

Thank you in advance those who can give me an answer.
I look forward to comments

Hi there, we don’t manage python-binance, not fully familiar with its methods, so for more efficient help here, please write the request, response and the market price with the raw information.

What’s the full request url of the order creation?
Status of the order when you query the order id? https://binance-docs.github.io/apidocs/spot/en/#query-order-user_data

Same questions as above. Plus, response for order creation request.

Hi Aisling
can you help me more??


The full request Url is https://testnet.binance.vision/ with this POST on /api/v3/order (HMAC SHA256)

For Example: Sell Limit with sell limit price set to 36582.20000000

Status Order response:

[{'symbol': 'BTCUSDT', 'orderId': 6034367, 'orderListId': -1, 'clientOrderId': '7pLZ3Gen1BpqP9LqSScoYX', 'price': '36582.20000000', 'origQty': '0.00329900', 'executedQty': '0.00329900', 'cummulativeQuoteQty': '120.68467780', 'status': 'FILLED', 'timeInForce': 'GTC', 'type': 'LIMIT', 'side': 'SELL', 'stopPrice': '0.00000000', 'icebergQty': '0.00000000', 'time': 1624990465589, 'updateTime': 1624994050119, 'isWorking': True, 'origQuoteOrderQty': '0.00000000'}]


Order INFO:

market price with the raw information: {'e': 'trade', 'E': 1624990463783, 's': 'BTCUSDT', 't': 938895601, 'p': '36271.11000000', 'q': '0.02876100', 'b': 6682807915, 'a': 6682808145, 'T': 1624990463782, 'm': True, 'M': True}

[INFO] - ---------- BUY ORDER -----------
[INFO] - order id: 6034364
[INFO] - order price: 36271.12
[INFO] - money invested: 119.65842488
[INFO] - crypto buy quote: 0.00329900
[INFO] - ----------------------------------------------
[INFO] - ---------- SELL LIMIT ORDER -----------
[INFO] - order id: 6034367
[INFO] - order price: 36582.2
[INFO] - ----------------------------------------------
[DEBUG] - correct buy qty: 0.003299


Price INFO at Closed Sell :

market price with the raw information: {'e': 'trade', 'E': 1624994058474, 's': 'BTCUSDT', 't': 938958900, 'p': '36336.98000000', 'q': '0.00027700', 'b': 6683266009, 'a': 6683266100, 'T': 1624994058473, 'm': True, 'M': True}

[INFO] - ---------- $$$$ $$$$$$$$$ -----------
[INFO] - ---------- SELL PERFORMED -----------
[INFO] - sell order id: 6034367
[INFO] - with sell limit price: 36582.20000000
[INFO] - trader reward: 0.7859098173200045
[INFO] - money amount: 142.96385408046999
[INFO] - ---------- $$$$ $$$$$$$$$ -----------

Thanks for the details!
After your order was filled, didn’t the market @trade stream updated with your order’s price?

Hi Aisilng
thanks to you for the answers!!

I answer your question:
If you mean the API that returns all my orders, then yes the order was present and with the same absurd price of the purchase …

it doesn’t always happen, but sometimes it happens that you buy at very high prices … The last night for example made me orders at the market price of 63,091.4 Dollars

buyId : 131770
buyQty : 0.089102
buyAmount : 5602.52473207
buyPrice : 62877.654060178225    <--------
buyFees : 5.60252473207
executionTimestamp : 02/07/2021-02:16:20    <------
    sellId : 131773
    sellLimitPrice : 63091.44    <-------- auto calculated on the price to have a profit margin

How can it happen that you buy at double the market price?

is it a testnet bug??
…or can it also happen in a real environment?

I would like to know how to avoid this problem or if there is a way to control it, also because in the create order api I only pass these params:
symbol = ‘BTCUSDT’,
side = ‘BUY’,
type = ‘MARKET’,
quantity = qty

Has this happened in the past? to me it occurs quite often.
thanks for the replies

Bye :wink: