Esempio n. 1
0
    def __init__(self, config, indicator):
        self.indicator = indicator

        self.timeout_id = 0
        self.alarm = Alarm(config['app']['name'])

        self.error = Error(self)
Esempio n. 2
0
class Bitstamp:

    def __init__(self, config, indicator):
        self.indicator = indicator

        self.timeout_id = 0
        self.alarm = Alarm(config['app']['name'])

        self.error = Error(self)

    def start(self, error_refresh=None):
        refresh = error_refresh if error_refresh else self.indicator.refresh_frequency
        self.timeout_id = GLib.timeout_add_seconds(refresh, self.check_price)

    def stop(self):
        if self.timeout_id:
            GLib.source_remove(self.timeout_id)

    def check_price(self):

        self.asset_pair = self.indicator.active_asset_pair

        self.pair = [item['pair'] for item in CONFIG['asset_pairs'] if item['isocode'] == self.asset_pair][0]

        try:
            res = requests.get(CONFIG['ticker'].format(self.pair))
            data = res.json()
            if data:
                self._parse_result(data)

        except Exception as e:
            logging.info(e)
            self.error.increment()

        return self.error.is_ok()

    def _parse_result(self, data):
        self.error.clear()

        currency = [item['currency'] for item in CONFIG['asset_pairs'] if item['isocode'] == self.asset_pair][0]

        label = currency + utils.decimal_round(data['last'])

        bid = utils.category['bid'] + currency + utils.decimal_round(data['bid'])
        high = utils.category['high'] + currency + utils.decimal_round(data['high'])
        low = utils.category['low'] + currency + utils.decimal_round(data['low'])
        ask = utils.category['ask'] + currency + utils.decimal_round(data['ask'])
        volume = utils.category['volume'] + utils.decimal_round(data['volume'])

        # if self.alarm:
        #   self.alarm.check(float(data["last"]))

        self.indicator.set_data(label, bid, high, low, ask, volume)

    def _handle_error(self, error):
        logging.info("Bitstamp API error: " + error[0])
Esempio n. 3
0
class Kraken:

  def __init__(self, config, indicator):
    self.indicator = indicator

    self.timeout_id = 0
    self.alarm = Alarm(config['app']['name'])

    self.error = Error(self)

  def start(self, error_refresh=None):
    refresh = error_refresh if error_refresh else self.indicator.refresh_frequency
    self.timeout_id = GLib.timeout_add_seconds(refresh, self.check_price)

  def stop(self):
    if self.timeout_id:
      GLib.source_remove(self.timeout_id)

  def check_price(self):
    self.asset_pair = self.indicator.active_asset_pair

    self.pair = [item['pair'] for item in CONFIG['asset_pairs'] if item['isocode'] == self.asset_pair][0]

    try:
      res = requests.get(CONFIG['ticker'] + '?pair=' + self.pair)
      data = res.json()
      if data['error']:
        self._handle_error(data['error'])
      elif data['result']:
        self._parse_result(data['result'])

    except Exception as e:
      logging.info('Error: ' + str(e))
      self.error.increment()

    return self.error.is_ok()

  def _parse_result(self, data):
    self.error.clear()

    asset = data[self.pair]
    currency = [item['currency'] for item in CONFIG['asset_pairs'] if item['isocode'] == self.asset_pair][0]
    coin = [item['name'] for item in CONFIG['asset_pairs'] if item['isocode'] == self.asset_pair][0]

    label = currency + utils.decimal_round(asset['c'][0])

    bid = utils.category['bid'] + currency + utils.decimal_round(asset['b'][0])
    high = utils.category['high'] + currency + utils.decimal_round(asset['h'][0])
    low = utils.category['low'] + currency + utils.decimal_round(asset['l'][0])
    ask = utils.category['ask'] + currency + utils.decimal_round(asset['a'][0])

    self.indicator.set_data(label, bid, high, low, ask)

  def _handle_error(self, error):
    logging.info("Kraken API error: " + error[0])
