Exemplo n.º 1
0
    def resetTicker(self, cp):
        pair = cp.split('_')
        if self.name == OKCOIN :
            cp = cp.replace('USDT', 'USD')
        data = json.loads(requests.get('https://www.{}.com/api/v1/ticker.do?symbol={}'.format(self.name, cp)).text)
        if 'error_code' in data:
            logging.error(data)
        elif 'tick' in data or 'ticker' in data:
            ts = data['date']
            if 'tick' in data:
                data = data['tick']
            else:
                data = data['ticker']
            tickData = {
                'price': data['last'],
                'baseVolume': data['vol'],
                'time': ts
            }
            tick = t()
            tick.formate(tickData, pair[0], pair[1])
            tick.lastprice = tick.price

            if self.name == OKCOIN :
                cp = cp.replace('USD', 'USDT')
            self.data.update({cp: tick})
            if cp in self.targe:
                callback(self.notice, cp)
Exemplo n.º 2
0
 def on_message(self, ws, message):
     message = json.loads(message)
     if type(message) is dict:
         return  # {"event":"pong"}
     if time.time() - self.lastTime > 30:
         ws.send('{"event":"ping"}')
         self.lastTime = time.time()
     message = message[0]
     channel = message['channel'].replace('ok_sub_spot_', '').replace('_ticker', '')
     if self.name is OKCOIN :
         channel = channel.replace('USD', 'USDT')
     cp = channel.upper()
     if 'result' in message['data'].keys():
         if message['data']['result']:
             logging.info(MSG_SUBSCRIPT_SUCCESS.format(self.name, 'ticker', message['data']['channel']))
         else:
             logging.error(message['data']['error_msg'])
     elif channel in self.currencypair:
         pair = channel.upper().split('_')
         data = message['data']
         tickData = {
             'price': data['last'],
             'baseVolume': data['vol'],
         }
         tick = t()
         tick.formate(tickData, pair[0], pair[1])
         tick.lastprice = self.data[cp].price
         self.data.update({cp: tick})
         self.isReady = True
         if cp in self.targe:
             if not self.data[cp].lastprice == self.data[cp].price:
                 self.data[cp].lastprice = self.data[cp].price
                 callback(self.notice, cp)
Exemplo n.º 3
0
 def on_message(self, ws, message):
     message = json.loads(message)
     if type(message) is dict:
         if message['event'] == 'subscribed':
             logging.info(
                 MSG_SUBSCRIPT_SUCCESS.format(BITFINEX, 'ticker',
                                              message['pair']))
             self.channelId.update({
                 str(message['chanId']):
                 self.currencypair[message['pair']]
             })
         elif message['event'] == 'error':
             logging.error(message)
     elif self.channelId[str(message[0])] in self.currencypair.values():
         cp = self.channelId[str(message[0])]
         pair = cp.split('_')
         if message[1] == 'hb':  # HeartBeat
             return
         else:
             d = message[1]
             tickerdata = {
                 'change': d[4],
                 'price': d[6],
                 'baseVolume': d[7]
             }
             tick = t()
             tick.formate(tickerdata, pair[0], pair[1])
             self.data.update({cp: tick})
             self.isReady = True
             if cp in self.targe:
                 callback(self.notice, cp)
Exemplo n.º 4
0
    def on_message(self, ws, message):
        message = json.loads(message)
        for data in message:
            try:  ## KeyError Not in the CurrencyPair
                cp = self.currencypair[data['s']]
                pair = cp.split('_')
                tickerData = {
                    'price': data['c'],
                    'change': float(data['p']) * 100,
                    'baseVolume': data['v'],
                    'time': float(data['E'])/1000
                }
                tick = t()
                tick.formate(tickerData, pair[0], pair[1])

                if cp in self.data:
                    tick.lastprice = self.data[cp].price
                self.data.update({cp: tick})
                self.isReady = True
                if cp in self.targe:
                    if not self.data[cp].lastprice == self.data[cp].price:
                        self.data[cp].lastprice = self.data[cp].price
                        callback(self.notice, cp)
            except:
                pass
Exemplo n.º 5
0
 def on_message(self, ws, message):
     message = json.loads(gzip.decompress(message).decode('utf-8'))
     if 'tick' in message:
         channel = message['ch'].replace('market.', '').replace('.detail', '')
         cp = self.currencypair[channel]
         if channel in self.currencypair:
             pair = cp.split('_')
             data = message['tick']
             tickerData = {
                 'price': data['close'],
                 'baseVolume': data['vol'],
             }
             tick = t()
             tick.formate(tickerData, pair[0], pair[1])
             tick.lastprice = self.data[cp].price
             self.data.update({cp: tick})
             self.isReady = True
             if cp in self.targe:
                 if not self.data[cp].lastprice == self.data[cp].price:
                     self.data[cp].lastprice = self.data[cp].price
                     callback(self.notice, cp)
     elif 'status' in message:
         if message['status'] == 'ok':
             logging.info(MSG_SUBSCRIPT_SUCCESS.format(HUOBI, 'ticker', message['subbed']))
         elif message['status'] == 'error':
             logging.error(message['err-msg'])
             return
     elif 'ping' in message:
         self.ws.send(json.dumps({"pong": message['ping']}))
