Currently I am trying to write an exchange bot to be used with Binance. Whenever I decide in code to make a sell or buy, the price value is almost always different, from the value, that I decide upon to make the exchange. Is there a faster way to get the price value than the code below?
I tried with the code below:
def get_price_value():
# Set the API endpoint for the coin1/coin2 pair
api_endpoint = 'https://api.binance.com/api/v3/ticker/price?symbol=' + currency
response = requests.get(api_endpoint)
# Parse the JSON data from the response and extract the current price
data = response.json()
current_price = float(data['price'])
return current_price
Thanks.