Ejemplo n.º 1
0
    def _fetch_market_ticker(self, market_id):

        market_config, _ = config.get_market_by_id(market_id)
        exchange, market = market_config['exchange'], market_config['market']
        provider = btcwidget.exchanges.factory.get(exchange)
        try:
            price = provider.ticker(market)
        except Exception as e:
            print('Failed to update ticker data for {}: {}'.format(
                market_id, e),
                  file=sys.stderr)
            price = None

        if price:
            price_str = btcwidget.currency.service.format_price(
                price, market[3:])
            print('{} {} ticker: {}'.format(provider.get_name(), market,
                                            price_str))
            GObject.idle_add(self._main_win.set_current_price, market_id,
                             price_str)

            self._check_alarms(exchange, market, price)

            self._last_ticer[market_id] = {
                'time': time.time(),
                'open': price,
                'close': price,
            }
            if market_id in self._graph_data_dict:
                graph_data = self._graph_data_dict[market_id]
                graph_data.append(self._last_ticer[market_id])
                self._update_market_graph(market_id)

        self._ticker_threads.pop(market_id, None)
Ejemplo n.º 2
0
    def _on_config_change(self):
        self._last_graph_update = 0

        market_ids = set([get_market_id(mc) for mc in config['markets']])
        removed_market_ids = self._last_ticer.keys() - market_ids
        [
            self._last_ticer.pop(market_id, None)
            for market_id in removed_market_ids
        ]

        market_ids = set(
            [get_market_id(mc) for mc in config['markets'] if mc['graph']])
        removed_graph_market_ids = self._graph_data_dict.keys() - market_ids
        [
            self._graph_data_dict.pop(market_id, None)
            for market_id in removed_graph_market_ids
        ]

        self._main_win.remove_graph_markets(removed_graph_market_ids)

        for market_id in self._last_ticer:
            last_price = self._last_ticer[market_id]['close']
            market_config, _ = config.get_market_by_id(market_id)
            price_str = btcwidget.currency.service.format_price(
                last_price, market_config['market'][3:])
            GObject.idle_add(self._main_win.set_current_price, market_id,
                             price_str)
        for market_id in self._graph_data_dict:
            self._update_market_graph(market_id)
Ejemplo n.º 3
0
 def set_current_price(self, market_id, price_str):
     market_config, i = config.get_market_by_id(market_id)
     price_html = '<span color="{}">{}</span>'.format(
         self._get_color(i), price_str)
     if market_id in self._ticker_labels:
         self._ticker_labels[market_id].set_markup(price_html)
     if market_config['indicator']:
         self.set_title(price_str)
         self._indicator.set_current_price(price_str)
Ejemplo n.º 4
0
 def set_graph_data(self, market_id, graph_data):
     now = time.time()
     market_config, i = config.get_market_by_id(market_id)
     market = market_config['market']
     market_currency = market[3:]
     graph_currency = config['graph_currency']
     graph_price_mult = btcwidget.currency.service.convert(
         1, market_currency, graph_currency)
     x = [
         int((e['time'] - now) / config['time_axis_div'])
         for e in graph_data
     ]
     y = [float(e['close']) * graph_price_mult for e in graph_data]
     self._graph.set_data(market_id, x, y, self._get_color(i))
Ejemplo n.º 5
0
    def _fetch_market_graph_data(self, market_id):

        market_config, _ = config.get_market_by_id(market_id)
        exchange, market = market_config['exchange'], market_config['market']
        provider = btcwidget.exchanges.factory.get(exchange)

        try:
            graph_data = provider.graph(market, config['graph_period_sec'],
                                        config['graph_res'])
        except Exception as e:
            print('Failed to update graph data for {}: {}'.format(
                market_id, e),
                  file=sys.stderr)
            graph_data = None

        if graph_data:
            if market_id in self._last_ticer:
                graph_data.append(self._last_ticer[market_id])
            self._graph_data_dict[market_id] = graph_data
            self._update_market_graph(market_id)

        self._graph_threads.pop(market_id, None)