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
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
def depth(self, currency_pair, limit=50, raw=False, type='step2'): # v1: https://poloniex.com/public?command=returnOrderBook¤cyPair=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¤cyPair=' + 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
def depth(self, currency_pair, limit=150, raw=False): # v2: https://openapi.digifinex.vip/v2/depth?symbol=usdt_btc&apiKey=59328e10e296a×tamp=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
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
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
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
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
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
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
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
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
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)
def depth(self,currency_pair, limit=10, raw=False): # v2: https://openapi.digifinex.vip/v2/depth?symbol=usdt_btc&apiKey=59328e10e296a×tamp=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
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
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