下面是通过设置'stop_loss_on_fill”参数来下达尾随止损订单的示例代码:
import ccxt
exchange = ccxt.binance({
'apiKey': 'YOUR_API_KEY',
'secret': 'YOUR_SECRET_KEY'
})
symbol = 'BTC/USDT'
amount = 1
price = 50000
stop_loss_price = 46000
trailing_stop_percentage = 1
order = exchange.create_order(
symbol=symbol,
type='limit',
side='buy',
amount=amount,
price=price,
params={
'stop_loss': stop_loss_price,
'stop_loss_on_fill': True,
'trail_stop_percent': trailing_stop_percentage
}
)
print(order)
其中,设置"stop_loss_on_fill"参数为True可以实现尾随止损,"trail_stop_percent"参数表示相对于当前价格的百分比来设置止损价格。但需要注意的是,该函数可能不适用于所有交易所和订单类型。