-
Notifications
You must be signed in to change notification settings - Fork 0
/
export.py
53 lines (40 loc) · 1.51 KB
/
export.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
import argparse
import csv
from time import sleep
from luno_python.client import Client
def fetch_trades(pair, api_key, api_secret):
c = Client(api_key_id=api_key, api_key_secret=api_secret)
upto = 0
all_trades = []
while True:
res = c.list_user_trades(pair, after_seq=upto+1, limit=100)
trades = res["trades"]
if not trades:
break
all_trades.extend(trades)
print("got " + str(len(all_trades)) + " trades so far...")
sleep(1)
upto = trades[-1]["sequence"]
print("got " + str(len(all_trades)) + " total trades.")
return all_trades
def write_trades_csv(trades, csv_name):
fields = [
"pair","sequence","order_id","type","timestamp",
"price","volume","base","counter","fee_base","fee_counter",
]
with open(csv_name, 'w') as csvfile:
writer = csv.DictWriter(csvfile, fieldnames=fields, extrasaction="ignore")
writer.writeheader()
for t in trades:
writer.writerow(t)
def main():
parser = argparse.ArgumentParser(description='Process some integers.')
parser.add_argument('--pair', required=True, help='the market we will be exporting trades for e.g. XBTEUR')
parser.add_argument('--key', required=True, help='the key part of the api key')
parser.add_argument('--secret', required=True, help='the secret part of the api key')
parser.add_argument('--output', default="trades.csv", help='the .csv file to write to, defaults to "trades.csv"')
args = parser.parse_args()
trades = fetch_trades(args.pair, args.key, args.secret)
write_trades_csv(trades, args.output)
if __name__ == "__main__":
main()