예제 #1
0
    def _post(self, params):
        params["nonce"] = self.next_nonce()
        encoded_params = urllib.urlencode(params)

        # Hash the params string to produce the Sign header value
        H = hmac.new(self.secret, digestmod=hashlib.sha512)
        H.update(encoded_params)
        sign = H.hexdigest()

        headers = {"Key": self.key, "Sign": sign}
        result = common.makeJSONRequest("/tapi", headers, encoded_params)

        success = result.get(u'success')
        if not success:
            if "method" in params:
                raise Exception("%s call failed with error: %s" \
                    % (params["method"], result.get(u'error')))

            raise Exception("Call failed with error: %s" %
                            result.get(u'error'))

        if u'return' not in result:
            raise Exception("Response does not contain a 'return' item.")

        return result.get(u'return')
예제 #2
0
파일: public.py 프로젝트: nick-ma/btce-api
def getTradeHistory(pair):
    '''Retrieve the trade history for the given pair.  Returns a list of 
    Trade instances.'''

    common.validatePair(pair)

    history = common.makeJSONRequest("/api/2/%s/trades" % pair)

    if type(history) is not list:
        raise Exception("The response is a %r, not a list." % type(history))

    result = []
    for h in history:
        t = Trade(**h)
        t.pair = pair
        result.append(t)
    return result
예제 #3
0
def getTradeHistory(pair):
    """Retrieve the trade history for the given pair.  Returns a list of 
    Trade instances."""

    common.validatePair(pair)

    history = common.makeJSONRequest("/api/2/%s/trades" % pair)

    if type(history) is not list:
        raise Exception("The response is a %r, not a list." % type(history))

    result = []
    for h in history:
        h["pair"] = pair
        t = Trade(**h)
        result.append(t)
    return result
예제 #4
0
파일: public.py 프로젝트: nick-ma/btce-api
def getDepth(pair):
    '''Retrieve the depth for the given pair.  Returns a tuple (asks, bids);
    each of these is a list of (price, volume) tuples.'''

    common.validatePair(pair)

    depth = common.makeJSONRequest("/api/2/%s/depth" % pair)
    if type(depth) is not dict:
        raise Exception("The response is not a dict.")

    asks = depth.get(u'asks')
    if type(asks) is not list:
        raise Exception("The response does not contain an asks list.")

    bids = depth.get(u'bids')
    if type(bids) is not list:
        raise Exception("The response does not contain a bids list.")

    return asks, bids
예제 #5
0
def getDepth(pair):
    """Retrieve the depth for the given pair.  Returns a tuple (asks, bids);
    each of these is a list of (price, volume) tuples."""

    common.validatePair(pair)

    depth = common.makeJSONRequest("/api/2/%s/depth" % pair)
    if type(depth) is not dict:
        raise Exception("The response is not a dict.")

    asks = depth.get(u"asks")
    if type(asks) is not list:
        raise Exception("The response does not contain an asks list.")

    bids = depth.get(u"bids")
    if type(bids) is not list:
        raise Exception("The response does not contain a bids list.")

    return asks, bids
예제 #6
0
def getTradeHistory(pair):
    '''Retrieve the trade history for the given pair.  Returns a list of 
    Trade instances.'''

    common.validatePair(pair)

    history = common.makeJSONRequest("/api/2/%s/trades" % pair)

    if type(history) is not list:
        raise Exception("The response is a %r, not a list." % type(history))

    result = []
    for h in history:
        t = Trade()
        for s in Trade.__slots__:
            u = unicode(s)
            setattr(t, u, h.get(u))
        t.date = datetime.datetime.fromtimestamp(t.date)
        result.append(t)
    return result
예제 #7
0
파일: public.py 프로젝트: a-r-d/btce-api
def getTradeHistory(pair):
    '''Retrieve the trade history for the given pair.  Returns a list of 
    Trade instances.'''
    
    common.validatePair(pair)
    
    history = common.makeJSONRequest("/api/2/%s/trades" % pair)
    
    if type(history) is not list:
        raise Exception("The response is a %r, not a list." % type(history))
        
    result = []
    for h in history:
        t = Trade()
        for s in Trade.__slots__:
            u = unicode(s)
            setattr(t, u, h.get(u))
        t.date = datetime.datetime.fromtimestamp(t.date)
        result.append(t)
    return result
예제 #8
0
    def _post(self, params):
        params["nonce"] = self.next_nonce()
        encoded_params = urllib.urlencode(params)

        # Hash the params string to produce the Sign header value
        H = hmac.new(self.secret, digestmod=hashlib.sha512)
        H.update(encoded_params)
        sign = H.hexdigest()
        
        headers = {"Key":self.key, "Sign":sign}
        result = common.makeJSONRequest("/tapi", headers, encoded_params)
        
        success = result.get(u'success')
        if not success:
            if "method" in params:
                raise Exception("%s call failed with error: %s" \
                    % (params["method"], result.get(u'error')))
            
            raise Exception("Call failed with error: %s" % result.get(u'error'))
            
        if u'return' not in result:
            raise Exception("Response does not contain a 'return' item.")
            
        return result.get(u'return')