Page 1 of 1

Getting price history

PostPosted: Tue Oct 02, 2018 10:35 am
by JuliaS
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.

Re: Getting price history

PostPosted: Sun Aug 23, 2020 10:26 am
by Sdoof2708
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

Re: Getting price history

PostPosted: Wed Sep 07, 2022 4:16 am
by Loggy48
Ticks at FXCM are all by the second so milliseconds will always be 0.

In the real market you are right but this is derivative market and ForexConnect will only deliver prices at about 2-3 per second anyway.

You can see this by specifying

date_format = '"%d.%m.%Y %H:%M:%S.%f'"

or whatever, which produces microseconds (add [:-3] to the string variable truncates down to 3dp ie truncated milliseconds).