sammchardy / python-binance

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

Creating continuous margin order with borrowing fails #777

Open susemeee opened 3 years ago

susemeee commented 3 years ago

Describe the bug Creating margin order with borrowing asset (sideEffectType=MARGIN_BUY) returns 3007 error from Binance

To Reproduce Code snippet to reproduce the behavior:


caller = Client(key, secret)

def margin_sell(ticker, amount):
    return caller.create_margin_order(
        symbol=ticker,
        side=binance_enums.SIDE_BUY,
        type=binance_enums.ORDER_TYPE_MARKET,
        # https://binance-docs.github.io/apidocs/spot/en/#margin-account-new-order-trade
        sideEffectType="AUTO_REPAY",
        quantity=amount,
    )

# successful transaction
print(margin_sell(ticker="ETHBTC", amount=0.005))
time.sleep(4.9)
# fails (binance.exceptions.BinanceAPIException: APIError(code=-3007): You have pending transcation, please try again later)
print(margin_sell(ticker="ETHBTC", amount=0.005))

Expected behavior Both of the trade should be created successfully.

Environment (please complete the following information):

Logs or Additional context I think the problem is on Binance's side(not actually client's bug), so I am going to report this issue to them as well. Creating this issue here to share further information.

Really weird thing is that the transaction goes well if I wait 5 or more seconds between transactions. I could not find related information for the wait time from Binance API docs.

vicbg123 commented 3 years ago

Hi, Just wondering if you got the above issue fixed and how. I am getting a similar one and I still haven't found a way to go around it... Thanks in advance.