Beispiel #1
0
    def trades(self, currency_pair, limit=1000, raw=False, since=None):
        # https://api.liquid.com/executions?product_id=5&timestamp=1567267200&limit=1000
        TRADES_RESOURCE = "/executions"
        if since is None:
            pass
        else:
            params = 'product_id=5' + '&limit=' + str(
                limit) + "&timestamp=" + str(since)
        result = None
        while result is None:
            try:
                result = requests.get(self.base_url + TRADES_RESOURCE,
                                      params,
                                      timeout=30)
            except:
                result = None

        if result.status_code != 200:
            time.sleep(300)
            self.trades(self, currency_pair, since=since, raw=True)
        if raw == True:
            return result.text
        else:
            result = universal.Trades(self.MARKET, currency_pair, result.text,
                                      2)
            return result
Beispiel #2
0
 def trades(self,
            currency_pair,
            limit=1000,
            since=None,
            raw=False,
            order_type=None):
     # https://api.kraken.com/0/public/Trades?pair=XXBTZUSD
     TRADES_RESOURCE = "/0/public/Trades"
     params = make_currency_pair_string_for_restful(currency_pair)
     if since:
         params += '&since=' + str(since)
     else:
         pass
     result = None
     while result is None:
         try:
             result = requests.get(self.base_url_for_rest + TRADES_RESOURCE,
                                   params)
         except:
             result = None
     if result.status_code != 200:
         return ERRORCODE.Error_Code_For_Status_Code[result.status_code]
     if raw == True:
         return result.text
     else:
         result = universal.Trades(self.MARKET, currency_pair, result.text,
                                   2, None, order_type)
         return result
Beispiel #3
0
def digest_data_from_db(limit=0, agregational=False):
    trades = UNIVERSAL.Trades('kraken', currency_pair, None, None)
    if limit==0:
        sql='select * from ' + table_name + ' order by timestamp desc'
    else:
        sql='select * from ' + table_name + ' order by timestamp desc limit ' + str(limit)
    rows=pgmanager.select(sql)

    previous_trade=UNIVERSAL.TradeInfo(0,0,0,0,None,2)
    for row in rows:
        date=row[6]
        price=float(row[1])
        amount=float(row[2])
        trade_type=row[3]
        tid=None
        status=2
        if agregational==True:
            if date == previous_trade.timestamp and trade_type == previous_trade.trade_type:
                price = (previous_trade.price * previous_trade.amount + amount * price) / (
                            previous_trade.amount + amount)
                amount += previous_trade.amount
                previous_trade = UNIVERSAL.TradeInfo(date, price, amount, trade_type, tid, status)
            else:
                import copy
                trade = copy.deepcopy(previous_trade)
                trades.trades.append(trade)
                previous_trade = copy.deepcopy(UNIVERSAL.TradeInfo(date, price, amount, trade_type, tid, status))
        else:
            trade = UNIVERSAL.TradeInfo(date, price, amount, trade_type, tid, status)
            trades.trades.append(trade)
    trades.trades.pop(0)
    return trades
Beispiel #4
0
 def trades(self, currency_pair=''):
     TRADES_RESOURCE = "/api/v1/trades.do"
     params = ''
     if currency_pair:
         params = 'symbol=%(symbol)s' % {'symbol': currency_pair}
     result = httpGet(self.base_url, TRADES_RESOURCE, params)
     result = universal.Trades(self.__market, currency_pair, result, 2)
     return result
Beispiel #5
0
 def trade_list(self, currency_pair, current_page=1, page_length=200):
     from packages import util
     aex2 = util.Client(self.account.api_key, self.account.secret_key,
                        self.user_id)
     result = aex2.getMyTradeList(currency_pair.reference,
                                  currency_pair.base, current_page)
     result = universal.Trades(self.MARKET, currency_pair, result, 2,
                               self.user_id)
     return result
