Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getting this error while running the following code: {'code': -1102, 'msg': "Mandatory parameter 'timestamp' was not sent, was empty/null, or malformed."} #870

Open
arnob7x41 opened this issue Jan 21, 2023 · 3 comments

Comments

@arnob7x41
Copy link

import requests
import json
import hmac
import hashlib
import time

API endpoint

url = "https://fapi.binance.com/fapi/v1/order"

API key and secret

api_key = ""
api_secret = ""

Request parameters

symbol = "BTCUSDT"
side = "SELL"
type = "MARKET"
notional_value = 30 # Notional value in USD
timestamp = int(time.time() * 1000)
recvWindow = 5000

Fetch last traded price

ticker_url = "https://fapi.binance.com/fapi/v1/ticker/price"
ticker_payload = {
"symbol": symbol
}
ticker_response = requests.get(ticker_url, params=ticker_payload)
last_price = float(ticker_response.json()["price"])

Calculate quantity

quantity = notional_value / last_price

Create the timestamp

timestamp = int(time.time() * 1000)

Create the signature

message = f"{timestamp}{recvWindow}".encode('utf-8')
signature = hmac.new(api_secret.encode('utf-8'), message, hashlib.sha256).hexdigest()

Create the request payload

payload = {
"symbol": symbol,
"side": side,
"type": type,
"quantity": quantity,
"timestamp": timestamp,
"recvWindow": recvWindow,
"signature": signature
}

Send the request

response = requests.post(url, headers={"X-MBX-APIKEY": api_key}, json=payload)

Print the response

print(response.json())

@justwicksapp
Copy link

Even i am facing the same error any possible solution?

i tried setting useServerTime()

@drinkthere
Copy link

check this issue, when useServerTime() returns NaN, timestamp in following request will be invalid. maybe it's the reason. #472

@timetaxy
Copy link

I got same error. Any solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants