Issue : A mandatory parameter was not sent, was empty/null, or malformed.

Hello Folks,
I am trying to access Binance Pay API.

And I got the postman collection that generate signature for me.

But when I hit the post request for create order I go this error. A mandatory parameter was not sent, was empty/null, or malformed. Though I have pass all the required parameters.

Can anyone please help me with this issue ?

Thanks.

Please check the Binance Pay document for which parameters are required for the endpoints.

I think these are the mandatory parameters that should be included.

{
   "env":
   {
      "terminalType":"MINI_PROGRAM"
   },
   "merchantTradeNo":"2223",
   "orderAmount": 1.00,
   "currency":"USDT",
   "goods":
   {
      "goodsType":"01",
      "goodsCategory":"0000",
      "referenceGoodsId":"abc001",
      "goodsName":"apple",
      "goodsUnitAmount":
      {
         "currency":"USDT",
         "amount":1.00
      }
   },
   "shipping":
   {
      "shippingName":
      {
         "firstName":"Joe",
         "lastName":"Don"
      },
      "shippingAddress":
      {
         "region":"NZ"
      }
   },
   "buyer":
   {
      "buyerName":
      {
         "firstName":"cz",
         "lastName":"zhao"
      }
   }
}


Nope, still showing that A mandatory parameter was not sent, was empty/null, or malformed.


If any parameters was required then response say that this parameter is required.

have you found any solution?

Maybe is missing “timestamp” or “datetime” ?
I found this, I hope it helps:

Cheers!

once I launch my strategy bot my terminal displays this:
Can anybody help me ?

