1

I'm running an algorithm to predict prices and enter trades for me using the ccxt API in python. I wish to execute a trailing stop loss order and I enter such a long position like this:

exchange = ccxt.binance({
    'enableRateLimit': True,
    'apiKey': '*****',
    'secret': '*****'
})

exchange.load_markets()

exchange.create_order('MKR/USDT, 'TRAILING_STOP_MARKET', 'buy', exchange.fetch_balance()['USDT']['free']/exchange.fetch_ticker('MKR/USDT)['last'], None, params = {'callbackRate': 1})

but I get the following error:

ccxt.base.errors.InvalidOrder: binance TRAILING_STOP_MARKET is not a valid order type in spot market MKR/USDT

I'm not sure why thought because I'm pretty sure binance supports trailing stop loss orders (it says so in its own API documentation).

CS1994
  • 143
  • 2
  • 7

2 Answers2

5

Binance does not support the TRAILING_STOP_MARKET order type with spot markets (which is the default with CCXT):

Binance only supports the TRAILING_STOP_MARKET order type with futures-markets:

If you want to switch to the Binance futures API with CCXT you can do the following:

exchange = ccxt.binance({
    'enableRateLimit': True,
    'apiKey': '*****',
    'secret': '*****'
    'options': {
        'defaultType': 'future',  # or 'delivery' for COIN-M futures
    },
})

exchange.load_markets()

exchange.create_order('MKR/USDT, 'TRAILING_STOP_MARKET', 'buy', exchange.fetch_balance()['USDT']['free']/exchange.fetch_ticker('MKR/USDT)['last'], None, params = {'callbackRate': 1})
Igor Kroitor
  • 1,548
  • 13
  • 16
1

Binance REST API doesn't support TRAILING_STOP_MARKET, see "Order types" in the Enum definitions.

If you want to simulate a trailing stop order, you'll need to subscribe to the trade stream and keep recalculating your stop price. When the current market price reaches the stop price, submit a new order.

Petr Hejda
  • 40,554
  • 8
  • 72
  • 100