Esempio n. 4
0
class Kraken:

  def __init__(self, config, indicator):
    self.indicator = indicator

    self.timeout_id = 0
    self.alarm = Alarm(config['app']['name'])

    self.error = Error(self)

  def start(self, error_refresh=None):
    refresh = error_refresh if error_refresh else self.indicator.refresh_frequency
    self.timeout_id = GLib.timeout_add_seconds(refresh, self.check_price)

  def stop(self):
    if self.timeout_id:
      GLib.source_remove(self.timeout_id)

  def check_price(self):
    self.asset_pair = self.indicator.active_asset_pair

    try:
      res = requests.get(CONFIG['ticker'] + '?pair=' + self.asset_pair)
      data = res.json()
      if data['error']:
        self._handle_error(data['error'])
      elif data['result']:
        self._parse_result(data['result'])

    except Exception as e:
      print(e)
      self.error.increment()

    return self.error.is_ok()

  def _parse_result(self, data):
    self.error.clear()

    asset = data[self.asset_pair]
    currency = [item['currency'] for item in CONFIG['asset_pairs'] if item['code'] == self.asset_pair][0]

    label = currency + utils.decimal_round(asset['c'][0])

    bid = utils.category['bid'] + currency + utils.decimal_round(asset['b'][0])
    high = utils.category['high'] + currency + utils.decimal_round(asset['h'][0])
    low = utils.category['low'] + currency + utils.decimal_round(asset['l'][0])
    ask = utils.category['ask'] + currency + utils.decimal_round(asset['a'][0])

    # if self.alarm:
    #   self.alarm.check(float(data["last"]))

    self.indicator.set_data(label, bid, high, low, ask)

  def _handle_error(self, error):
    print("Kraken API error: " + error[0])
Esempio n. 5
0
class Bitstamp:

  def __init__(self, config, indicator):
    self.indicator = indicator

    self.timeout_id = 0
    self.alarm = Alarm(config['app']['name'])

    self.error = Error(self)

  def start(self, error_refresh=None):
    refresh = error_refresh if error_refresh else self.indicator.refresh_frequency
    self.timeout_id = GLib.timeout_add_seconds(refresh, self.check_price)

  def stop(self):
    if self.timeout_id:
      GLib.source_remove(self.timeout_id)

  def check_price(self):
    try:
      res = requests.get(CONFIG['ticker'])
      data = res.json()
      if data:
        self._parse_result(data)

    except Exception as e:
      print(e)
      self.error.increment()

    return self.error.is_ok()

  def _parse_result(self, data):
    self.error.clear()

    currency = utils.currency['usd']

    label = currency + utils.decimal_round(data['last'])

    bid = utils.category['bid'] + currency + utils.decimal_round(data['bid'])
    high = utils.category['high'] + currency + utils.decimal_round(data['high'])
    low = utils.category['low'] + currency + utils.decimal_round(data['low'])
    ask = utils.category['ask'] + currency + utils.decimal_round(data['ask'])
    volume = utils.category['volume'] + utils.decimal_round(data['volume'])

    # if self.alarm:
    #   self.alarm.check(float(data["last"]))

    self.indicator.set_data(label, bid, high, low, ask, volume)

  def _handle_error(self, error):
    print("Bitstamp API error: " + error[0])
Esempio n. 6
0
class MtGox:
    def __init__(self, config, indicator):
        self.indicator = indicator

        self.timeout_id = 0
        self.alarm = Alarm(config['app']['name'])

        self.error = Error(self)

    def start(self, error_refresh=None):
        refresh = error_refresh if error_refresh else self.indicator.refresh_frequency
        self.timeout_id = GLib.timeout_add_seconds(refresh, self.check_price)

    def stop(self):
        if self.timeout_id:
            GLib.source_remove(self.timeout_id)

    def check_price(self):
        self.asset_pair = self.indicator.active_asset_pair

        try:
            res = requests.get(CONFIG['ticker'] + self.asset_pair +
                               CONFIG['ticker_suffix'])
            data = res.json()
            if data:
                self._parse_result(data['data'])

        except Exception as e:
            print(e)
            self.error.increment()

        return self.error.is_ok()

    def _parse_result(self, data):
        self.error.clear()

        label = data['last']['display_short']

        bid = utils.category['bid'] + data['buy']['display_short']
        high = utils.category['high'] + data['high']['display_short']
        low = utils.category['low'] + data['low']['display_short']
        ask = utils.category['ask'] + data['sell']['display_short']
        volume = utils.category['volume'] + data['vol']['display_short']

        # if self.alarm:
        #   self.alarm.check(float(data["last"]))

        self.indicator.set_data(label, bid, high, low, ask, volume)

    def _handle_error(self, error):
        print("MtGox API error: " + error[0])
