-2

I have this code and i want to place a buy order using the binance spot api, but it doesn't like my symbol that i am using showing me the error:

{'code': -1102, 'msg': "Mandatory parameter 'symbol' was not sent, was empty/null, or malformed."}
import json
import requests
import time
API_KEY = "apikey"
SECRET_KEY = "secretkey"


ENDPOINT = "https://api.binance.com/api/v3/order"
HEADERS = {
"X-MBX-APIKEY": API_KEY
}

PAYLOAD = {
"symbol": "BTCUSDT",
        "side": "BUY",
        "type": "MARKET",
        "quantity": "0.1",
        "timestamp": int(time.time() * 1000)
    }

    
response = requests.post(ENDPOINT, headers=HEADERS, params=json.dumps(PAYLOAD))

    if response.status_code != 200:
        print("Error placing buy order:")
        print(response.json())
    else:
        print("Buy order placed successfully:")
        print(response.json())

I wanted it to tell me that i had insufficient funds (true) but just to know that if i had money on it, it would place the order.

EDIT: Changed to most recent comment, the prevailing error occurs.

Shiny
  • 3
  • 2

1 Answers1

0

Can you try this:

import json
response = requests.post(ENDPOINT, headers=HEADERS, params=json.dumps(PAYLOAD))
Bushmaster
  • 4,196
  • 3
  • 8
  • 28