Filled LIMIT BUY / SELL Orders in a websocket / api construct

Hi, im kinda desperate… Im programming my own grid trading bot using this binance-connector: GitHub - binance/binance-connector-python: a simple connector to Binance Public API

My Script places a market order on “BTCUSDT” and calculates the initial limit orders for the grid. Just like in the Binance App. Then I implemented a user data stream for updating my orders and account info. Based on the order updates (“executionReport”) i go for a new exchange.new_order(). In general it works fine, but…

For example: Randomly the BTCUSDT price is at 21600 and i get an order update out of my socket userstream for a new placed BUY order at 21100. To make this happen, a previous SELL order for 21120 has to be filled, so that the buy order at 21100 is placed.

My questions:

  1. Is it possible that a LIMIT BUY Order is placed at 21500 and is filled at 21100 (to generate the 21120 LIMIT SELL order)? Why would my LIMIT BUY Order be filled 400 USDT below my LIMIT BUY price of 21500? Is this normal or a “Bug” of the Testnet? I never had this szenario on the live Binance Trading App.

  2. vice versa i see SELL Orders being filled at a price below the actual price. I guess this came from the place-sell-order - trigger when the websocket tells about an “below price”-filled BUY order update. Is this right? Not that script question - but furthermore a general question about filling BUY / SELL orders.

Im kinda confused, tbh…

Pls halp <3
Niels

This is possible that if the current best sell price is 21100, and you place the BUY LIMIT at 21500, then it will be filled at 21100. The market is offering cheaper price, so your order will be filled with that price, because the SELL order comes to market first. It’s not a bug, it’s how order matching works.

Hey and thanks for your reply. This is correct and maybe i have expressed myself incorrectly. I mean how can the BUY LIMIT Order at 21500 be filled at 21100, when the Symbolprice “BTCUSDT” never hit the 21100 in that time period. The price ranged between 21600 and 21400 but has never fallen to the limit of 21100 in that time period.

And my exchange.new_order(symbol, side,…) function of the binance-connector that triggers the “POST /api/v3/order” is 100% based on my USER_STREAM (/api/v3/userDataStream) with my listenKey.

So the only way in my script to place a new SELL LIMIT Order is when the USER_STREAM tells me about a filled BUY LIMIT Order.

So my problem is, that the USER_STREAM informs me about filled BUY LIMIT Orders far below the current price level. And this is what is confusing me highly…

best regards
Niels

You can share the order details here, mask the order id or client id.
It can be fetched from API endpoint GET /api/v3/order

right now it happens again:

i test my grid bot at 80 usdt orders every 20 usdt range.
right now the btc price is 20.650 usdt and my user_data stream spams filled orders like the one below. (at price: 20040 usdt) how :confused:

order update


order id: 12366519
order creation datetime: 08.26.2022 - 23:49:53
transaction datetime: 08.27.2022 - 00:08:31
side: BUY
order quantity: 0.00399200
order price: 20040.00000000
current execution type: TRADE
current order status: FILLED
last executed quantity: 0.00399200
cumulative filled quantity: 0.00399200
last executed price: 20040.00000000
commission amount: 0.00000000
commission asset: BTC
cumulative quote asset transacted quantity: 79.99968000
last quote asset transacted quantity: 79.99968000
quote order quantity: 0.00000000

i programmed it like this:

init grid with 50 orders.

  1. checking open orders
  2. comparing open_order_list with own placed_order_list
  3. checking missing orderId of open_order_list (has to be filled then)
  4. if filled: create new order based on filled price +/- grid step
  5. little delay
  6. repeat

the websocket user_data stream is just the controlling instance right now. Just 2 mins ago I looked up my open_orders that contains only 18. Now, it has the correct value of 50 again. I didn’t do anything. I’m really confused because a new order will only be placed when the previous order[“status”] = “FILLED” is true.

Right now it is 00:25 o’clock.
Please have a look on the timestamp (it’s coded GMT+2) of filled order: So much happened around 00:01:58 o’clock… Do you have an idea? The posted data is from my user_data stream (Testnet). Of course I don’t have any influence on the websocket user_data stream.

I don’t even know why the last posted order (12369996) is filled with quote asset of 81.37769576 usdt. im placing 80 usdt orders and they get filled with 79.9… (I understand the 79.9… but not the 81…).