Traceback (most recent call last):
File “/Users/brandonmbambi/Documents/BOT/bot280524/BOT.py”, line 134, in
main()
File “/Users/brandonmbambi/Documents/BOT/bot280524/BOT.py”, line 91, in main
set_leverage(symbol, leverage)
File “/Users/brandonmbambi/Documents/BOT/bot280524/BOT.py”, line 42, in set_leverage
client.futures_change_leverage(symbol=symbol, leverage=leverage)
File “/Users/brandonmbambi/trading_bot_env/lib/python3.12/site-packages/binance/client.py”, line 6590, in futures_change_leverage
return self._request_futures_api(‘post’, ‘leverage’, True, data=params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/Users/brandonmbambi/trading_bot_env/lib/python3.12/site-packages/binance/client.py”, line 383, in _request_futures_api
return self._request(method, uri, signed, True, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/Users/brandonmbambi/trading_bot_env/lib/python3.12/site-packages/binance/client.py”, line 359, in _request
return self._handle_response(self.response)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/Users/brandonmbambi/trading_bot_env/lib/python3.12/site-packages/binance/client.py”, line 368, in _handle_response
raise BinanceAPIException(response, response.status_code, response.text)
binance.exceptions.BinanceAPIException: APIError(code=-1121): Invalid symbol.
(trading_bot_env) brandonmbambi@MacBook-Pro-3 ~ %

Hey,
Could you please share the symbol you’re including in the request parameters?
Also, for any new issues in the future, kindly create a separate topic.

1 Like

here is the code:

import json
from binance.client import Client
from binance.exceptions import BinanceAPIException

Charger les clés API depuis le fichier de configuration

try:
with open(‘/Users/brandonmbambi/Documents/BOT/bot280524/config.json’) as config_file:
config = json.load(config_file)
except FileNotFoundError:
print(“Erreur : Le fichier config.json est introuvable.”)
exit()

api_key = config[‘api_key’]
api_secret = config[‘api_secret’]

Vérifiez les clés API

print(f"API Key: {api_key}“)
print(f"API Secret: {api_secret}”)

Initialisation de l’instance Binance Futures avec python-binance

client = Client(api_key, api_secret)

Vérifiez les permissions de la clé API

try:
account_info = client.futures_account()
print(“Les clĂ©s API sont valides et les permissions sont correctes.”)
except BinanceAPIException as e:
print(f"Erreur de l’API Binance: {e}")
exit()

VĂ©rifiez les symboles disponibles pour les futures USD-M et COIN-M

try:
exchange_info = client.futures_exchange_info()
usd_m_symbols = [symbol[‘symbol’] for symbol in exchange_info[‘symbols’] if symbol[‘contractType’] == ‘PERPETUAL’]
coin_m_symbols = [symbol[‘symbol’] for symbol in exchange_info[‘symbols’] if symbol[‘contractType’] in [‘CURRENT_QUARTER’, ‘NEXT_QUARTER’]]
print(“Symboles valides pour les futures USD-M :”)
print(usd_m_symbols)
print(“Symboles valides pour les futures COIN-M :”)
print(coin_m_symbols)
except BinanceAPIException as e:
print(f"Erreur lors de la rĂ©cupĂ©ration des informations d’échange: {e}")
exit()

Choisir le bon symbole (modifiez ici si nécessaire)

symbol = ‘BTCUSDT’ # Changez pour ‘BTCUSD_PERP’ si vous utilisez les futures COIN-M

VĂ©rifiez si le symbole est valide

if symbol not in usd_m_symbols and symbol not in coin_m_symbols:
print(f"Erreur : Le symbole {symbol} n’est pas valide.")
exit()

leverage = 100
risk_percentage = 10.0
take_profit_multiplier = 3.0
magic_number = 123456 # Identifiant unique pour les ordres

def set_leverage(symbol, leverage):
try:
client.futures_change_leverage(symbol=symbol, leverage=leverage)
print(f"Leverage set to {leverage} for {symbol}“)
except BinanceAPIException as e:
print(f"Erreur lors de la dĂ©finition de l’effet de levier: {e}”)

def calculate_position_size(balance, entry_price, leverage):
effective_balance = balance * (risk_percentage / 100)
position_size = (effective_balance * leverage) / entry_price
return position_size

def place_order(symbol, side, position_size, stop_loss_price, take_profit_price):
try:
order = client.futures_create_order(
symbol=symbol,
side=side.upper(),
type=‘MARKET’,
quantity=position_size,
newClientOrderId=magic_number
)
stop_loss_order = client.futures_create_order(
symbol=symbol,
side=‘SELL’ if side.upper() == ‘BUY’ else ‘BUY’,
type=‘STOP_MARKET’,
stopPrice=stop_loss_price,
quantity=position_size,
)
take_profit_order = client.futures_create_order(
symbol=symbol,
side=‘SELL’ if side.upper() == ‘BUY’ else ‘BUY’,
type=‘LIMIT’,
price=take_profit_price,
quantity=position_size,
timeInForce=‘GTC’
)
return order, stop_loss_order, take_profit_order
except BinanceAPIException as e:
print(f"Erreur lors de la crĂ©ation de l’ordre: {e}")

def manage_open_orders():
try:
orders = client.futures_get_open_orders(symbol=symbol)
for order in orders:
print(f"Open order: {order}“)
except BinanceAPIException as e:
print(f"Erreur lors de la gestion des ordres ouverts: {e}”)

def fibonacci_levels(high, low):
diff = high - low
levels = {
‘retracement_50’: high - (diff * 0.5),
‘retracement_618’: high - (diff * 0.618),
}
return levels

def main():
set_leverage(symbol, leverage)
balance = 1000 # Exemple de balance en USDT
HH = 50000 # Exemple de HH
HL = 49500 # Exemple de HL
LH = 50500 # Exemple de LH
LL = 49000 # Exemple de LL
levels = fibonacci_levels(HH, HL)
if levels[‘retracement_618’] <= LH <= levels[‘retracement_50’]:
entry_price = LH
stop_loss_price = HH
take_profit_price = HL - (HH - HL) * take_profit_multiplier
position_size = calculate_position_size(balance, entry_price, leverage)
place_order(symbol, ‘SELL’, position_size, stop_loss_price, take_profit_price)
levels = fibonacci_levels(LL, LH)
if levels[‘retracement_618’] <= HL <= levels[‘retracement_50’]:
entry_price = HL
stop_loss_price = LL
take_profit_price = LH + (LH - LL) * take_profit_multiplier
position_size = calculate_position_size(balance, entry_price, leverage)
place_order(symbol, ‘BUY’, position_size, stop_loss_price, take_profit_price)
manage_open_orders()

if name == ‘main’:
main()