Esempio n. 1
0
    def depth(self, currency_pair, limit=20, raw=False, type='step2'):
        # v1: https://api.liquid.com/products/5/price_levels
        '''

        :param currency_pair:
        :param raw:
        :return:
        '''
        # there are 4 required params: symbol, apikey, timestamp, sign
        DEPTH_RESOURCE = "/products/5/price_levels"
        symbol = make_currency_pair_string(currency_pair)
        # 下面的代码仅适用于v2版本的api
        # timestamp=str(int(time.time()))
        # _sign=sign(self.account,{
        #     'symbol':symbol,
        #     'timestamp':timestamp,
        # })
        # params={
        #     'symbol': symbol,
        #     'timestamp': timestamp,
        #     'apiKey':self.account.api_key,
        #     'sign':_sign
        # }

        params = 'symbol=' + symbol + '&ldepth=' + str(limit) + '&type=' + type
        result = requests.get(self.base_url + DEPTH_RESOURCE)
        if result.status_code != 200:
            return ERRORCODE.Error_Code_For_Status_Code[result.status_code]
        if raw == True:
            return result.text
        else:
            result = universal.Depth(self.MARKET, currency_pair, result.text)
            return result
Esempio n. 2
0
    def depth(self, currency_pair, limit=20, raw=False, type='step2'):
        # v1: 'https://api.bitso.com/v3/order_book?book=btc_mxn'
        '''

        :param currency_pair:
        :param raw:
        :return:
        '''
        # there are 4 required params: symbol, apikey, timestamp, sign
        DEPTH_RESOURCE = "/v3/order_book"
        symbol = make_currency_pair_string(currency_pair)
        # 下面的代码仅适用于v2版本的api
        # timestamp=str(int(time.time()))
        # _sign=sign(self.account,{
        #     'symbol':symbol,
        #     'timestamp':timestamp,
        # })
        # params={
        #     'symbol': symbol,
        #     'timestamp': timestamp,
        #     'apiKey':self.account.api_key,
        #     'sign':_sign
        # }

        params = 'book=' + symbol
        result = requests.get(self.base_url + DEPTH_RESOURCE,
                              params,
                              timeout=5)
        if result.status_code != 200:
            return ERRORCODE.Error_Code_For_Status_Code[result.status_code]
        if raw == True:
            return result.text
        else:
            result = universal.Depth(self.MARKET, currency_pair, result.text)
            return result
