I have these codes inside my trading strategy made with python.
Fetch market data for the symbol
def get_live_data(symbol):
url = f"https://api.upstox.com/v2/historical-candle/intraday/NSE_EQ|HDFCBANK-EQ/1minute"
response = requests.get(url, headers=headers)
try:
response.raise_for_status() # Raise an exception for HTTP errors
data = response.json()
return data['data']['candles'][-1] # Adjusting to access the most recent candle data
except requests.exceptions.HTTPError as err:
print(f"HTTP error occurred: {err}")
return None
except KeyError as e:
print(f"Key error: {e}")
return None
# Place an order
def place_order(transaction_type, symbol, quantity, order_type, product_type, stop_loss):
url = "https://api.upstox.com/v2/order/place"
payload = {
'transaction_type': transaction_type,
'symbol': symbol,
'quantity': quantity,
'order_type': order_type,
'product_type': product_type,
'stop_loss': stop_loss
}
response = requests.post(url, json=payload, headers=headers)
response.raise_for_status()
return response.json()
Symbol
symbol = 'NSE_EQ|HDFCBANK-EQ' # Symbol for HDFC Bank for intraday trading
print(execute_trade(symbol))
print(exit_trade_if_needed(symbol))
However, I get this error when executing.
HTTP error occurred: 400 Client Error: Bad Request for url: https://api.upstox.com/v2/historical-candle/intraday/NSE_EQ|HDFCBANK-EQ/1minute
Error: Unable to fetch live market data.
Can anyone share their thoughts on possible errors that I have made? Are the symbols correct or should I use INE040A01034