Getting 400 error when invoking get_history in python

Various questions related to programming, testing, deployment and support.

Moderator: admin

Getting 400 error when invoking get_history in python

Postby joekairouz » Tue Jan 31, 2023 5:58 pm

I am new to Forexconnect. I tried different examples in python, the one using get_history are always giving a error 400.

The program establish a connection successfully.
On this line: history = fx.get_history("EUR/USD", "m1", None, None, 50), I am getting this error:
Exception: QuotesManager error: HTTP request failed object='/pricearchive/catalog.xml' errorCode=400 code: QuotesServerConnectionError subcode: 400

This is the code
import pandas as pd
from forexconnect import ForexConnect, fxcorepy
import datetime
import common_samples

str_user_id = "XXXXXX"
str_password = "XXXX"
str_url = "fxcorporate.com/Hosts.jsp"
str_timeframe = "m1"
str_connection = "Demo"

def main():
with ForexConnect() as fx:
try:
fx.login(str_user_id, str_password, str_url,
str_connection, common_samples.session_status_changed)

print("")
print("Requesting a price history...")
history = fx.get_history("EUR/USD", "m1", None, None, 50)
current_unit, _ = ForexConnect.parse_timeframe(str_timeframe)

date_format = '%m.%d.%Y %H:%M:%S'
if current_unit == fxcorepy.O2GTimeFrameUnit.TICK:
print("Date, Bid, Ask")
print(history.dtype.names)
for row in history:
print("{0:s}, {1:,.5f}, {2:,.5f}".format(
pd.to_datetime(str(row['Date'])).strftime(date_format), row['Bid'], row['Ask']))
else:
print("Date, BidOpen, BidHigh, BidLow, BidClose, Volume")
for row in history:
print("{0:s}, {1:,.5f}, {2:,.5f}, {3:,.5f}, {4:,.5f}, {5:d}".format(
pd.to_datetime(str(row['Date'])).strftime(date_format), row['BidOpen'], row['BidHigh'],
row['BidLow'], row['BidClose'], row['Volume']))
except Exception as e:
print("Exception: " + str(e))
try:
fx.logout()
except Exception as e:
print("Exception: " + str(e))


if __name__ == "__main__":
main()
print("")
input("Done! Press enter key to exit\n")



This is the error:
Requesting a price history...
Exception: QuotesManager error: HTTP request failed object='/pricearchive/catalog.xml' errorCode=400 code: QuotesServerConnectionError subcode: 400

Done! Press enter key to exit
joekairouz
 
Posts: 2
Joined: Tue Jan 31, 2023 10:12 am

Return to Development

Who is online

Users browsing this forum: No registered users and 2 guests