Getting price history

Moderator: Moderator

Getting price history

Postby JuliaS » Tue Oct 02, 2018 10:35 am

Using ForexConnect API, you can receive both tick historical data and a big amount of bar historical data in the standard or custom timeframes.

For a detailed step-by-step instruction on how to get price history, see the Getting Price History article.

The following sample script is available at github:

- GetHistPrices.py
This sample script shows how to get historical prices for specified dates, instrument, and timeframe.
JuliaS
 
Posts: 16
Joined: Wed Jan 25, 2017 11:19 am

Re: Getting price history

Postby Sdoof2708 » Sun Aug 23, 2020 10:26 am

It seems there is timestamp bug when it comes to Tick, because the timestamp for each update is not set to milliseconds, only showing the seconds.

For example I currently get the following timestamps.
2019-06-24 19:13:43
2019-06-24 19:13:43
2019-06-24 19:13:43
2019-06-24 19:13:43
2019-06-24 19:13:43

Should be something like this.
2019-06-24 19:13:43.022
2019-06-24 19:13:43.053
2019-06-24 19:13:43.068
2019-06-24 19:13:43.070

This is a fairly critical bug because there is no way to eliminate 'out of order' ticks/updates, what is the best way to fix this?

Code: Select all
import pandas as pd
import datetime
import csv
import numpy as np
data_file='C:\\Users\\FOREXCONNECT_DB.csv'

from forexconnect import fxcorepy, ForexConnect


def session_status_changed(session: fxcorepy.O2GSession,
                           status: fxcorepy.AO2GSessionStatus.O2GSessionStatus):
    print("Trading session status: " + str(status))


def main():
    with ForexConnect() as fx:
        try:
            fx.login(REAL_ACCOUNT_ID, PASSWORD, "fxcorporate.com/Hosts.jsp",
                     "Real", session_status_callback=session_status_changed)
            history = fx.get_history("EUR/USD", "t1",
                                     datetime.datetime.strptime("08.06.2020 17:51:21.000", '%m.%d.%Y %H:%M:%S.%f').replace(
                                         tzinfo=datetime.timezone.utc),
                                     datetime.datetime.strptime("08.06.2020 18:00:21.000", '%m.%d.%Y %H:%M:%S.%f').replace(
                                         tzinfo=datetime.timezone.utc))
            np.savetxt(data_file, history, delimiter=",")

            print("Date, Bid, Ask")
            for row in history:
                print("{0:s}, {1:,.5f}, {2:,.5f}".format(
                    pd.to_datetime(str(row['Date'])).strftime('%m.%d.%Y %H:%M:%S.%f'), row['Bid'], row['Ask']))
                    # 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()


Thanks for your help

Cheers
Sdoof2708
 
Posts: 2
Joined: Sun Aug 23, 2020 10:02 am


Return to ForexConnect-Python API

Who is online

Users browsing this forum: No registered users and 1 guest