Esempio n. 7
0
class MtGox:

  def __init__(self, config, indicator):
    self.indicator = indicator

    self.timeout_id = 0
    self.alarm = Alarm(config['app']['name'])

    self.error = Error(self)

  def start(self, error_refresh=None):
    refresh = error_refresh if error_refresh else self.indicator.refresh_frequency
    self.timeout_id = GLib.timeout_add_seconds(refresh, self.check_price)

  def stop(self):
    if self.timeout_id:
      GLib.source_remove(self.timeout_id)

  def check_price(self):
    self.asset_pair = self.indicator.active_asset_pair

    try:
      res = requests.get(CONFIG['ticker'] + self.asset_pair + CONFIG['ticker_suffix'])
      data = res.json()
      if data:
        self._parse_result(data['data'])

    except Exception as e:
      print(e)
      self.error.increment()

    return self.error.is_ok()

  def _parse_result(self, data):
    self.error.clear()

    label = data['last']['display_short']

    bid = utils.category['bid'] + data['buy']['display_short']
    high = utils.category['high'] + data['high']['display_short']
    low = utils.category['low'] + data['low']['display_short']
    ask = utils.category['ask'] + data['sell']['display_short']
    volume = utils.category['volume'] + data['vol']['display_short']

    # if self.alarm:
    #   self.alarm.check(float(data["last"]))

    self.indicator.set_data(label, bid, high, low, ask, volume)

  def _handle_error(self, error):
    print("MtGox API error: " + error[0])
Esempio n. 8
0
  def __init__(self, config, indicator):
    self.indicator = indicator

    self.timeout_id = 0
    self.alarm = Alarm(config['app']['name'])

    self.error = Error(self)
Esempio n. 9
0
class Coinbase:
    def __init__(self, config, indicator):
        self.indicator = indicator

        self.timeout_id = 0
        self.alarm = Alarm(config['app']['name'])

        self.error = Error(self)

    def start(self, error_refresh=None):
        refresh = error_refresh if error_refresh else self.indicator.refresh_frequency
        self.timeout_id = GLib.timeout_add_seconds(refresh, self.check_price)

    def stop(self):
        if self.timeout_id:
            GLib.source_remove(self.timeout_id)

    def check_price(self):
        self.asset_pair = self.indicator.active_asset_pair

        try:
            res = requests.get(CONFIG['ticker'].replace(
                ':currency_pair', self.asset_pair))

            data = res.json()
            if data['data']:
                self._parse_result(data['data'])

        except Exception as e:
            print(e)
            self.error.increment()

        return self.error.is_ok()

    def _parse_result(self, data):
        self.error.clear()

        print(data)
        asset = data
        currency = [
            item['currency'] for item in CONFIG['asset_pairs']
            if item['code'] == self.asset_pair
        ][0]

        label = currency + asset['amount']

        bid = utils.category['bid'] + currency + utils.decimal_round(
            asset['amount'])
        high = utils.category['high'] + currency + utils.decimal_round(
            asset['amount'])
        low = utils.category['low'] + currency + utils.decimal_round(
            asset['amount'])
        ask = utils.category['ask'] + currency + utils.decimal_round(
            asset['amount'])

        # if self.alarm:
        #   self.alarm.check(float(data["last"]))

        self.indicator.set_data(label, bid, high, low, ask)

    def _handle_error(self, error):
        print("Coinbase API error: " + error[0])
Esempio n. 10
0
class BitYep:
    def __init__(self, config, indicator):
        self.indicator = indicator

        self.timeout_id = 0
        self.alarm = Alarm(config['app']['name'])

        self.error = Error(self)

    def start(self, error_refresh=None):
        refresh = error_refresh if error_refresh else self.indicator.refresh_frequency
        self.timeout_id = GLib.timeout_add_seconds(refresh, self.check_price)

    def stop(self):
        if self.timeout_id:
            GLib.source_remove(self.timeout_id)

    def check_price(self):
        self.asset_pair = self.indicator.active_asset_pair

        try:
            res = requests.get(CONFIG['ticker'])
            data = res.json()
            if res.status_code != 200:
                self._handle_error('HTTP error code ' + res.status_code)
            else:
                self._parse_result(data)

        except Exception as e:
            self._handle_error(e)
            self.error.increment()

        return self.error.is_ok()

    def _parse_result(self, data):
        self.error.clear()

        asset = data[int([
            item['pair'] for item in CONFIG['asset_pairs']
            if item['isocode'] == self.asset_pair
        ][0])]
        currency = [
            item['currency'] for item in CONFIG['asset_pairs']
            if item['isocode'] == self.asset_pair
        ][0]
        coin = [
            item['name'] for item in CONFIG['asset_pairs']
            if item['isocode'] == self.asset_pair
        ][0]

        label = currency + utils.decimal_round(asset['last'])

        first = utils.category['first'] + currency + utils.decimal_round(
            asset['first'])
        high = utils.category['high'] + currency + utils.decimal_round(
            asset['high'])
        low = utils.category['low'] + currency + utils.decimal_round(
            asset['low'])
        volume = utils.category['volume'] + asset['volume']

        self.indicator.set_data(label, first, high, low, volume)

    def _handle_error(self, error):
        logging.info("BitYep API error: " + str(error))
