コード例 #1
0
    def run(self):
        while self.isRun:
            self.mutex.lock()
            bithumbDict = dict()

            prices = self.bithumb.get_current_price('ALL')
            orderbooks = self.bithumb.get_orderbook('ALL')
            if orderbooks and prices:
                orderbooks = orderbooks['data']
                for i in self.bithumbList:
                    try:
                        price = prices[i]['closing_price']
                        orderbook = orderbooks[i]
                        ask = orderbook['asks'][0]['price'] + '/' + str(
                            round(float(orderbook['asks'][0]['quantity']), 2))
                        bid = orderbook['bids'][0]['price'] + '/' + str(
                            round(float(orderbook['bids'][0]['quantity']), 2))
                        bithumbDict[i] = dict()
                        bithumbDict[i]['price'] = price
                        bithumbDict[i]['ask'] = ask
                        bithumbDict[i]['bid'] = bid
                    except Exception as e:
                        debuginfo(e)
                        pass
                self.bithumb_data.emit(bithumbDict)
            self.mutex.unlock()
コード例 #2
0
 def get_symbol_list(self):
     bithumbList = list()
     try:
         bithumbList = self.bithumb.get_tickers()
     except Exception as e:
         debuginfo(e)
         pass
     return bithumbList
コード例 #3
0
 def get_prices(self):
     prices = dict()
     try:
         for i in self.binance.get_all_tickers():
             prices[i['symbol']] = i['price']
     except Exception as e:
         debuginfo(e)
         pass
     return prices
コード例 #4
0
 def get_symbol_list(self):
     upbitList = list()
     try:
         for i in self.upbit.get_tickers(fiat="KRW"):
             upbitList.append(i.split('KRW-')[1])
     except Exception as e:
         debuginfo(e)
         pass
     return upbitList
コード例 #5
0
 def get_orderbooks(self):
     orderbooks = dict()
     try:
         for i in self.binance.get_orderbook_tickers():
             orderbooks[i['symbol']] = dict()
             orderbooks[i['symbol']]['bidPrice'] = i['bidPrice']
             orderbooks[i['symbol']]['bidQty'] = i['bidQty']
             orderbooks[i['symbol']]['askPrice'] = i['askPrice']
             orderbooks[i['symbol']]['askQty'] = i['askQty']
     except Exception as e:
         debuginfo(e)
         pass
     return orderbooks
コード例 #6
0
 def get_symbol_list(self):
     binanceList = list()
     try:
         for i in self.binance.get_all_tickers():
             symbol = i['symbol']
             if symbol[-3:] == 'BTC':
                 binanceList.append(symbol[:-3])
             if symbol == 'BTCUSDT':
                 binanceList.append(symbol[:-4])
     except Exception as e:
         debuginfo(e)
         pass
     return binanceList
コード例 #7
0
    def run(self):
        while self.isRun:
            self.mutex.lock()
            binanceDict = dict()
            self.get_dollor()
            prices = self.get_prices()
            orderbooks = self.get_orderbooks()

            try:
                BTCUSDT = float(prices['BTCUSDT'])
                binanceDict['BTC'] = dict()
                binanceDict['BTC']['price'] = str(
                    round(BTCUSDT * self.exchange_rate, 2))
                binanceDict['BTC']['ask'] = str(
                    round(
                        float(orderbooks['BTCUSDT']['askPrice']) *
                        self.exchange_rate, 2)) + '/' + str(
                            round(float(orderbooks['BTCUSDT']['askQty']), 2))
                binanceDict['BTC']['bid'] = str(
                    round(
                        float(orderbooks['BTCUSDT']['bidPrice']) *
                        self.exchange_rate, 2)) + '/' + str(
                            round(float(orderbooks['BTCUSDT']['bidQty']), 2))

            except Exception as e:
                debuginfo(e)

            for i in self.binanceList:
                if i == 'BTCUSDT':
                    continue
                try:
                    symbol = i.replace('BTC', '')
                    binanceDict[symbol] = dict()
                    binanceDict[symbol]['price'] = self.calculate_krw(
                        prices[i], BTCUSDT, self.exchange_rate)
                    binanceDict[symbol]['ask'] = self.calculate_krw(
                        orderbooks[i]['askPrice'], BTCUSDT,
                        self.exchange_rate) + '/' + str(
                            round(float(orderbooks[i]['askQty']), 2))
                    binanceDict[symbol]['bid'] = self.calculate_krw(
                        orderbooks[i]['bidPrice'], BTCUSDT,
                        self.exchange_rate) + '/' + str(
                            round(float(orderbooks[i]['bidQty']), 2))
                except Exception as e:
                    debuginfo(e)
                    pass

            self.binance_data.emit(binanceDict)
            self.mutex.unlock()
