Exemple #1
0
 def GetOHLC(self, **kwargs):
     """
     Gets candlestick data with the Opening, High, Low and Closing values during specified time periods.
     
     Keyword args:
     before: Only return candles opening before this time. (UNIX Timestamp)
     after: Only return candles opening after this time. (UNIX Timestamp)
     periods: Only return these time periods. (Integer list)
     """
     url = urljoin(self.base_url, "ohlc")
     params = {}
     if('before' in kwargs):
         params['before'] = kwargs['before']
     if('after' in kwargs):
         params['after'] = kwargs['after']
     if('periods' in kwargs):
         params['periods'] = ",".join(kwargs['periods'])
     url = _add_query_string(url, params)
     
     resp = _get_response(url)
     
     res = {}
     for period in resp['result']:
         data = resp['result'][period]
         period_ms = int(period)*1000
         res[period] = [Msg.Candle(x, period_ms) for x in data]
     return _include_allowance(res, resp, kwargs)
Exemple #2
0
def GetAllowance(**kwargs):
    """Request the status of your current allowance"""
    url = _get_url(kwargs)
    resp = _get_response(url)
    
    res = Msg.Allowance(resp)
    return res
Exemple #3
0
 def GetSummary(self, **kwargs):
     """
     Get a 24-hour summary of this exchange.
     
     Result includes last, highest and lowest prices, volume, and price change information.
     """
     url = urljoin(self.base_url, "summary")
     resp = _get_response(url)
     
     res = Msg.Summary(resp['result'])
     return _include_allowance(res, resp, kwargs)
Exemple #4
0
 def GetOrderBook(self, **kwargs):
     """
     Get the current order book.
     """
     url = urljoin(self.base_url, "orderbook")
     params = {}
     url = _add_query_string(url, params)
     
     resp = _get_response(url)
     
     res = Msg.OrderBook(resp['result'])
     return _include_allowance(res, resp, kwargs)
Exemple #5
0
def GetAllSummaries(split_slug = False, **kwargs):
    """
    Get summaries from all currency pairs on all exchanges.
    
    split_slug: Indicates whether the 'slug' should be split. By default, the result will
    return a dict() with concatenated exchange and currency pair names as the key, joined by
    a colon (e.g.  'coinbase:ethusd'). If this is set true, instead of a dict, the result 
    will be a list of 3-tuples containing the exchange, currency pair and summary (in that order)
    """
    url = urljoin(_get_url(kwargs), "markets/summaries")
    resp = _get_response(url)

    if(split_slug):
        res = []
        for slug in resp['result']:
            summ = Msg.Summary(resp['result'][slug])
            exch,cpair = slug.split(":")
            res.append((exch, cpair, summ))
    else:
        res = {x: Msg.Summary(resp['result'][x]) for x in resp['result']}
        
    return _include_allowance(res, resp, kwargs)
Exemple #6
0
def GetMarkets(exchange = None, **kwargs):
    """
    Get a list of available exchanges and currency pairs
    """
    if(exchange):
        url = urljoin(_get_url(kwargs), "markets/")
        url = urljoin(url, exchange)
    else:
        url = urljoin(_get_url(kwargs), "markets")
    resp = _get_response(url)
    
    res = [Msg.Market(x) for x in resp['result']]
    return _include_allowance(res, resp, kwargs)
Exemple #7
0
 def GetTrades(self, **kwargs):
     """
     Get a trade history.
     
     Keyword args:
     limit: Limit amount of trades returned. Defaults to 50. Integer
     since: Only return trades at or after this time. UNIX timestamp
     """
     url = urljoin(self.base_url, "trades")
     params = {}
     if('limit' in kwargs):
         params['limit'] = kwargs['limit']
     if('since' in kwargs):
         params['since'] = kwargs['since']
     
     url = _add_query_string(url, params)
     
     resp = _get_response(url)
     
     res = [Msg.Trade(x) for x in resp['result']]
     return _include_allowance(res, resp, kwargs)
Exemple #8
0
def _include_allowance(res, json, kwargs):
    if('get_allowance' in kwargs and kwargs['get_allowance']):
        alw = Msg.Allowance(json)
        return (res, alw)
    else:
        return res
Exemple #9
0
def _raiseIfError(response):
    if(response.ok):
        return
    raise Msg.ApiRequestException(response)