5

I try to do that by codes below but I got error

import ccxt  # noqa: E402
import apiConfig

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

symbol = 'RVN/USDT'

type = 'limit'  # or 'market', other types aren't unified yet
side = 'buy'
amount = 69  # your amount
price = 0.21  # your price
# overrides
params = {
    'stopPrice': 0.20,  # your stop price
    'type': 'stopLimit',
}
order = exchange.create_order(symbol, type, side, amount, price, params)

I got this error: ccxt.base.errors.BadRequest: binance {"code":-1106,"msg":"Parameter 'stopPrice' sent when not required."}

kambiz
  • 51
  • 1
  • 3

1 Answers1

4

The ccxt documentation is incorrect in this case (stop limit on Binance, might work with other exchanges).

You need to set the type argument as stop_loss_limit or take_profit_limit (depending on whether price is greater/less than stopPrice). Also, the params.type doesn't override the type value.

type = 'stop_loss_limit'

params = {
    'stopPrice': 0.20,
}

Binance API (docs) accepts the stopPrice param only when the type is one of the following:

  • STOP_LOSS
  • STOP_LOSS_LIMIT
  • TAKE_PROFIT
  • TAKE_PROFIT_LIMIT

And ccxt (GitHub source) sets the uppercaseType only from the function argument type and does not override the value from params.

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