Esempio n. 3
0
    def depth(self, currency_pair, limit=50, raw=False, type='step2'):
        # v1: https://poloniex.com/public?command=returnOrderBook&currencyPair=USDT_BTC&depth=10
        '''

        :param currency_pair:
        :param raw:
        :return:
        '''
        # there are 4 required params: symbol, apikey, timestamp, sign
        DEPTH_RESOURCE = "/public"
        symbol = make_currency_pair_string(currency_pair)
        # 下面的代码仅适用于v2版本的api
        # timestamp=str(int(time.time()))
        # _sign=sign(self.account,{
        #     'symbol':symbol,
        #     'timestamp':timestamp,
        # })
        # params={
        #     'symbol': symbol,
        #     'timestamp': timestamp,
        #     'apiKey':self.account.api_key,
        #     'sign':_sign
        # }

        params = 'command=returnOrderBook&currencyPair=' + make_currency_pair_string(
            currency_pair) + '&depth=' + str(limit)
        result = requests.get(self.base_url + DEPTH_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.Depth(self.MARKET, currency_pair, result.text)
            return result
Esempio n. 4
0
    def depth(self, currency_pair, limit=150, raw=False):
        # v2: https://openapi.digifinex.vip/v2/depth?symbol=usdt_btc&apiKey=59328e10e296a&timestamp=1410431266&sign=0a8d39b515fd8f3f8b848a4c459884c2
        # v3:https://openapi.digifinex.com/v3/order_book?market=btc_usdt&limit=30
        '''

        :param currency_pair:
        :param raw:
        :return:
        '''
        # there are 4 required params: symbol, apikey, timestamp, sign
        DEPTH_RESOURCE = "/v3/order_book"
        symbol = make_currency_pair_string(currency_pair)
        # 下面的代码仅适用于v2版本的api
        # timestamp=str(int(time.time()))
        # _sign=sign(self.account,{
        #     'symbol':symbol,
        #     'timestamp':timestamp,
        # })
        # params={
        #     'symbol': symbol,
        #     'timestamp': timestamp,
        #     'apiKey':self.account.api_key,
        #     'sign':_sign
        # }
        params = 'market=' + currency_pair.base + '_' + currency_pair.reference + '&limit=' + str(
            limit)
        result = requests.get(self.base_url + DEPTH_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.Depth(self.MARKET, currency_pair, result.text)
            return result
Esempio n. 5
0
    def depth(self, currency_pair, limit=20, raw=False, type='step2'):
        # v1: https://data.gateio.co/api2/1/orderBook/usdt_cnyx
        '''

        :param currency_pair:
        :param raw:
        :return:
        '''
        # there are 4 required params: symbol, apikey, timestamp, sign
        DEPTH_RESOURCE = "/api2/1/orderBook/"
        symbol = make_currency_pair_string(currency_pair)
        # 下面的代码仅适用于v2版本的api
        # timestamp=str(int(time.time()))
        # _sign=sign(self.account,{
        #     'symbol':symbol,
        #     'timestamp':timestamp,
        # })
        # params={
        #     'symbol': symbol,
        #     'timestamp': timestamp,
        #     'apiKey':self.account.api_key,
        #     'sign':_sign
        # }
        DEPTH_RESOURCE += make_currency_pair_string(currency_pair)
        result = requests.get(self.base_url + DEPTH_RESOURCE)
        if result.status_code != 200:
            return ERRORCODE.Error_Code_For_Status_Code[result.status_code]
        if raw == True:
            return result.text
        else:
            result = universal.Depth(self.MARKET, currency_pair, result.text)
            return result
Esempio n. 6
0
    def depth(self, currency_pair, limit=50, raw=False, type='step2'):
        # v1: http://api.zb.cn/data/v1/depth?market=btc_usdt&size=3
        '''

        :param currency_pair:
        :param raw:
        :return:
        '''
        # there are 4 required params: symbol, apikey, timestamp, sign
        DEPTH_RESOURCE = "/data/v1/depth"
        symbol = make_currency_pair_string(currency_pair)
        # 下面的代码仅适用于v2版本的api
        # timestamp=str(int(time.time()))
        # _sign=sign(self.account,{
        #     'symbol':symbol,
        #     'timestamp':timestamp,
        # })
        # params={
        #     'symbol': symbol,
        #     'timestamp': timestamp,
        #     'apiKey':self.account.api_key,
        #     'sign':_sign
        # }

        params = 'market=' + symbol + '&size=' + str(limit)
        result = requests.get(self.base_url + DEPTH_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.Depth(self.MARKET, currency_pair, result.text)
            return result
Esempio n. 7
0
    def depth(self, currency_pair, limit=150, raw=False):
        # v1:https://api.itbit.com/v1/markets/XBTUSD/order_book?tickerSymbol=XBTUSD
        '''

        :param currency_pair:
        :param raw:
        :return:
        '''
        # there are 4 required params: symbol, apikey, timestamp, sign
        DEPTH_RESOURCE = "/v1/markets/"
        symbol = make_currency_pair_string(currency_pair)
        # 下面的代码仅适用于v2版本的api
        # timestamp=str(int(time.time()))
        # _sign=sign(self.account,{
        #     'symbol':symbol,
        #     'timestamp':timestamp,
        # })
        # params={
        #     'symbol': symbol,
        #     'timestamp': timestamp,
        #     'apiKey':self.account.api_key,
        #     'sign':_sign
        # }
        DEPTH_RESOURCE += make_currency_pair_string(
            currency_pair) + '/order_book'
        result = requests.get(self.base_url + DEPTH_RESOURCE)
        if result.status_code != 200:
            return ERRORCODE.Error_Code_For_Status_Code[result.status_code]
        if raw == True:
            return result.text
        else:
            result = universal.Depth(self.MARKET, currency_pair, result.text)
            return result
Esempio n. 8
0
    def depth(self, currency_pair, limit=20, raw=False):
        # v1: 'https://api.pro.coinbase.com/products/BTC-USD/book?level=2'
        '''

        :param currency_pair:
        :param raw:
        :return:
        '''
        # there are 4 required params: symbol, apikey, timestamp, sign
        DEPTH_RESOURCE = "/products/"
        symbol = make_currency_pair_string(currency_pair)
        # 下面的代码仅适用于v2版本的api
        # timestamp=str(int(time.time()))
        # _sign=sign(self.account,{
        #     'symbol':symbol,
        #     'timestamp':timestamp,
        # })
        # params={
        #     'symbol': symbol,
        #     'timestamp': timestamp,
        #     'apiKey':self.account.api_key,
        #     'sign':_sign
        # }
        DEPTH_RESOURCE += symbol + '/book'
        params = 'level=2'
        result = requests.get(self.base_url + DEPTH_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.Depth(self.MARKET, currency_pair, result.text)
            return result
Esempio n. 9
0
File: okex.py Progetto: cc5985/robot
    def depth(self, currency_pair, limit=200, raw=False, type='1'):
        # v3: 'https://www.okex.com/api/spot/v3/instruments/BTC-USDT/book?size=100&depth=1'
        '''

        :param currency_pair:
        :param raw:
        :return:
        '''
        # there are 4 required params: symbol, apikey, timestamp, sign
        DEPTH_RESOURCE = "/api/spot/v3/instruments/"
        symbol = make_currency_pair_string(currency_pair)
        # 下面的代码仅适用于v2版本的api
        # timestamp=str(int(time.time()))
        # _sign=sign(self.account,{
        #     'symbol':symbol,
        #     'timestamp':timestamp,
        # })
        # params={
        #     'symbol': symbol,
        #     'timestamp': timestamp,
        #     'apiKey':self.account.api_key,
        #     'sign':_sign
        # }
        DEPTH_RESOURCE += symbol + '/book'
        params = 'size=' + str(limit) + '&depth=' + type
        result = requests.get(self.base_url + DEPTH_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.Depth(self.MARKET, currency_pair, result.text)
            return result
Esempio n. 10
0
    def depth(self, currency_pair, limit=100, raw=False):
        # v1: 'https://api.binance.com/api/v1/depth?symbol=BTCUSDT'
        '''

        :param currency_pair:
        :param raw:
        :return:
        '''
        # there are 4 required params: symbol, apikey, timestamp, sign
        DEPTH_RESOURCE = "/api/v1/market/orderbook/level2_100"
        symbol = make_currency_pair_string(currency_pair)
        # 下面的代码仅适用于v2版本的api
        # timestamp=str(int(time.time()))
        # _sign=sign(self.account,{
        #     'symbol':symbol,
        #     'timestamp':timestamp,
        # })
        # params={
        #     'symbol': symbol,
        #     'timestamp': timestamp,
        #     'apiKey':self.account.api_key,
        #     'sign':_sign
        # }

        params = 'symbol=' + symbol + '&limit=' + str(limit)
        result = requests.get(self.base_url + DEPTH_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.Depth(self.MARKET, currency_pair, result.text)
            return result
Esempio n. 11
0
 def depth(self, currency_pair='btc_usdt'):
     DEPTH_RESOURCE = "/api/v1/depth.do"
     params = ''
     if currency_pair:
         params = 'symbol=%(symbol)s' % {'symbol': currency_pair}
     result = httpGet(self.base_url, DEPTH_RESOURCE, params)
     print(result)
     result = universal.Depth(self.__market, currency_pair, result)
     return result
Esempio n. 12
0
 def depth(self, currency_pair, raw=False):
     # https://api.aex.zone/depth.php?c=btc&mk_type=cnc
     DEPTH_RESOURCE = "/depth.php"
     params = make_currency_pair_string(currency_pair)
     result = requests.get(self.base_url + DEPTH_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.Depth(self.MARKET, currency_pair, result.text)
         return result
Esempio n. 13
0
 def _create_depth_link(self, currency_pair, limit=10):
     self._depth = universal.Depth('Kraken', currency_pair)
     self.api_update_book={"bid":{}, "ask":{}}
     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 depth has been sent!')
     self.is_depth_subscribed=True
     if self._on_reading_message_flag==False:
         self._on_reading_message(currency_pair)
Esempio n. 14
0
    def depth(self,currency_pair, limit=10, raw=False):
        # v2: https://openapi.digifinex.vip/v2/depth?symbol=usdt_btc&apiKey=59328e10e296a&timestamp=1410431266&sign=0a8d39b515fd8f3f8b848a4c459884c2
        # v3:https://openapi.digifinex.com/v3/order_book?market=btc_usdt&limit=30
        '''

        :param currency_pair:
        :param raw:
        :return:
        '''
        # there are 4 required params: symbol, apikey, timestamp, sign
        import threading
        while True:
            if self.is_depth_subscribed==False:
                thread=threading.Thread(target=self._create_depth_link,args=(currency_pair,limit))
                thread.start()
                time.sleep(2)
            else:
                self._depth=universal.Depth(self.MARKET,currency_pair,self.api_update_book)
                return self._depth
Esempio n. 15
0
    def depth(self, currency_pair, limit=20, raw=False, type='step2'):
        # v1: 'https://api.bitfinex.com/v1/book/btcusd'
        '''

        :param currency_pair:
        :param raw:
        :return:
        '''
        # there are 4 required params: symbol, apikey, timestamp, sign
        DEPTH_RESOURCE = "/book/"
        symbol = make_currency_pair_string(currency_pair)
        DEPTH_RESOURCE += symbol
        params = 'symbol=' + symbol + '&ldepth=' + str(limit) + '&type=' + type
        result = requests.get(self.base_url + DEPTH_RESOURCE, timeout=5)
        if result.status_code != 200:
            return ERRORCODE.Error_Code_For_Status_Code[result.status_code]
        if raw == True:
            return result.text
        else:
            result = universal.Depth(self.MARKET, currency_pair, result.text)
            return result
Esempio n. 16
0
    def depth(self,currency_pair, limit=20, raw=False, type='step2'):
        # v1: https://api.bittrex.com/api/v1.1/public/getorderbook?market=USDT-BTC&type=both
        '''

        :param currency_pair:
        :param raw:
        :return:
        '''
        # there are 4 required params: symbol, apikey, timestamp, sign
        DEPTH_RESOURCE = "/api/v1.1/public/getorderbook"
        symbol = make_currency_pair_string(currency_pair)

        params='market='+symbol+'&type=both'
        result = requests.get(self.base_url+DEPTH_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.Depth(self.MARKET, currency_pair, result.text)
            return result