コード例 #1
0
ファイル: public.py プロジェクト: howardchung/mining
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 Exception("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
ファイル: trade.py プロジェクト: simhaonline/meteopt
    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 = self._post(params, connection)
        result = []
        for k, v in orders.items():
            result.append(TradeHistoryItem(k, v))

        return result
コード例 #3
0
ファイル: public.py プロジェクト: AndrewSB/equilibrium
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
コード例 #4
0
    def orderList(self,
                  from_number=None,
                  count_number=None,
                  from_id=None,
                  end_id=None,
                  order=None,
                  since=None,
                  end=None,
                  pair=None,
                  active=None,
                  connection=None):

        params = {"method": "OrderList"}

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

        if pair is not None:
            common.validatePair(pair)
            params["pair"] = pair
        if active is not None:
            if active not in (0, 1, True, False):
                raise Exception("Unexpected active parameter: %r" % active)
            params["active"] = int(active)

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

        return result
コード例 #5
0
ファイル: public.py プロジェクト: simhaonline/meteopt
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 Exception("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
コード例 #6
0
ファイル: trade.py プロジェクト: Mwako/btc-e_Trade_bot
 def trade(self, pair, trade_type, rate, amount):
     common.validatePair(pair)
     if trade_type not in ("buy", "sell"):
         raise Exception("Unrecognized trade type: %r" % trade_type)
    
     params = {"method":"Trade",
               "pair":pair,
               "type":trade_type,
               "rate":common.formatCurrency(rate, pair),
               "amount":common.formatCurrency(amount, pair)}
     
     return TradeResult(self._post(params))
コード例 #7
0
    def trade(self, pair, trade_type, rate, amount, connection=None):
        common.validatePair(pair)
        if trade_type not in ("buy", "sell"):
            raise Exception("Unrecognized trade type: %r" % trade_type)

        params = {
            "method": "Trade",
            "pair": pair,
            "type": trade_type,
            "rate": common.formatCurrency(rate, pair),
            "amount": common.formatCurrency(amount, pair)
        }

        return TradeResult(self._post(params, connection))
コード例 #8
0
ファイル: trade.py プロジェクト: geojitsu/CryptoSwitch
 def trade(self, pair, trade_type, rate, amount):
     common.validatePair(pair)
     if trade_type not in ("buy", "sell"):
         raise Exception("Unrecognized trade type: %r" % trade_type)
    
     maxdigits = common.max_digits.get(pair)
     
     params = {"method":"Trade",
               "pair":pair,
               "type":trade_type,
               "rate":common.formatCurrency(rate, maxdigits),
               "amount":common.formatCurrency(amount, maxdigits)}
     
     return TradeResult(self._post(params))
コード例 #9
0
ファイル: public.py プロジェクト: simhaonline/meteopt
def getTicker(pair, connection=None):
    '''Retrieve the ticker for the given pair.  Returns a Ticker instance.'''

    common.validatePair(pair)

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

    response = connection.makeJSONRequest("/api/2/%s/ticker" % pair)

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

    return Ticker(**response[u'ticker'])
コード例 #10
0
ファイル: trade.py プロジェクト: deamoon/meteopt
    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
コード例 #11
0
ファイル: trade.py プロジェクト: simhaonline/meteopt
    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
コード例 #12
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
コード例 #13
0
ファイル: public.py プロジェクト: JamesGalt/btc-e_Trade_bot
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
コード例 #14
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
コード例 #15
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
コード例 #16
0
ファイル: public.py プロジェクト: JamesGalt/btc-e_Trade_bot
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
コード例 #17
0
ファイル: trade.py プロジェクト: Mwako/btc-e_Trade_bot
    def tradeHistory(self, from_number = None, count_number = None,
                  from_id = None, end_id = None, order = None,
                  since = None, end = None, pair = 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 = self._post(params)
        result = []
        for k, v in orders.items():
            result.append(TradeHistoryItem(k, v))
            
        return result
コード例 #18
0
ファイル: public.py プロジェクト: simhaonline/meteopt
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 Exception("The response is not a dict.")

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

    return trade_fee
コード例 #19
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
コード例 #20
0
ファイル: public.py プロジェクト: geojitsu/CryptoSwitch
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
コード例 #21
0
def getTradeHistory(pair, connection = None):
    '''Retrieve the trade history for the given pair.  Returns a list of 
    Trade instances.'''
    
    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 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
コード例 #22
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
コード例 #23
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
コード例 #24
0
ファイル: public.py プロジェクト: FrenchFriesKetchup/btce-api
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 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
コード例 #25
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
コード例 #26
0
ファイル: public.py プロジェクト: AndrewSB/equilibrium
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
コード例 #27
0
ファイル: trade.py プロジェクト: Mwako/btc-e_Trade_bot
    def orderList(self, from_number = None, count_number = None,
                  from_id = None, end_id = None, order = None,
                  since = None, end = None, pair = None, active = None):

        params = {"method":"OrderList"}

        setHistoryParams(params, from_number, count_number, from_id, end_id,
            order, since, end)
        
        if pair is not None:
            common.validatePair(pair)
            params["pair"] = pair
        if active is not None:
            if active not in (0, 1, True, False):
                raise Exception("Unexpected active parameter: %r" % active)
            params["active"] = int(active)

        orders = self._post(params)
        result = []
        for k, v in orders.items():
            result.append(OrderItem(k, v))
            
        return result
コード例 #28
0
ファイル: trade.py プロジェクト: Fizzixnerd/bter-api
    def placeOrder(self, pair, trade_type, rate, amount, connection=None, update_delay=None, error_handler=None):
        common.validatePair(pair)
        if trade_type.lower() not in ("buy", "sell"):
            if trade_type.lower() == 'bid':
                trade_type = 'buy'
            elif trade_type.lower() == 'ask':
                trade_type = 'sell'
            else:
                raise Exception("Unrecognized trade type: %r" % trade_type)
       
        params = {"pair": pair,
                  "type": trade_type.upper(),
                  "rate": common.formatCurrency(rate, pair, 'price'),
                  "amount": common.formatCurrency(amount, pair, 'amount')}

        order = OrderItem(self._post('placeorder', params=params, connection=connection,
                                     error_handler=error_handler).get(u'order_id'), initial_params=params, date=now())

        if update_delay is not None:
            time.sleep(update_delay)
            order = self.getOrderStatus(order.order_id, connection=None)

        return order
コード例 #29
0
    def placeOrder(self,
                   pair,
                   trade_type,
                   rate,
                   amount,
                   connection=None,
                   update_delay=None,
                   error_handler=None):
        common.validatePair(pair)
        if trade_type.lower() not in ("buy", "sell"):
            if trade_type.lower() == 'bid':
                trade_type = 'buy'
            elif trade_type.lower() == 'ask':
                trade_type = 'sell'
            else:
                raise Exception("Unrecognized trade type: %r" % trade_type)

        params = {
            "pair": pair,
            "type": trade_type.upper(),
            "rate": common.formatCurrency(rate, pair, 'price'),
            "amount": common.formatCurrency(amount, pair, 'amount')
        }

        order = OrderItem(self._post(
            'placeorder',
            params=params,
            connection=connection,
            error_handler=error_handler).get(u'order_id'),
                          initial_params=params,
                          date=now())

        if update_delay is not None:
            time.sleep(update_delay)
            order = self.getOrderStatus(order.order_id, connection=None)

        return order
コード例 #30
0
ファイル: public.py プロジェクト: howardchung/mining
def getTickerInfo(pair):
    common.validatePair(pair)
    connection = common.BTCEConnection()
    ticker = connection.makeJSONRequest("/api/2/%s/ticker" % pair)
    return ticker["ticker"]
コード例 #31
0
ファイル: ticker.py プロジェクト: Fizzixnerd/bter-api
 def __init__(self, pairs=common.all_pairs):
     for pair in pairs: common.validatePair(pair)
     self._pairs = pairs
     self._all = self._pairs == common.all_pairs