aboutsummaryrefslogblamecommitdiff
path: root/market.py
blob: 63eff5a87ea089c6043964a72e7af1257422ebe9 (plain) (tree)
1
2
3
           
              
 

















































                                                                                       



                                                                                                                                                 
import ccxt
import decimal

def exchange_sum(self, *args):
    return sum([arg for arg in args if isinstance(arg, (float, int, decimal.Decimal))])
ccxt.Exchange.sum = exchange_sum
def poloniex_fetch_balance(self, params={}):
    self.load_markets()
    balances = self.privatePostReturnCompleteBalances(self.extend({
        'account': 'all',
        }, params))
    result = {'info': balances}
    currencies = list(balances.keys())
    for c in range(0, len(currencies)):
        id = currencies[c]
        balance = balances[id]
        currency = self.common_currency_code(id)
        account = {
                'free': decimal.Decimal(balance['available']),
                'used': decimal.Decimal(balance['onOrders']),
                'total': decimal.Decimal(0.0),
                }
        account['total'] = self.sum(account['free'], account['used'])
        result[currency] = account
    return self.parse_balance(result)
ccxt.poloniex.fetch_balance = poloniex_fetch_balance

def poloniex_parse_ticker(self, ticker, market=None):
    timestamp = self.milliseconds()
    symbol = None
    if market:
        symbol = market['symbol']
    return {
        'symbol': symbol,
        'timestamp': timestamp,
        'datetime': self.iso8601(timestamp),
        'high': decimal.Decimal(ticker['high24hr']),
        'low': decimal.Decimal(ticker['low24hr']),
        'bid': decimal.Decimal(ticker['highestBid']),
        'ask': decimal.Decimal(ticker['lowestAsk']),
        'vwap': None,
        'open': None,
        'close': None,
        'first': None,
        'last': decimal.Decimal(ticker['last']),
        'change': decimal.Decimal(ticker['percentChange']),
        'percentage': None,
        'average': None,
        'baseVolume': decimal.Decimal(ticker['quoteVolume']),
        'quoteVolume': decimal.Decimal(ticker['baseVolume']),
        'info': ticker,
    }
ccxt.poloniex.parse_ticker = poloniex_parse_ticker
market = ccxt.poloniex({
    "apiKey": "XXXXXXXX-XXXXXXXX-XXXXXXXX-XXXXXXXX",
    "secret": "1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
    })