I’m full of hope! :slight_smile: Have a nice evening.
regards Niels

order update


order id: 12369899
order creation datetime: 08.27.2022 - 00:01:40
transaction datetime: 08.27.2022 - 00:01:40
side: SELL
order quantity: 0.00387500
order price: 20640.00000000
current execution type: NEW
current order status: NEW
last executed quantity: 0.00000000
cumulative filled quantity: 0.00000000
last executed price: 0.00000000
commission amount: 0
commission asset: None
cumulative quote asset transacted quantity: 0.00000000
last quote asset transacted quantity: 0.00000000
quote order quantity: 0.00000000

27.08.2022 - 00:01:40 - account update


BTC: 0.00067800 (free), 0.07300000 (locked)
USDT: 9.02445663 (free), 2479.77648000 (locked)

order update


order id: 12366596
order creation datetime: 08.26.2022 - 23:50:05
transaction datetime: 08.27.2022 - 00:01:58
side: BUY
order quantity: 0.00388300
order price: 20600.00000000
current execution type: TRADE
current order status: FILLED
last executed quantity: 0.00388300
cumulative filled quantity: 0.00388300
last executed price: 20600.00000000
commission amount: 0.00000000
commission asset: BTC
cumulative quote asset transacted quantity: 79.98980000
last quote asset transacted quantity: 79.98980000
quote order quantity: 0.00000000

order update


order id: 12366595
order creation datetime: 08.26.2022 - 23:50:05
transaction datetime: 08.27.2022 - 00:01:58
side: BUY
order quantity: 0.00388700
order price: 20580.00000000
current execution type: TRADE
current order status: FILLED
last executed quantity: 0.00388700
cumulative filled quantity: 0.00388700
last executed price: 20580.00000000
commission amount: 0.00000000
commission asset: BTC
cumulative quote asset transacted quantity: 79.99446000
last quote asset transacted quantity: 79.99446000
quote order quantity: 0.00000000

order update


order id: 12366594
order creation datetime: 08.26.2022 - 23:50:04
transaction datetime: 08.27.2022 - 00:01:58
side: BUY
order quantity: 0.00389100
order price: 20560.00000000
current execution type: TRADE
current order status: FILLED
last executed quantity: 0.00389100
cumulative filled quantity: 0.00389100
last executed price: 20560.00000000
commission amount: 0.00000000
commission asset: BTC
cumulative quote asset transacted quantity: 79.99896000
last quote asset transacted quantity: 79.99896000
quote order quantity: 0.00000000

order update


order id: 12366589
order creation datetime: 08.26.2022 - 23:50:04
transaction datetime: 08.27.2022 - 00:01:58
side: BUY
order quantity: 0.00389400
order price: 20540.00000000
current execution type: TRADE
current order status: FILLED
last executed quantity: 0.00389400
cumulative filled quantity: 0.00389400
last executed price: 20540.00000000
commission amount: 0.00000000
commission asset: BTC
cumulative quote asset transacted quantity: 79.98276000
last quote asset transacted quantity: 79.98276000
quote order quantity: 0.00000000

order update


order id: 12366588
order creation datetime: 08.26.2022 - 23:50:04
transaction datetime: 08.27.2022 - 00:01:58
side: BUY
order quantity: 0.00389800
order price: 20520.00000000
current execution type: TRADE
current order status: FILLED
last executed quantity: 0.00389800
cumulative filled quantity: 0.00389800
last executed price: 20520.00000000
commission amount: 0.00000000
commission asset: BTC
cumulative quote asset transacted quantity: 79.98696000
last quote asset transacted quantity: 79.98696000
quote order quantity: 0.00000000

order update


order id: 12366587
order creation datetime: 08.26.2022 - 23:50:03
transaction datetime: 08.27.2022 - 00:01:58
side: BUY
order quantity: 0.00390200
order price: 20500.00000000
current execution type: TRADE
current order status: FILLED
last executed quantity: 0.00390200
cumulative filled quantity: 0.00390200
last executed price: 20500.00000000
commission amount: 0.00000000
commission asset: BTC
cumulative quote asset transacted quantity: 79.99100000
last quote asset transacted quantity: 79.99100000
quote order quantity: 0.00000000

order update


