aboutsummaryrefslogtreecommitdiff
path: root/market.py
blob: 63eff5a87ea089c6043964a72e7af1257422ebe9 (plain) (blame)
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
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",
    })