コード例 #8
0
 def get_dollor(self):
     try:
         res = requests.get('http://finance.naver.com/')
         text = res.text
         soup = BeautifulSoup(text, 'html.parser')
         td = soup.select_one(
             "#content > div.article2 > div.section1 > div.group1 > table > tbody > tr > td"
         )
         exchange_rate = ''
         for i in td.text:
             if i == ',':
                 pass
             else:
                 exchange_rate += i
         self.exchange_rate = float(exchange_rate)
     except Exception as e:
         debuginfo(e)
コード例 #9
0
 def run(self):
     while self.isRun:
         self.mutex.lock()
         upbitDict = dict()
         prices = self.upbit.get_current_price(self.upbitList)
         orderbooks = self.upbit.get_orderbook(self.upbitList)
         if orderbooks and prices:
             for i in orderbooks:
                 try:
                     symbol = i['market'].split('-')[1]
                     orderbook = i['orderbook_units'][0]
                     ask = str(orderbook['ask_price']) + '/' + str(
                         round(orderbook['ask_size'], 2))
                     bid = str(orderbook['bid_price']) + '/' + str(
                         round(orderbook['bid_size'], 2))
                     upbitDict[symbol] = dict()
                     upbitDict[symbol]['price'] = str(
                         round(prices[i['market']], 2))
                     upbitDict[symbol]['ask'] = ask
                     upbitDict[symbol]['bid'] = bid
                 except Exception as e:
                     debuginfo(e)
             self.upbit_data.emit(upbitDict)
         self.mutex.unlock()
コード例 #10
0
ファイル: main.py プロジェクト: JunTae90/coin_viewer
    def fusion(self):

        try:
            fusion_dict = dict()
            for i in self.binance_dict.keys():
                if "ask" not in self.binance_dict[i].keys():
                    continue
                if "bid" not in self.binance_dict[i].keys():
                    continue
                if (self.binance_dict[i]['ask']
                        == '0.0/0.0') and (self.binance_dict[i]['bid']
                                           == '0.0/0.0'):
                    continue
                if (i in self.upbit_dict.keys()) or (
                        i in self.bithumb_dict.keys()):
                    calculated_dict = dict()
                    calculated_dict['binance'] = self.binance_dict[i]
                    if i in self.bithumb_dict.keys():
                        calculated_dict['bithumb'] = self.bithumb_dict[i]
                        calculated_dict['bithumb_premium'] = round(
                            ((float(self.bithumb_dict[i]['price']) -
                              float(self.binance_dict[i]['price'])) /
                             float(self.binance_dict[i]['price'])) * 100, 2)
                        calculated_dict['main_premium'] = calculated_dict[
                            'bithumb_premium']
                    if i in self.upbit_dict.keys():
                        calculated_dict['upbit'] = self.upbit_dict[i]
                        calculated_dict['upbit_premium'] = round(
                            ((float(self.upbit_dict[i]['price']) -
                              float(self.binance_dict[i]['price'])) /
                             float(self.binance_dict[i]['price'])) * 100, 2)
                        if 'bithumb_premium' in calculated_dict.keys():
                            if abs(calculated_dict['upbit_premium']) > abs(
                                    calculated_dict['bithumb_premium']):
                                calculated_dict[
                                    'main_premium'] = calculated_dict[
                                        'upbit_premium']
                        else:
                            calculated_dict['main_premium'] = calculated_dict[
                                'upbit_premium']
                    else:
                        calculated_dict['upbit_premium'] = float('inf')
                    fusion_dict[i] = calculated_dict

            if self.boolSort:
                fusion_list = list()
                for i in fusion_dict.keys():
                    data = fusion_dict[i]
                    fusion_list.append({
                        "symbol": i,
                        "upbit_premium": data["upbit_premium"]
                    })
                    fusion_list.sort(key=itemgetter("upbit_premium"))

                self.sortedList = list()
                for j in fusion_list:
                    self.sortedList.append(j["symbol"])

                self.boolSort = False

            if not self.sortedList:
                lists = fusion_dict.keys()
            else:
                lists = self.sortedList

            for i in range(self.num):
                widget_name = "coin_widget_{}".format(i)
                widget = self.findChild(CoinWidget, widget_name)
                widget.clear()
            cnt = 0
            for i in lists:
                data = fusion_dict[i]
                widget_name = "coin_widget_{}".format(cnt)
                widget = self.findChild(CoinWidget, widget_name)
                widget.setData(i, data)
                cnt += 1

        except Exception as e:
            debuginfo(e)
            pass