· 5 years ago · Mar 29, 2020, 02:42 PM
1!pip install ccxt
2!pip install openpyxl
3
4import http.client
5import urllib
6import json
7import hashlib
8import hmac
9from collections import OrderedDict
10import pandas as pd
11from pandas.io.json import json_normalize
12import openpyxl
13
14
15
16def fetchTrades(pair):
17 df = pd.DataFrame()
18 for offset in range(0,1000,100):
19 server = "api.livecoin.net"
20 method = "/exchange/trades"
21 api_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
22 secret_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxx"
23
24 data = OrderedDict([('currencyPair', pair), ('offset', offset)])
25
26 encoded_data = urllib.parse.urlencode(data)
27
28 sign = hmac.new(b'secret_key', msg=encoded_data.encode('utf-8'), digestmod=hashlib.sha256).hexdigest()
29
30 headers = {"Api-key": api_key, "Sign": sign}
31
32 conn = http.client.HTTPSConnection(server)
33 conn.request("GET", method + '?' + encoded_data, '', headers)
34
35 response = conn.getresponse()
36 data = json.load(response)
37 conn.close()
38 data1 = json_normalize(data)
39 df= df.append(data1)
40
41 return df
42
43DIG = fetchTrades('DIG/BTC')
44#NAM = fetchTrades('NAM/BTC')
45#ORE = fetchTrades('ORE/BTC')
46#HNR = fetchTrades('HNR/BTC')
47#concat = pd.concat([DIG,NAM,ORE,HNR])
48#concat['datetime'] = pd.to_datetime(concat['datetime'], unit='s')
49DIG.to_excel('myTrades.xlsx')