binance-us / binance-us-api-docs

Official Documentation for the Binance US APIs and Streams
410 stars 169 forks source link

binance rest api place TRAILING_STOP_MARKET order activatePrice being ignored #132

Closed asafd11 closed 1 year ago

asafd11 commented 1 year ago

i have a function to set a TRAILING_STOP_MARKET order the function works the order being place but my activatePrice is not the number am sending i set it to 0.9918 and on binance it set it to 0.9841 i try to change the number of activatePrice and the callbackRate it did not seem to have an effect on the activatePrice i used this docs to make the function:https://binance-docs.github.io/apidocs/futures/en/#query-current-open-order-user_data anyone know why my activateprice being ignored or being set to value different then what am sending heres the function:

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

values:

'symbol':'TOMOUSDT'
'side':'SELL'
'quantity':24.0
'callbackRate':0.1
'activatePrice':0.9918
'reduceOnly':True
'type':'TRAILING_STOP_MARKET'
'timestamp':1693069060070
asafd11 commented 1 year ago

activationPrice not activatePrice