-
Notifications
You must be signed in to change notification settings - Fork 43
/
get_pairs_name.py
145 lines (119 loc) · 5.01 KB
/
get_pairs_name.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# This python3 script displays all pairs that can be used
# on Kraken, Poloniex and Bitstamp platform. The pairs can then be copied/pasted
# into Coinnect. This script does the conversion for Poloniex (see Pair doc).
import json
import ssl
import urllib.request
# ugly fix the ssl certificate bug
ssl._create_default_https_context = ssl._create_unverified_context
# ╔╗ ╦ ╔╦╗ ╔═╗ ╔╦╗ ╔═╗ ╔╦╗ ╔═╗
# ╠╩╗ ║ ║ ╚═╗ ║ ╠═╣ ║║║ ╠═╝
# ╚═╝ ╩ ╩ ╚═╝ ╩ ╩ ╩ ╩ ╩ ╩
raw_bitstamp_pairs = ["btcusd", "btceur", "eurusd", "xrpusd", "xrpeur",
"xrpbtc"]
standardized_bitstamp_pairs = ["BTC_USD", "BTC_EUR", "EUR_USD", "XRP_USD",
"XRP_EUR", "XRP_BTC"]
# ╦╔═ ╦═╗ ╔═╗ ╦╔═ ╔═╗ ╔╗╔
# ╠╩╗ ╠╦╝ ╠═╣ ╠╩╗ ║╣ ║║║
# ╩ ╩ ╩╚═ ╩ ╩ ╩ ╩ ╚═╝ ╝╚╝
url = "https://api.kraken.com/0/public/AssetPairs"
raw_kraken_pairs = list()
standardized_kraken_pairs = list()
with urllib.request.urlopen(url) as response:
html = response.read().decode("utf-8")
json_data = json.loads(html)
for currency in json_data["result"]:
raw_kraken_pairs.append(currency)
quote = json_data["result"][currency]["quote"][1:] # remove the X or Z
base = json_data["result"][currency]["base"]
old_naming = ("XETH", "XXBT", "XETC", "XLTC", "XICN", "XREP", "XXDG",
"XZEC", "XXLM", "XXMR", "XMLN", "XXRP")
if base in old_naming:
base = base[1:] # remove the X
if base == "XBT":
base = "BTC"
if quote == "XBT":
quote = "BTC"
if json_data["result"][currency]["altname"][-2:] == ".d":
quote += "_d"
standardized_kraken_pairs.append(base + "_" + quote)
# ╔═╗ ╔═╗ ╦ ╔═╗ ╔╗╔ ╦ ╔═╗ ═╗ ╦
# ╠═╝ ║ ║ ║ ║ ║ ║║║ ║ ║╣ ╔╩╦╝
# ╩ ╚═╝ ╩═╝ ╚═╝ ╝╚╝ ╩ ╚═╝ ╩ ╚═
url = "https://poloniex.com/public?command=returnTicker"
raw_poloniex_pairs = list()
with urllib.request.urlopen(url) as response:
html = response.read().decode("utf-8")
json_data = json.loads(html)
for currency in json_data:
raw_poloniex_pairs.append(currency)
# conversion
standardized_poloniex_pairs = list()
for pair in raw_poloniex_pairs:
base, quote = pair.split('_', 1)
standardized_poloniex_pairs.append(quote + "_" + base)
# ╔╗ ╦ ╔╦╗ ╔╦╗ ╦═╗ ╔═╗ ═╗ ╦
# ╠╩╗ ║ ║ ║ ╠╦╝ ║╣ ╔╩╦╝
# ╚═╝ ╩ ╩ ╩ ╩╚═ ╚═╝ ╩ ╚═
url = "https://bittrex.com/api/v1.1/public/getmarketsummaries"
raw_bittrex_pairs = list()
with urllib.request.urlopen(url) as response:
html = response.read().decode("utf-8")
json_data = json.loads(html)
for currency in json_data["result"]:
raw_bittrex_pairs.append(currency["MarketName"])
# conversion
standardized_bittrex_pairs = list()
for pair in raw_bittrex_pairs:
base, quote = pair.split('-', 1)
standardized_bittrex_pairs.append(quote + "_" + base)
# Generate all possible pairs
exchanges = [standardized_bitstamp_pairs, standardized_kraken_pairs,
standardized_poloniex_pairs, standardized_bittrex_pairs]
pairs = list()
for exchange in exchanges:
for pair in exchange:
if pair not in pairs:
pairs.append(pair)
pairs = sorted(pairs)
print("SUPPORTED PAIRS")
print("===============")
for pair in pairs:
print(pair + ",")
print("\n\n\n")
print("BITSTAMP PAIRS")
print("==============")
for std, raw in zip(standardized_bitstamp_pairs, raw_bitstamp_pairs):
print("m.insert({std}, \"{raw}\");".format(std=std, raw=raw))
print("\n\n\n")
print("KRAKEN PAIRS")
print("============")
for std, raw in zip(standardized_kraken_pairs, raw_kraken_pairs):
print("m.insert({std}, \"{raw}\");".format(std=std, raw=raw))
print("\n\n\n")
print("POLONIEX PAIRS")
print("==============")
for std, raw in zip(standardized_poloniex_pairs, raw_poloniex_pairs):
print("m.insert({std}, \"{raw}\");".format(std=std, raw=raw))
print("\n\n\n")
print("BITTREX PAIRS")
print("==============")
for std, raw in zip(standardized_bittrex_pairs, raw_bittrex_pairs):
print("m.insert({std}, \"{raw}\");".format(std=std, raw=raw))
# CURRENCIES
# BITTREX
url = "https://bittrex.com/api/v1.1/public/getcurrencies"
bittrex_currencies = list()
with urllib.request.urlopen(url) as response:
html = response.read().decode("utf-8")
json_data = json.loads(html)
for currency in json_data["result"]:
print(currency["Currency"] + ",")
bittrex_currencies.append(currency["Currency"])
# Currency enum -> Option<String>
for currency in bittrex_currencies:
print("Currency::" + currency + " => Some(\"" +
currency + "\".to_string()),")
# Currency str -> Option<Currency>
for currency in bittrex_currencies:
print("\"" + currency + "\" => Some(Currency::" + currency + "),")