예제 #1
0
def getTradeHistory(pair, connection=None, count=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.BTCEConnection()

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

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

    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
예제 #2
0
    def activeOrders(self, pair=None, connection=None):

        params = {"method": "ActiveOrders"}

        if pair is not None:
            common.validatePair(pair)
            params["pair"] = pair

        orders = self._post(params, connection)
        result = []
        for k, v in orders.items():
            result.append(OrderItem(k, v))

        return result
예제 #3
0
def getTradeFee(pair, connection=None):
    """
    Retrieve the fee (in percent) associated with trades for a given pair.
    """

    common.validatePair(pair)

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

    fees = connection.makeJSONRequest("/api/2/%s/fee" % pair)
    if type(fees) is not dict:
        raise TypeError("The response is not a dict.")

    trade_fee = fees.get(u'trade')
    if type(trade_fee) is not decimal.Decimal:
        raise TypeError("The response does not contain a trade fee")

    return trade_fee
예제 #4
0
    def tradeHistory(self, from_number=None, count_number=None,
                     from_id=None, end_id=None, order=None,
                     since=None, end=None, pair=None, connection=None):

        params = {"method": "TradeHistory"}

        setHistoryParams(params, from_number, count_number, from_id, end_id,
                         order, since, end)

        if pair is not None:
            common.validatePair(pair)
            params["pair"] = pair

        orders = list(self._post(params, connection).items())
        orders.sort(reverse=order != "ASC")
        result = []
        for k, v in orders:
            result.append(TradeHistoryItem(int(k), v))

        return result
예제 #5
0
def getDepth(pair, connection=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.BTCEConnection()

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

    asks = depth.get(u'asks')
    if type(asks) is not list:
        pp = pprint.PrettyPrinter(indent=4).pprint(depth)
        pp.pprint(depth)
        raise TypeError("The response does not contain an asks list.")

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

    return asks, bids