-
Notifications
You must be signed in to change notification settings - Fork 827
/
spotfx_from_csvAndInvestingDotCom_to_db.py
64 lines (50 loc) · 2.29 KB
/
spotfx_from_csvAndInvestingDotCom_to_db.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"""
Get FX prices from investing.com files, and from csv, merge and write to Arctic and/or optionally overwrite csv files
"""
from sysdata.csv.csv_spot_fx import csvFxPricesData, ConfigCsvFXPrices
import pandas as pd
from sysproduction.data.currency_data import fxPricesData
# You may need to change this!
# There must be ONLY fx prices here, with filenames "GBPUSD.csv" etc
db_fx_prices_data = fxPricesData()
investing_dot_com_config = ConfigCsvFXPrices(
price_column="Close", date_column="Date Time", date_format="%Y-%m-%d"
)
def spotfx_from_csv_and_investing_dot_com(
datapath, ADD_TO_DB=True, ADD_TO_CSV=True, ADD_EXTRA_DATA=True
):
# You can adapt this for different providers by changing these parameters
if ADD_EXTRA_DATA:
investingDotCom_csv_fx_prices = csvFxPricesData(
datapath=datapath, config=investing_dot_com_config
)
my_csv_fx_prices_data = csvFxPricesData()
list_of_ccy_codes = my_csv_fx_prices_data.get_list_of_fxcodes()
for currency_code in list_of_ccy_codes:
print(currency_code)
fx_prices_my_csv = my_csv_fx_prices_data.get_fx_prices(currency_code)
fx_prices = investingDotCom_csv_fx_prices.get_fx_prices(currency_code)
if ADD_EXTRA_DATA:
fx_prices_investingDotCom = investingDotCom_csv_fx_prices.get_fx_prices(
currency_code
)
print(
"%d rows for my csv files, %d rows for investing.com"
% (len(fx_prices_my_csv), len(fx_prices_investingDotCom))
)
# Merge;
last_date_in_my_csv = fx_prices_my_csv.index[-1]
fx_prices_investingDotCom = fx_prices_investingDotCom[last_date_in_my_csv:]
fx_prices = pd.concat([fx_prices_my_csv, fx_prices_investingDotCom])
fx_prices = fx_prices.loc[~fx_prices.index.duplicated(keep="first")]
else:
fx_prices = fx_prices_my_csv
print("%d rows to write for %s" % (len(fx_prices), currency_code))
if ADD_TO_CSV:
my_csv_fx_prices_data.add_fx_prices(
currency_code, fx_prices, ignore_duplication=True
)
if ADD_TO_DB:
db_fx_prices_data.add_fx_prices(
code=currency_code, fx_price_data=fx_prices, ignore_duplication=True
)