adamhyman / dinar-trader

0 stars 3 forks source link

Mapping! #27

Open adamhyman opened 6 years ago

adamhyman commented 6 years ago

We need a way to map currencies and trade pairs in both directions.

We already made some progress mapping trade pairs in Exchange_Session:

    def get_pair_name(self, trade_name):
        ## Returns the proper trade name per exchange
        if (trade_name == "ETHUSD"):
            if (self.exchange.lower() == "kraken"):
                return "XETHZUSD"
            if (self.exchange.lower() == "gemini"):
                return "ethusd"
            if (self.exchange.lower() == "gdax"):
                return "ETH-USD"

I propose we do something like this:

## Returns the proper trade name per exchange

self.pair_map={}

if (self.exchange.lower() == "kraken"):
    # https://api.kraken.com/0/public/AssetPairs
    # https://api.kraken.com/0/public/Ticker?pair=ETHUSD,ETHXBT
    self.pair_map["ETHUSD"]="XETHZUSD"
    self.pair_map["BTCUSD"]="XXBTZUSD"
    self.pair_map["ETHBTC"]="XETHXXBT"

if (self.exchange.lower() == "gemini"):
    # https://api.gemini.com/v1/symbols
    self.pair_map["ETHUSD"]="ethusd"
    self.pair_map["BTCUSD"]="btcusd"
    self.pair_map["ETHBTC"]="ethbtc"

if (self.exchange.lower() == "gdax"):
    # https://api.gdax.com/products
    self.pair_map["ETHUSD"]="ETH-USD"
    self.pair_map["BTCUSD"]="BTC-USD"
    self.pair_map["ETHBTC"]="ETH-BTC"

if (self.exchange.lower() == "bittrex"):
    # https://bittrex.com/api/v1.1/public/getmarkets
    # https://bittrex.com/api/v1.1/public/getmarketsummaries
    self.pair_map["ETHUSD"]=""
    self.pair_map["BTCUSD"]=""
    self.pair_map["ETHBTC"]="BTC-ETH"

if (self.exchange.lower() == "liquio"):
    # https://api.liqui.io/api/3/info
    self.pair_map["ETHUSD"]=""
    self.pair_map["BTCUSD"]=""
    self.pair_map["ETHBTC"]="eth_btc"

## Returns the proper currency name per exchange

self.currency_map={}

if (self.exchange.lower() == "kraken"):
    # https://api.kraken.com/0/public/Assets
    self.currency_map["USD"] = "ZUSD"
    self.currency_map["ETH"] = "XETH"
    self.currency_map["BTC"] = "XXBT"
    self.currency_map["LTC"] = "XLTC"
    self.currency_map["USDT"] = "USDT"
    self.currency_map["GNT"] = ""
    self.currency_map[""] = ""

if (self.exchange.lower() == "gemini"):
    # https://api.gemini.com/v1/symbols
    self.currency_map["USD"] = "USD"
    self.currency_map["ETH"] = "ETH"
    self.currency_map["BTC"] = "BTC"

if (self.exchange.lower() == "gdax"):
    self.currency_map["USD"] = ""

if (self.exchange.lower() == "bittrex"):
    # https://bittrex.com/api/v1.1/public/getcurrencies
    self.currency_map["USD"] = ""
    self.currency_map["ETH"] = "ETH"
    self.currency_map["BTC"] = "BTC"
    self.currency_map["LTC"] = "LTC"
    self.currency_map["USDT"] = "USDT"
    self.currency_map["GNT"] = "GNT"

if (self.exchange.lower() == "liquio"):
        # https://api.liqui.io/api/3/info
    self.currency_map["USD"] = ""
    self.currency_map["ETH"] = "eth"
    self.currency_map["BTC"] = "btc"
    self.currency_map["LTC"] = "ltc"
    self.currency_map["USDT"] = "usdt"
    self.currency_map["GNT"] = "gnt"

What do you think?

We could include a dash or underscore between the different currencies in the pairs.

As new currencies and trade pairs are listed, we can add them.

We should also add the assets and trade pairs as objects in the class when we update the balances and prices.

Eventually we need to be able to do something like.

  1. Update account balances.
  2. Get prices for all pairs on all exchanges.
  3. Look for arbitrate opportunities.
adamhyman commented 6 years ago

I will finish mapping things out as we discussed on the phone. I'm using paper but will put it all into Excel.

bustoutfunk commented 6 years ago

The above sample code is perfect. Please update the code and commit it.

bustoutfunk commented 6 years ago

FYI, the above code is more of a C style (which is fine). One way of doing the same thing in fewer lines would be from this:

    self.currency_map["USD"] = "ZUSD"
    self.currency_map["ETH"] = "XETH"
    self.currency_map["BTC"] = "XXBT"
    self.currency_map["LTC"] = "XLTC"
    self.currency_map["USDT"] = "USDT"
    self.currency_map["GNT"] = ""
    self.currency_map[""] = ""

to something like this:

self.currency_map = {"USD": "ZUSD", "ETH": "XETH", "BTC": "XXBT", "LTC": "XLTC", "USDT": "USDT", "GNT": ""}

Some people actually prefer the first method because it looks better. Hackers prefer the latter because it's quicker to write.

adamhyman commented 6 years ago

I will use a CSV for Excel file to load in the mapping.