def combine_trades_by_timestamp(rows):
    trades = []
    current_timestamp = rows[0][3]
    current_price = rows[0][5]
    current_amount = rows[0][6]
    current_trade_type = rows[0][4]
    rows_len = len(rows)
    cnt = 1
    trade = UNIVERSAL.TradeInfo(current_timestamp, current_price,
                                current_amount, current_trade_type)

    while cnt < rows_len:
        row = rows[cnt]
        timestamp = row[3]
        price = row[5]
        amount = row[6]
        trade_type = row[4]
        if current_timestamp == timestamp:
            if current_trade_type == trade_type:
                if current_price == price:
                    # 时间、方向、价格都相同,认为是同一笔交易
                    trade.amount += amount
                else:
                    # 时间、类型相同,价格不同,不是同一笔交易
                    trades.append(trade)
                    current_timestamp = timestamp
                    current_price = price
                    current_amount = amount
                    current_trade_type = trade_type
                    trade = UNIVERSAL.TradeInfo(current_timestamp,
                                                current_price, current_amount,
                                                current_trade_type)
            else:
                # 时间相同,类型不同,认为是不同交易
                trades.append(trade)
                current_timestamp = timestamp
                current_price = price
                current_amount = amount
                current_trade_type = trade_type
                trade = UNIVERSAL.TradeInfo(current_timestamp, current_price,
                                            current_amount, current_trade_type)
        else:
            # 时间戳不同,不是同一笔交易
            trades.append(trade)
            current_timestamp = timestamp
            current_price = price
            current_amount = amount
            current_trade_type = trade_type
            trade = UNIVERSAL.TradeInfo(current_timestamp, current_price,
                                        current_amount, current_trade_type)
        cnt += 1
    _trades = UNIVERSAL.Trades('Kraken', currency_pair, None)
    _trades.trades = trades
    return _trades
Beispiel #7
0
 def trades(self, currency_pair, limit=300, raw=False):
     # https://openapi.digifinex.com/v3/trades?market=btc_usdt&limit=30
     TRADES_RESOURCE = "/v3/trades"
     params = 'market=' + currency_pair.base + '_' + currency_pair.reference + '&limit=' + str(limit)
     result = requests.get(self.base_url + TRADES_RESOURCE, params)
     if result.status_code!=200:
         return ERRORCODE.Error_Code_For_Status_Code[result.status_code]
     if raw == True:
         return result.text
     else:
         result = universal.Trades(self.MARKET, currency_pair, result.text,2)
         return result
Beispiel #8
0
 def trades(self, currency_pair, since=1, limit=1000, raw=False):
     # https://openapi.digifinex.com/v3/trades?market=btc_usdt&limit=30
     TRADES_RESOURCE = "/api/v3/historicalTrades"
     headers={"X-MBX-APIKEY":self.account.api_key}
     params="limit=1000&symbol=" + currency_pair.base.upper() + currency_pair.reference.upper() + "&fromId="+str(since)
     result = requests.get(self.base_url + TRADES_RESOURCE, params, verify=False, headers=headers)
     if result.status_code!=200:
         return ERRORCODE.Error_Code_For_Status_Code[result.status_code]
     if raw == True:
         return result.text
     else:
         result = universal.Trades(self.MARKET, currency_pair, result.text,2)
         return result
Beispiel #9
0
 def trades(self, currency_pair, tid=None, raw=False):
     # https://api.aex.zone/trades.php?c=btc&mk_type=cnc
     TRADES_RESOURCE = "/trades.php"
     params = make_currency_pair_string(currency_pair)
     if not tid is None:
         params+='&tid='+str(tid)
     result = requests.get(self.base_url + TRADES_RESOURCE, params)
     if result.status_code!=200:
         return ERRORCODE.Error_Code_For_Status_Code[result.status_code]
     if raw == True:
         return result.text
     else:
         result = universal.Trades(self.MARKET, currency_pair, result.text,2,self.user_id)
         return result
Beispiel #10
0
 def _create_trades_link(self, currency_pair):
     self._trades = universal.Trades('Kraken', currency_pair, [], 2)
     pair = make_currency_pair_string(currency_pair)
     self.ws.send(json.dumps({
         "event": "subscribe",
         # "event": "ping",
         "pair": [pair],
         # "subscription": {"name": "ticker"}
         # "subscription": {"name": "spread"}
         "subscription": {"name": "trade"},
         # "subscription": {"name": "book", "depth": limit}
         # "subscription": {"name": "ohlc", "interval": 5}
     }))
     print('subscription for trades has been sent!')
     self.is_trades_subscribed = True
     if self._on_reading_message_flag==False:
         self._on_reading_message(currency_pair)