We have received some inquiries about changing the timestamp on data retrieved using fxcmpy. So in this post, I will attempt to clarify two points about the data and provide some code you can use to convert the timestamp on the data into the timezone of choice.
First, two points about the data:
Timestamps are in UTC/GMT
The trading day begins at 5pm EST, which is 22:00 GMT or 21:00 GMT during US daylight savings time. (Here is a link of historical US DST start and end dates)
I found a Python library of timezones which works nicely with fxcmpy. To use it, pip install pytz.
You will need to import the following dependencies:
import pandas as pd
from datetime import datetime as dt
con = fxcmpy.fxcmpy(config_file=‘fxcm.cfg’)
For the con.get_candles method (historical data), use
df = con.get_candles(‘EUR/USD’, period=‘D1’, number=30)
For the con.get_prices method (live data), use
df = con.get_prices(‘EUR/USD’)
df = df.tz_localize(pytz.timezone(‘UTC’))
df = df.tz_convert(pytz.timezone(‘Etc/GMT+3’))
For a list of all available timezones using the pytz library, enter
If you use a different method for dealing with timezone conversions, please share!