Exemplo n.º 6
0
 def resetTicker(self, cp):
     pair = cp.split('_')
     data = json.loads(
         requests.get('https://api.bitfinex.com/v1/pubticker/{}'.format(
             cp.replace('_', '').replace('USDT', 'USD'))).text)
     tickerData = {
         'price': data['last_price'],
         'baseVolume': data['volume'],
         #'time': float(data['timestamp'])/1000
     }
     tick = t()
     tick.formate(tickerData, pair[0], pair[1])
     self.data.update({cp: tick})
Exemplo n.º 7
0
 def resetTick(self, cp):
     pair = self.currencypair[cp].split('_')
     #data = get_ticker(cp)
     data = json.loads(requests.get('https://api.huobi.pro/market/detail/merged?symbol={}'.format(cp)).text)
     if not data == None:
         data = data['tick']
         tickerData = {
             'price': data['close'],
             'baseVolume': data['vol'],
         }
         tick = t()
         tick.formate(tickerData, pair[0], pair[1])
         self.data.update({self.currencypair[cp]: tick})
Exemplo n.º 8
0
 def resetTick(self):
     data = json.loads(requests.get('https://api.binance.com/api/v1/ticker/24hr').text)  # reset ticker
     for tick in data:
         if tick['symbol'] in self.currencypair:
             cp = self.currencypair[tick['symbol']]
             pair = cp.split('_')
             tickerData = {
                 'price': tick['lastPrice'],
                 'change': float(tick['priceChange']) * 100,
                 'baseVolume': tick['volume'],
                 'time': float(tick['closeTime'])/1000
             }
             tick = t()
             tick.formate(tickerData, pair[0], pair[1])
             self.data.update({cp: tick})
Exemplo n.º 9
0
 def getTickerData(self):
     data = self.caller.returnTicker(
     )  # call PoloniexApi Reset The ticker Data
     self.ids = {market: data[market]['id'] for market in data}
     self.cps = {str(data[market]['id']): market for market in data}
     for currencypair in data:
         tick = t()
         cp = currencypair.split('_')
         data[currencypair].update({'price': data[currencypair]['last']})
         data[currencypair].update(
             {'change': float(data[currencypair]['percentChange']) * 100})
         tick.formate(data[currencypair], cp[1], cp[0])
         tick.lastprice = tick.price
         rcp = reserve(currencypair)  # reverse
         self.data.update({rcp: tick})
     self.isReady = True
Exemplo n.º 10
0
 def on_open(self, ws):
     self.ws.subscribe('ticker')
     datas = self.api.get_market_summaries()
     if datas['success'] is True:
         for data in datas['result']:
             currencypair = reserve(data['MarketName'])
             pair = currencypair
             TickerData = {
                 'price': data['Last'],
                 'baseVolume': data['Volume'],
                 #'TimeStamp': data['TimeStamp']
             }
             ticker = t()
             ticker.formate(TickerData, pair[0], pair[1])
             self.data.update({currencypair: ticker})
         self.isReady = True
         logging.info(MSG_RESET_TICKER_DATA.format(BITTREX))
Exemplo n.º 11
0
 def ticketEvent(self, args):
     cp = args[0]
     pairAr = cp.split('_')
     base = pairAr[0]
     quote = pairAr[1]
     newTickerData = {
         'price': args[1],
         'change': float(args[4]) * 100,
         'baseVolume': args[5],
     }
     tk = t()
     tk.formate(newTickerData, base, quote)
     tk.lastprice = self.data[cp].price
     self.data.update({args[0]: tk})
     self.isReady = True
     if cp in self.targe:
         if not self.data[cp].lastprice == self.data[cp].price:
             self.data[cp].lastprice = self.data[cp].price
             callback(self.notice, cp)
Exemplo n.º 12
0
 def on_message(self, ws, message):
     for data in message['Deltas']:
         cp = reserve(data['MarketName'])
         pair = cp
         ticker = t()
         TickerData = {
             'price': data['Last'],
             'baseVolume': data['Volume'],
             #'TimeStamp': data['TimeStamp']
         }
         ticker.formate(TickerData, pair[0], pair[1])
         ticker.lastprice = self.data[cp].price
         self.data.update({cp: ticker})
         self.isReady = True
         if cp in self.targe:
             if not self.data[cp].lastprice == self.data[cp].price:
                 self.data[cp].lastprice = self.data[cp].price
                 callback(self.notice, cp)
     self.isReady = True
Exemplo n.º 13
0
 def on_message(self, ws, message):
     message = json.loads(message)
     if 'success' in message:
         if message['success'] == False:
             logging.error(message)
     channel = message['channel'].replace('_ticker', '')
     if channel in self.currencypair:
         data = message['ticker']
         cp = self.currencypair[channel]
         pair = cp.split('_')
         tickData = {'price': data['last'], 'baseVolume': data['vol']}
         tick = t()
         tick.formate(tickData, pair[0], pair[1])
         try:
             tick.lastprice = self.data[cp].price
         except:
             pass
         self.data.update({cp: tick})
         self.isReady = True
         if cp in self.targe:
             if not self.data[cp].lastprice == self.data[cp].price:
                 self.data[cp].lastprice = self.data[cp].price
                 callback(self.notice, cp)