def _post(self,
              api_method,
              params=None,
              connection=None,
              error_handler=None):
        if params is None:
            params = {'nonce': datetime.now().microsecond}
        else:
            params["nonce"] = datetime.now().microsecond
        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()

        if connection is None:
            connection = common.BTERConnection()

        headers = {"Key": self.key, "Sign": sign}
        result = connection.makeJSONRequest('/api/1/private/' + api_method,
                                            method='POST',
                                            extra_headers=headers,
                                            params=encoded_params)

        return common.validateResponse(result, error_handler=error_handler)
Exemple #2
0
def getTradeHistory(pair, connection=None, start_tid=None, count=None, error_handler=None):
    """
Retrieve the trade history for the given pair. Returns a list of
Trade instances. If count is not None, it should be an integer, and
specifies the number of items from the trade history that will be
processed and returned.
"""
    common.validatePair(pair)

    if connection is None:
        connection = common.BTERConnection()

    if start_tid is None:
        result = connection.makeJSONRequest("/api/1/trade/%s" % pair, method="GET")
    else:
        result = connection.makeJSONRequest("/api/1/trade/%s/%d" % (pair, start_tid), method="GET")

    result = common.validateResponse(result, error_handler=error_handler)

    history = result[u"data"]
    if type(history) is not list:
        raise Exception("The response does not contain a history list.")

    result = []
    # Limit the number of items returned if requested.
    if count is not None:
        history = history[:count]

    for h in history:
        h["pair"] = pair
        t = Trade(**h)
        result.append(t)
    return result
Exemple #3
0
def getHistory(pair, connection=None, error_handler=None):
    """
    Retrieve the last 80 trade history for the given pair (oon BTER)
    """

    common.validatePair(pair)

    if connection is None:
        connection = common.BTERConnection()

    depth = common.validateResponse(connection.makeJSONRequest('/api/1/trade/%s' % pair, method='GET'),
                                    error_handler=error_handler)

    if error_handler is not None:
        print "ERROR: " + error_handler
Exemple #4
0
def getTickerfastEUR(error_handler=None, connection=None):

	if connection is None:
		connection = common.MTGOXConnection()


	depth = common.validateResponse(connection.makeJSONRequest('/api/1/BTCEUR/ticker_fast', method='GET'),
                                    error_handler=error_handler)

	if error_handler is not None:
		print error_handler

	BTCEUR = depth.get(u'return')

	BTCEUR = BTCEUR.get(u'last')

	return BTCEUR
Exemple #5
0
    def _post(self, api_method, params=None, connection=None, error_handler=None):
        if params is None:
            params = {'nonce': datetime.now().microsecond}
        else:
            params["nonce"] = datetime.now().microsecond
        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()
        
        if connection is None:
            connection = common.BTERConnection()
        
        headers = {"Key": self.key, "Sign": sign}
        result = connection.makeJSONRequest('/api/1/private/' + api_method, method='POST',
                                            extra_headers=headers, params=encoded_params)

        return common.validateResponse(result, error_handler=error_handler)
Exemple #6
0
def getTradeHistory(pair,
                    connection=None,
                    start_tid=None,
                    count=None,
                    error_handler=None):
    """
    Retrieve the trade history for the given pair. Returns a list of
    Trade instances. If count is not None, it should be an integer, and
    specifies the number of items from the trade history that will be
    processed and returned.
    """
    common.validatePair(pair)

    if connection is None:
        connection = common.BTERConnection()

    if start_tid is None:
        result = connection.makeJSONRequest('/api/1/trade/%s' % pair,
                                            method='GET')
    else:
        result = connection.makeJSONRequest('/api/1/trade/%s/%d' %
                                            (pair, start_tid),
                                            method='GET')

    result = common.validateResponse(result, error_handler=error_handler)

    history = result[u'data']
    if type(history) is not list:
        raise Exception('The response does not contain a history list.')

    result = []
    # Limit the number of items returned if requested.
    if count is not None:
        history = history[:count]

    for h in history:
        h["pair"] = pair
        t = Trade(**h)
        result.append(t)
    return result
Exemple #7
0
def getTicker(pair, connection=None, error_handler=None):
    """
    Retrieve the ticker
    """
    common.validatePair(pair)
    
    if connection is None:
        connection = common.BTERConnection()
    
    depth = common.validateResponse(connection.makeJSONRequest('/api/1/ticker/%s' % pair, method='GET'),
                                    error_handler=error_handler)
    

    buy = depth.get(u'buy')


    # 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.")

    # if len(asks) > 0:
    #     ask_prices, ask_sizes = zip(*asks)
    #     ask_prices = [decimal.Decimal(p) for p in ask_prices]
    #     ask_sizes = [decimal.Decimal(s) for s in ask_sizes]
    #     asks = zip(ask_prices, ask_sizes)
    # else:
    #     asks = []
    # if len(bids) > 0:
    #     bid_prices, bid_sizes = zip(*bids)
    #     bid_prices = [decimal.Decimal(p) for p in bid_prices]
    #     bid_sizes = [decimal.Decimal(s) for s in bid_sizes]
    #     bids = zip(bid_prices, bid_sizes)
    # else:
    #     bids = []
    
    return buy
Exemple #8
0
def getDepth(pair, connection=None, error_handler=None):
    """
    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)

    if connection is None:
        connection = common.BTERConnection()

    depth = common.validateResponse(connection.makeJSONRequest(
        '/api/1/depth/%s' % pair, method='GET'),
                                    error_handler=error_handler)

    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.")

    if len(asks) > 0:
        ask_prices, ask_sizes = zip(*asks)
        ask_prices = [decimal.Decimal(p) for p in ask_prices]
        ask_sizes = [decimal.Decimal(s) for s in ask_sizes]
        asks = zip(ask_prices, ask_sizes)
    else:
        asks = []
    if len(bids) > 0:
        bid_prices, bid_sizes = zip(*bids)
        bid_prices = [decimal.Decimal(p) for p in bid_prices]
        bid_sizes = [decimal.Decimal(s) for s in bid_sizes]
        bids = zip(bid_prices, bid_sizes)
    else:
        bids = []

    return asks, bids
Exemple #9
0
def getDepth(pair, connection=None, error_handler=None):
    """
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)

    if connection is None:
        connection = common.BTERConnection()

    depth = common.validateResponse(
        connection.makeJSONRequest("/api/1/depth/%s" % pair, method="GET"), error_handler=error_handler
    )

    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.")

    if len(asks) > 0:
        ask_prices, ask_sizes = zip(*asks)
        ask_prices = [decimal.Decimal(p) for p in ask_prices]
        ask_sizes = [decimal.Decimal(s) for s in ask_sizes]
        asks = zip(ask_prices, ask_sizes)
    else:
        asks = []
    if len(bids) > 0:
        bid_prices, bid_sizes = zip(*bids)
        bid_prices = [decimal.Decimal(p) for p in bid_prices]
        bid_sizes = [decimal.Decimal(s) for s in bid_sizes]
        bids = zip(bid_prices, bid_sizes)
    else:
        bids = []

    return asks, bids