Esempio n. 11
0
class Bittrex:

  def __init__(self, config, indicator):
    self.indicator = indicator

    self.timeout_id = 0
    self.alarm = Alarm(config['app']['name'])

    self.error = Error(self)

  def start(self, error_refresh=None):
    refresh = error_refresh if error_refresh else self.indicator.refresh_frequency
    self.timeout_id = GLib.timeout_add_seconds(refresh, self.check_price)

  def stop(self):
    if self.timeout_id:
      GLib.source_remove(self.timeout_id)

  def check_price(self):
    self.asset_pair = self.indicator.active_asset_pair

    self.pair = [item['pair'] for item in CONFIG['asset_pairs'] if item['isocode'] == self.asset_pair][0]

    try:
      res = requests.get(CONFIG['ticker'] + '?market=' + self.pair)
      data = res.json()

      if not data['success']:
        self._handle_error(data['error'])
      elif data['result']:
        self._parse_result(data['result'])

    except Exception as e:
      logging.info('Error: ' + str(e))
      self.error.increment()

    return self.error.is_ok()

  def _parse_result(self, data):
    self.error.clear()

    '''
    Response example
    [{'Bid': 5655.15, 'MarketName': 'USDT-BTC', 'Ask': 5665.0, 'BaseVolume': 19499585.87469274, 'High': 5888.0, 'Low': 5648.0, 'Volume': 3393.61801172, 'OpenBuyOrders': 8505, 'Created': '2015-12-11T06:31:40.633', 'PrevDay': 5762.180121, 'Last': 5665.0, 'OpenSellOrders': 4194, 'TimeStamp': '2017-10-28T12:24:39.38'}]
    '''

    asset = data[0]

    currency = [item['currency'] for item in CONFIG['asset_pairs'] if item['isocode'] == self.asset_pair][0]

    coin = [item['name'] for item in CONFIG['asset_pairs'] if item['isocode'] == self.asset_pair][0]

    label = currency + utils.decimal_auto(asset['Last'])

    bid = utils.category['bid'] + currency + utils.decimal_auto(asset['Bid'])
    high = utils.category['high'] + currency + utils.decimal_auto(asset['High'])
    low = utils.category['low'] + currency + utils.decimal_auto(asset['Low'])
    ask = utils.category['ask'] + currency + utils.decimal_auto(asset['Ask'])

    self.indicator.set_data(label, bid, high, low, ask)

  def _handle_error(self, error):
    logging.info("Bittrex API error: " + error[0])
Esempio n. 12
0
class Gdax:
    def __init__(self, config, indicator):
        self.indicator = indicator

        self.timeout_id = 0
        self.alarm = Alarm(config['app']['name'])

        self.error = Error(self)

    def start(self, error_refresh=None):
        refresh = error_refresh if error_refresh else self.indicator.refresh_frequency
        self.timeout_id = GLib.timeout_add_seconds(refresh, self.check_price)

    def stop(self):
        if self.timeout_id:
            GLib.source_remove(self.timeout_id)

    def check_price(self):
        self.asset_pair = self.indicator.active_asset_pair

        pair = [
            item['pair'] for item in CONFIG['asset_pairs']
            if item['isocode'] == self.asset_pair
        ][0]

        try:
            res = requests.get(CONFIG['ticker'] + pair + '/ticker')
            data = res.json()
            if res.status_code != 200:
                self._handle_error('HTTP error code ' + res.status_code)
            else:
                self._parse_result(data)

        except Exception as e:
            self._handle_error(e)
            self.error.increment()

        return self.error.is_ok()

    def _parse_result(self, asset):
        self.error.clear()

        currency = [
            item['currency'] for item in CONFIG['asset_pairs']
            if item['isocode'] == self.asset_pair
        ][0]
        coin = [
            item['name'] for item in CONFIG['asset_pairs']
            if item['isocode'] == self.asset_pair
        ][0]

        label = currency + utils.decimal_round(asset['price'])

        bid = utils.category['bid'] + currency + utils.decimal_round(
            asset['bid'])
        ask = utils.category['ask'] + currency + utils.decimal_round(
            asset['ask'])
        volume = utils.category['volume'] + utils.decimal_round(
            asset['volume'])

        self.indicator.set_data(label, bid, ask, volume, 'no further data')

    def _handle_error(self, error):
        logging.info("Gdax API error: " + str(error))