-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathget_crypto_pairs.py
94 lines (65 loc) · 1.94 KB
/
get_crypto_pairs.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import requests
import os
import pandas as pd
from pandas.tseries.holiday import get_calendar, HolidayCalendarFactory, GoodFriday
import time
import datetime
from datetime import datetime
from datetime import timedelta
import mysql.connector
import sys
import telegram_send
import signal
import argparse
import subprocess
import linecache
def PrintException():
exc_type, exc_obj, tb = sys.exc_info()
f_err = tb.tb_frame
lineno = tb.tb_lineno
filename = f_err.f_code.co_filename
linecache.checkcache(filename)
line = linecache.getline(filename, lineno, f_err.f_globals)
print ('EXCEPTION IN ({}, LINE {} "{}"): {}'.format(filename, lineno, line.strip(), exc_obj))
polygon = "UJcr9ctoMBXEBK1Mqu_KQAkUuBxLvEtE" #jolly_bhaskara
#connect to database
#con = mydb = mysql.connector.connect(user='root', password='waWWii21156!', host='127.0.0.1', database='pts', allow_local_infile=True)
global polygon_api_key
timestamp = int(time.time())
localtime = time.ctime(timestamp)
print("Local time:", localtime)
starttime = time.time()
ux1 = timestamp
#ux = (ux1 - 86400)
#con = mydb = mysql.connector.connect(user='root', password='waWWii21156!', #host='127.0.0.1', database='ticker_prices', allow_local_infile=True)
filename = "polygon_crypto_pairs.tsv"
f = open(str(filename), "w")
getstring=f'https://api.polygon.io/v3/reference/tickers?market=crypto&active=true&sort=ticker&order=asc&limit=1000&apiKey={polygon}'
print(getstring)
resp = requests.get(getstring)
print(resp)
r=resp.json()
#print(r)
try:
results = r['results']
except:
PrintException()
pass
# print(results)
for item in r["results"]:
# print(item)
ticker = str(item['ticker'])
name = str(item['name'])
t = ticker.replace('USD','-usd')
t = t.replace('AUD','-aud')
t = t.replace('EUR','-eur')
t = t.replace('X:','')
tl = t.lower()
out = ticker+ "\t" +name+ "\t" +tl+ "\n"
try:
print(out)
f.write(out)
except:
PrintException()
pass
exit()