sammchardy / python-binance

Binance Exchange API python implementation for automated trading
https://python-binance.readthedocs.io/en/latest/
MIT License
6.02k stars 2.2k forks source link

List of test orders #919

Closed dima-dmytruk23 closed 3 years ago

dima-dmytruk23 commented 3 years ago

I create test order using following code

from decimal import Decimal as D, ROUND_DOWN, ROUND_UP
import decimal

info = client.get_symbol_info(symbol='BNBBTC')
price_filter = float(info['filters'][0]['tickSize'])
ticker = client.get_symbol_ticker(symbol="BNBBTC")
price = float(ticker['price'])
price = D.from_float(price).quantize(D(str(price_filter)))
minimum = float(info['filters'][2]['minQty'])
quant = D.from_float(10.3).quantize(D(str(minimum))) # if quantity >= 10.3/price
try:
    buy_limit = client.create_test_order(
        symbol='BNBBTC',
        side='BUY',
        type='LIMIT',
        timeInForce='GTC',
        quantity=quant,
        price=price)
except BinanceAPIException as e:
    print(e)
except BinanceOrderException as e:
    print(e)

In response I get empty dict.

  1. How can I get id of created orders? Or list of test orders?
  2. How can I get all orders on my test account (testnet)
doubtrageous commented 3 years ago

I know this is a bit old here but figure it might still be worth mentioning. The official docs say that test orders are validated but not sent to the matching engine and intentionally return an empty dictionary. So this is the correct behavior. As noted here: https://github.com/binance-us/binance-official-api-docs/blob/master/rest-api.md#test-new-order-trade

I have a similar concept when I'm paper trading with test strategies and I just create my own order ID in the format of something like: TEST-{SYMBOL}-{UNIX_TIMESTAMP}

You could easily use a UUID generator or something instead of course. As far as the testnet behavior sorry I got nothing. I haven't used it. Though it's possible you're confusing placing a test order on the main network vs. placing an actual order on the test net? They're very different things.