def get_balances(self): E = models.Exchange('Poloniex') raw = self.raw_balances() for t in raw: balance = float(raw[t]['available']) if balance > 0: value = float(raw[t]['btcValue']) ticker = t try: E.tokens.append( models.Token(ticker, balance, 'Poloniex', value=value)) except KeyError: E.tokens.append(models.Token(ticker, balance, 'Poloniex')) return E
def get_balances(self): E = models.Exchange('Gemini') raw = self.raw_balances() for t in raw: balance = float(t['available']) if balance > 0: ticker = t['currency'] try: price = requests.get( 'https://api.gemini.com/v1/pubticker/{0}'.format( ticker + 'btc')).json()['last'] E.tokens.append( models.Token(ticker, balance, 'Gemini', price=price)) except KeyError: E.tokens.append(models.Token(ticker, balance, 'Gemini')) return E
def get_balances(self): E = models.Exchange('Gdax') raw = self.raw_balances() for t in raw: balance = float(t['available']) if balance > 0: ticker = t['currency'] try: price = requests.get( 'https://api.gdax.com/products/{0}-BTC/ticker'.format( ticker)).json()['price'] E.tokens.append( models.Token(ticker, balance, 'Gdax', price=price)) except KeyError: E.tokens.append(models.Token(ticker, balance, 'Gdax')) return E
def get_balances(self): E = models.Exchange('Binance') prices = requests.get( 'https://api.binance.com//api/v1/ticker/allPrices').json() prices = {i['symbol']: i['price'] for i in prices} raw = self.raw_balances() for t in raw: balance = float(t['free']) if balance > 0: ticker = t['asset'] try: price = prices['{0}BTC'.format(ticker)] E.tokens.append( models.Token(ticker, balance, 'Binance', price=price)) except KeyError: E.tokens.append(models.Token(ticker, balance, 'Binance')) return E
def parser(balances, exchange): E = models.Exchange(exchange) if exchange is 'poloniex': for token in balances: summary = balances[token] if float(summary['available']) > 0: E.tokens.append( models.Token(token, summary['available'], exchange, value=summary['btcValue'])) elif exchange is 'gdax': for token in balances: if float(token['available']) > 0: quote = requests.get( 'https://api.gdax.com/products/{0}-BTC/ticker'.format( token['currency'])).json() try: E.tokens.append( models.Token(token['currency'], token['available'], exchange, price=quote['price'])) except KeyError: E.tokens.append( models.Token(token['currency'], token['available'], exchange)) elif exchange is 'bittrex': for token in balances['result']: if float(token['Available']) > 0: quote = requests.get( 'https://bittrex.com/api/v1.1/public/getticker?market=BTC-{0}' .format(token['Currency'])).json() try: E.tokens.append( models.Token(token['Currency'], token['Available'], exchange, price=quote['result']['Last'])) except TypeError: E.tokens.append( models.Token(token['Currency'], token['Available'], exchange)) return E
def get_balances(self): E = models.Exchange('Bittrex') prices = requests.get( 'https://bittrex.com/api/v1.1/public/getmarketsummaries').json( )['result'] prices = {i['MarketName']: i['Last'] for i in prices} raw = self.raw_balances() for t in raw: balance = float(t['Available']) if balance > 0: ticker = t['Currency'] try: price = prices['BTC-{0}'.format(ticker)] E.tokens.append( models.Token(ticker, balance, 'Bittrex', price=price)) except KeyError: E.tokens.append(models.Token(ticker, balance, 'Bittrex')) return E