def place_stop_trail_order(symbol,side,quanitity,callbackrate,activateprice):
symbol =symbol # Replace with the trading pair symbol
side = side # 'BUY' or 'SELL'
quantity = quanitity # Replace with the quantity
callbackRate =callbackrate # Price rate for trailing stop
activatePrice = activateprice # Activation price for trailing stop
reduceOnly = True # Set to True to make the order reduce-only
trailType = 'TRAILING_STOP_MARKET' # Type of trailing stop
endpoint="/fapi/v1/order"
timestamp = int(time.time() * 1000)
params = {
'symbol': symbol,
'side': 'SELL' if side == 'long' else 'BUY',
'quantity': quantity,
'callbackRate': callbackRate,
'activatePrice': activatePrice,
'reduceOnly': reduceOnly,
'type': trailType,
'timestamp': timestamp,
}
query_string = '&'.join([f"{key}={params[key]}" for key in params])
signature = hmac.new(api_secret.encode(), query_string.encode(), hashlib.sha256).hexdigest()
headers = {
'X-MBX-APIKEY': api_key,
}
data = {
'symbol': symbol,
'side': 'SELL' if side == 'long' else 'BUY',
'quantity': quantity,
'callbackRate': callbackRate,
'activatePrice': activatePrice,
'reduceOnly': reduceOnly,
'type': trailType,
'timestamp': timestamp,
'signature': signature,
}
response = requests.post(base_url + endpoint, headers=headers, data=data)
if response.status_code == 200:
print("TRAILING_STOP order placed successfully!")
print(response.json())
data=response.json()
return data
else:
print(f"Failed to place TRAILING_STOP order. Status code: {response.status_code}")
print(response.json())
data=response.json()
return data
'symbol':'TOMOUSDT'
'side':'SELL'
'quantity':24.0
'callbackRate':0.1
'activatePrice':0.9918
'reduceOnly':True
'type':'TRAILING_STOP_MARKET'
'timestamp':1693069060070