order id: 12366584
order creation datetime: 08.26.2022 - 23:50:03
transaction datetime: 08.27.2022 - 00:01:58
side: BUY
order quantity: 0.00390600
order price: 20480.00000000
current execution type: TRADE
current order status: FILLED
last executed quantity: 0.00390600
cumulative filled quantity: 0.00390600
last executed price: 20480.00000000
commission amount: 0.00000000
commission asset: BTC
cumulative quote asset transacted quantity: 79.99488000
last quote asset transacted quantity: 79.99488000
quote order quantity: 0.00000000

order update


order id: 12366581
order creation datetime: 08.26.2022 - 23:50:03
transaction datetime: 08.27.2022 - 00:01:58
side: BUY
order quantity: 0.00391000
order price: 20460.00000000
current execution type: TRADE
current order status: FILLED
last executed quantity: 0.00391000
cumulative filled quantity: 0.00391000
last executed price: 20460.00000000
commission amount: 0.00000000
commission asset: BTC
cumulative quote asset transacted quantity: 79.99860000
last quote asset transacted quantity: 79.99860000
quote order quantity: 0.00000000

order update


order id: 12366579
order creation datetime: 08.26.2022 - 23:50:02
transaction datetime: 08.27.2022 - 00:01:58
side: BUY
order quantity: 0.00391300
order price: 20440.00000000
current execution type: TRADE
current order status: FILLED
last executed quantity: 0.00391300
cumulative filled quantity: 0.00391300
last executed price: 20440.00000000
commission amount: 0.00000000
commission asset: BTC
cumulative quote asset transacted quantity: 79.98172000
last quote asset transacted quantity: 79.98172000
quote order quantity: 0.00000000

order update


order id: 12366578
order creation datetime: 08.26.2022 - 23:50:02
transaction datetime: 08.27.2022 - 00:01:58
side: BUY
order quantity: 0.00391700
order price: 20420.00000000
current execution type: TRADE
current order status: FILLED
last executed quantity: 0.00391700
cumulative filled quantity: 0.00391700
last executed price: 20420.00000000
commission amount: 0.00000000
commission asset: BTC
cumulative quote asset transacted quantity: 79.98514000
last quote asset transacted quantity: 79.98514000
quote order quantity: 0.00000000

order update


order id: 12366573
order creation datetime: 08.26.2022 - 23:50:02
transaction datetime: 08.27.2022 - 00:01:58
side: BUY
order quantity: 0.00392100
order price: 20400.00000000
current execution type: TRADE
current order status: FILLED
last executed quantity: 0.00392100
cumulative filled quantity: 0.00392100
last executed price: 20400.00000000
commission amount: 0.00000000
commission asset: BTC
cumulative quote asset transacted quantity: 79.98840000
last quote asset transacted quantity: 79.98840000
quote order quantity: 0.00000000

order update


order id: 12366572
order creation datetime: 08.26.2022 - 23:50:02
transaction datetime: 08.27.2022 - 00:01:58
side: BUY
order quantity: 0.00392500
order price: 20380.00000000
current execution type: TRADE
current order status: FILLED
last executed quantity: 0.00392500
cumulative filled quantity: 0.00392500
last executed price: 20380.00000000
commission amount: 0.00000000
commission asset: BTC
cumulative quote asset transacted quantity: 79.99150000
last quote asset transacted quantity: 79.99150000
quote order quantity: 0.00000000

order update


order id: 12366571
order creation datetime: 08.26.2022 - 23:50:01
transaction datetime: 08.27.2022 - 00:01:58
side: BUY
order quantity: 0.00392900
order price: 20360.00000000
current execution type: TRADE
current order status: FILLED
last executed quantity: 0.00392900
cumulative filled quantity: 0.00392900
last executed price: 20360.00000000
commission amount: 0.00000000
commission asset: BTC
cumulative quote asset transacted quantity: 79.99444000
last quote asset transacted quantity: 79.99444000
quote order quantity: 0.00000000

order update


order id: 12366567
order creation datetime: 08.26.2022 - 23:50:01
transaction datetime: 08.27.2022 - 00:01:58
side: BUY
order quantity: 0.00393300
order price: 20340.00000000
current execution type: TRADE
current order status: FILLED
last executed quantity: 0.00393300
cumulative filled quantity: 0.00393300
last executed price: 20340.00000000
commission amount: 0.00000000
commission asset: BTC
cumulative quote asset transacted quantity: 79.99722000
last quote asset transacted quantity: 79.99722000
quote order quantity: 0.00000000

