Skip to content

Commit f0632aa

Browse files
committed
patch download to process files
1 parent 61c417a commit f0632aa

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

cot.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
cot.py latest <currency>
66
cot.py --date <report_date> <currency>
77
cot.py --from-file <filename> <currency>
8-
8+
99
Example:
1010
cot.py latest EURO
1111
cot.py --date 01/19/2017 YEN
@@ -72,21 +72,19 @@ def _download_report(date_to_get='latest'):
7272

7373
def _visualize(json_data, currency, report_date):
7474
data = []
75-
data.append(['Non-Commercial (current)', 'Non-Commercial (changes)', 'Commercial (current)', 'Commercial (changes)'])
75+
data.append(['Non-Commercial (% long)', 'Commercial (% long)'])
7676

7777
non_com_current = json_data['non-commercial']['current']
7878
non_com_changes = json_data['non-commercial']['changes']
7979
com_current = json_data['commercial']['current']
8080
com_changes = json_data['commercial']['changes']
8181

8282
# all
83-
data.append([locale.atoi(non_com_current['long']) - locale.atoi(non_com_current['short']),
84-
locale.atoi(non_com_changes['long']) - locale.atoi(non_com_changes['short']),
85-
locale.atoi(com_current['long']) - locale.atoi(com_current['short']),
86-
locale.atoi(com_changes['long']) - locale.atoi(com_changes['short'])])
83+
data.append([float(locale.atoi(non_com_changes['long']))/locale.atoi(non_com_current['long']),
84+
float(locale.atoi(com_changes['long']))/locale.atoi(com_current['long'])])
8785

8886
table = SingleTable(data)
89-
table.title = 'Commitment of Traders (sum):' + currency + "|" + report_date
87+
table.title = 'Commitment of Traders (long %): ' + currency + " | " + report_date
9088
print table.table
9189

9290
# Non-Commercial

download_all_cot.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@
77
"""
88
from datetime import datetime, timedelta
99
from cot import _download_report, process
10+
import locale
1011

1112
if __name__ == "__main__":
13+
locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
14+
1215
csv_file = open("all_data.csv", "w+")
13-
csv_file.write("non_com_long;non_com_short;spreads;com_long;com_short\n")
16+
csv_file.write("non_com_long;non_com_short;spreads;com_long;com_short;date\n")
1417

1518
start, end = datetime(2005, 01, 4), datetime(2017, 01, 23)
1619
days = (start + timedelta(days=i) for i in range((end - start).days + 1))
@@ -26,10 +29,11 @@
2629
with open(report, 'r') as fd:
2730
data, current, changes = process(fd.readlines(), 'EURO')
2831
for c in current[:5]:
29-
csv_file.write(c+";")
30-
csv_file.write(str_tuesday+"\n")
32+
csv_file.write(str(locale.atoi(c))+";")
33+
34+
csv_file.write(str_tuesday+"\n")
35+
3136
except:
3237
print "Something went wrong"
33-
3438

3539

0 commit comments

Comments
 (0)