def place_stop_loss(symbol, side, qty, stop_price):
response = session.place_active_order(
symbol=symbol,
side=side,
order_type='Market',
qty=qty,
stop_loss=stop_price,
time_in_force='GoodTillCancel'
)
if response['ret_code'] == 0:
print(f"Stop-loss set at {stop_price} for {symbol}")
else:
print(f"Error setting stop-loss: {response['ret_msg']}")
return response
place_stop_loss('BTCUSD', 'Buy', 0.01, 29000) # Buy 0.01 BTC with stop-loss at $29,000
This function places a stop-loss order at $29,000 for a buy order of 0.01 BTC.