order update


order id: 12366565
order creation datetime: 08.26.2022 - 23:50:01
transaction datetime: 08.27.2022 - 00:01:58
side: BUY
order quantity: 0.00393700
order price: 20320.00000000
current execution type: TRADE
current order status: FILLED
last executed quantity: 0.00393700
cumulative filled quantity: 0.00393700
last executed price: 20320.00000000
commission amount: 0.00000000
commission asset: BTC
cumulative quote asset transacted quantity: 79.99984000
last quote asset transacted quantity: 79.99984000
quote order quantity: 0.00000000

order update


order id: 12366564
order creation datetime: 08.26.2022 - 23:50:00
transaction datetime: 08.27.2022 - 00:01:58
side: BUY
order quantity: 0.00394000
order price: 20300.00000000
current execution type: TRADE
current order status: FILLED
last executed quantity: 0.00394000
cumulative filled quantity: 0.00394000
last executed price: 20300.00000000
commission amount: 0.00000000
commission asset: BTC
cumulative quote asset transacted quantity: 79.98200000
last quote asset transacted quantity: 79.98200000
quote order quantity: 0.00000000

order update


order id: 12366563
order creation datetime: 08.26.2022 - 23:50:00
transaction datetime: 08.27.2022 - 00:01:58
side: BUY
order quantity: 0.00394400
order price: 20280.00000000
current execution type: TRADE
current order status: FILLED
last executed quantity: 0.00394400
cumulative filled quantity: 0.00394400
last executed price: 20280.00000000
commission amount: 0.00000000
commission asset: BTC
cumulative quote asset transacted quantity: 79.98432000
last quote asset transacted quantity: 79.98432000
quote order quantity: 0.00000000

order update


order id: 12366558
order creation datetime: 08.26.2022 - 23:50:00
transaction datetime: 08.27.2022 - 00:01:58
side: BUY
order quantity: 0.00394800
order price: 20260.00000000
current execution type: TRADE
current order status: FILLED
last executed quantity: 0.00394800
cumulative filled quantity: 0.00394800
last executed price: 20260.00000000
commission amount: 0.00000000
commission asset: BTC
cumulative quote asset transacted quantity: 79.98648000
last quote asset transacted quantity: 79.98648000
quote order quantity: 0.00000000

27.08.2022 - 00:01:58 - account update


BTC: 0.07115600 (free), 0.07300000 (locked)
USDT: 9.02445663 (free), 1039.94800000 (locked)

order update


order id: 12369996
order creation datetime: 08.27.2022 - 00:01:59
transaction datetime: 08.27.2022 - 00:01:59
side: SELL
order quantity: 0.00394400
order price: 20280.00000000
current execution type: NEW
current order status: NEW
last executed quantity: 0.00000000
cumulative filled quantity: 0.00000000
last executed price: 0.00000000
commission amount: 0
commission asset: None
cumulative quote asset transacted quantity: 0.00000000
last quote asset transacted quantity: 0.00000000
quote order quantity: 0.00000000

order update


order id: 12369996
order creation datetime: 08.27.2022 - 00:01:59
transaction datetime: 08.27.2022 - 00:01:59
side: SELL
order quantity: 0.00394400
order price: 20280.00000000
current execution type: TRADE
current order status: FILLED
last executed quantity: 0.00394400
cumulative filled quantity: 0.00394400
last executed price: 20633.29000000
commission amount: 0.00000000
commission asset: USDT
cumulative quote asset transacted quantity: 81.37769576
last quote asset transacted quantity: 81.37769576
quote order quantity: 0.00000000

I’m giga afraid of putting my live api keys on it as you can imagine x]

→ 29.08.2022 - 12:19 - btc/usdt price: 19828.36

→ 29.08.2022 - 12:24:20 - SELL order 13836560 filled at 19850.0!

It is 12:27 now. since 12:19 the highest price was 19838.49
Why is this limit SELL Order filled? Somebody bought a huge amount via MARKET Order so my Limit SELL Order was filled at better price?

→ 29.08.2022 - 12:26:56 - BUY order 13836535 filled at 19750.0!

Do we have April 1st? xD What is happening here?