bybit-exchange / pybit

Official Python3 API connector for Bybit's HTTP and WebSockets APIs.
Other
385 stars 129 forks source link

Question about order quantity #150

Closed natanhoffmann closed 1 year ago

natanhoffmann commented 1 year ago

Hey,

I am making spot market orders via the Pybit API. I am experiencing a certain issue. I am trying to make a spot market buy order of 0.001 BTC. In the Pybit API request, the qty parameter must be given in terms of USDT. So I convert from BTC quantity to USDT quantity like so:

bitcoin_quantity = 0.001 usdt_quantity = bitcoin_quantity bitcoin_price usdt_quantity = math.ceil(usdt_quantity 100) / 100

where bitcoin_price is obtained from:

symbol = 'BTCUSDT' exchange = ccxt.bybit() def get_ticker_price(): ticker = exchange.fetch_ticker(symbol) ticker_price = ticker['last'] return ticker_price

Once I send the API request, the buy order fill qty is recorded in BTC. I see in the fill qty a value of 0.000999. Why is it off by 0.000001? I have tried everything. Going mad

Appreciate any advice!

natanhoffmann commented 1 year ago

This was my fault. I shouldn't have been using the ticker price to compute the USDT quantity. Instead I got the best ask price from the Pybit websocket. I'll close.