coinnect 0.5.9

A Rust library to connect to various crypto-currencies exchanges.
Documentation
# 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 + "),")