sammchardy / python-binance

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

Cannot create a stoploss/takeprofit order on futures market #752

Open TheSeacfr opened 3 years ago

TheSeacfr commented 3 years ago

Hello,

I am trying to create stoploss/takeprofit orders using the API on Python but it seems like it is not working with futures. Indeed, I have opened a long position on testnet and then tried:

client.futures_create_order(symbol='BTCUSDT', side=SIDE_SELL, type=ORDER_TYPE_STOP_LOSS, timeInForce=TIME_IN_FORCE_GTC, quantity=qty , stopPrice='%f' % (price))

But it gives an error "BinanceAPIException: APIError(code=-1116): Invalid orderType.". As I have seen that the enums.py file has been modified a few days ago, I have tried:

client.futures_create_order(symbol='BTCUSDT', side=SIDE_SELL, type=FUTURE_ORDER_TYPE_STOP_MARKET, timeInForce=TIME_IN_FORCE_GTC, quantity=qty , stopPrice='%f' % (price))

But it gives an error "NameError: name 'FUTURE_ORDER_TYPE_STOP_MARKET' is not defined"

Could you please help me with that ?

Thanks !

wolfox33 commented 3 years ago

def OrderBuy(lot, stop): order = client.futures_create_order( symbol='ETHUSDT', side= Client.SIDE_BUY, type = Client.ORDER_TYPE_MARKET, quantity=lot)

price = float(client.futures_symbol_ticker(symbol = 'ETHUSDT')['price'])
orderstop= client.futures_create_order(
    symbol='ETHUSDT',
    side= Client.SIDE_SELL,
    type = 'STOP_MARKET',
    stopLimitTimeInForce='GTC',
    stopPrice = price-stop,
    closePosition= True,
    quantity=lot)