class BitcoinAverage(FeedSource): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) assert hasattr(self, "secret_key"), "Bitcoinaverage needs 'secret_key'" assert hasattr(self, "public_key"), "Bitcoinaverage needs 'public_key'" self.rest = RestfulClient(self.secret_key, self.public_key) def _fetch(self): feed = {} try: for base in self.bases: feed[base] = {} for quote in self.quotes: if quote == base: continue result = self.rest.ticker_global_per_symbol( quote.upper() + base.upper() ) if ( hasattr(self, "quoteNames") and quote in self.quoteNames ): quote = self.quoteNames[quote] feed[base][quote] = { "price": (float(result["last"])), "volume": (float(result["volume"]))} except Exception as e: raise Exception("\nError fetching results from {1}! ({0})".format(str(e), type(self).__name__)) return feed
def get(cur, base): log.debug('checking feeds for %s/%s at %s' % (cur, base, NAME)) try: secret_key = core.config['credentials']['bitcoinaverage']['secret_key'] public_key = core.config['credentials']['bitcoinaverage']['public_key'] except KeyError: raise KeyError('config.yaml does not specify both "credentials.bitcoinaverage.secret_key" and ' '"credentials.bitcoinaverage.public_key" variables') client = RestfulClient(secret_key=secret_key, public_key=public_key) r = client.ticker_short_local()[cur + base] return FeedPrice(float(r['last']), cur, base, last_updated=pendulum.from_timestamp(r['timestamp']), provider=NAME)
def get(cur, base): log.debug('checking feeds for %s/%s at %s' % (cur, base, NAME)) try: secret_key = core.config['credentials']['bitcoinaverage']['secret_key'] public_key = core.config['credentials']['bitcoinaverage']['public_key'] except KeyError: raise KeyError( 'config.yaml does not specify both "credentials.bitcoinaverage.secret_key" and ' '"credentials.bitcoinaverage.public_key" variables') client = RestfulClient(secret_key=secret_key, public_key=public_key) r = client.ticker_short_local()[cur + base] return FeedPrice(float(r['last']), cur, base, last_updated=pendulum.from_timestamp(r['timestamp']), provider=NAME)
class BitcoinAverageFeedProvider(FeedProvider): NAME = 'BitcoinAverage' AVAILABLE_MARKETS = [('BTC', 'USD')] def __init__(self, secret_key, public_key): super().__init__() self.client = RestfulClient(secret_key=secret_key, public_key=public_key) @check_online_status @check_market def get(self, cur, base): log.debug('checking feeds for %s/%s at %s' % (cur, base, self.NAME)) r = self.client.ticker_short_local()[cur+base] return self.feed_price(cur, base, price=float(r['last']), last_updated=pendulum.from_timestamp(r['timestamp']))
from bitcoinaverage import RestfulClient if __name__ == '__main__': secret_key = '' or input('Enter your secret key: ') public_key = '' or input('Enter your public key: ') restful_client = RestfulClient(secret_key, public_key) ticker_all_local = restful_client.ticker_all_local(crypto='LTC', fiat='GBP') print('ticker all local') print(ticker_all_local) ticker_all_global = restful_client.ticker_all_global(crypto='BTC', fiat='USD,EUR') print('ticker all global') print(ticker_all_global) ticker_local_per_symbol = restful_client.ticker_local_per_symbol('BTCUSD') print('Local Ticker for BTCUSD') print(ticker_local_per_symbol) ticker_global_per_symbol = restful_client.ticker_global_per_symbol('BTCUSD') print('Global Ticker for BTCUSD') print(ticker_global_per_symbol) ticker_short_local = restful_client.ticker_short_local() print('Local Ticker Short') print(ticker_short_local) ticker_short_global = restful_client.ticker_short_global() print('Global Ticker Short')
from bitcoinaverage import RestfulClient if __name__ == '__main__': secret_key = '' or input('Enter your secret key: ') public_key = '' or input('Enter your public key: ') restful_client = RestfulClient(secret_key, public_key) all_symbols = restful_client.all_symbols() print('all symbols:') print(all_symbols) symbols_local = restful_client.symbols_local() print('local symbols') print(symbols_local) symbols_global = restful_client.symbols_global() print('global symbols') print(symbols_global) exchange_rates_local = restful_client.exchange_rates_local() print('local exchange rates') print(exchange_rates_local) exchange_rates_global = restful_client.exchange_rates_global() print('global exchange rates') print(exchange_rates_global)
from bitcoinaverage import RestfulClient if __name__ == '__main__': secret_key = '' or input('Enter your secret key: ') public_key = '' or input('Enter your public key: ') restful_client = RestfulClient(secret_key, public_key) all_exchange_data = restful_client.all_exchange_data(crypto='BTC', fiat='USD,CNY') print('data from all exchanges for BTCUSD and BTCCNY') print(all_exchange_data) all_exchange_data_BTCUSD = restful_client.all_exchange_data_for_symbol('BTCUSD') print('data from all exchanges fro BTCUSD') print(all_exchange_data_BTCUSD) gdax_data = restful_client.per_exchange_data('gdax') print('data from GDAX') print(gdax_data) exchange_count = restful_client.exchange_count() print('exchange count') print(exchange_count) outlier_exchanges = restful_client.outlier_exchanges() print('outlier exchanges') print(outlier_exchanges) ignored_exchanges = restful_client.ignored_exchanges() print('ignored exchanges') print(ignored_exchanges)
from bitcoinaverage import RestfulClient if __name__ == '__main__': secret_key = '' or input('Enter your secret key: ') public_key = '' or input('Enter your public key: ') restful_client = RestfulClient(secret_key, public_key) all_exchange_data = restful_client.all_exchange_data(crypto='BTC', fiat='USD,CNY') print('data from all exchanges for BTCUSD and BTCCNY') print(all_exchange_data) all_exchange_data_BTCUSD = restful_client.all_exchange_data_for_symbol( 'BTCUSD') print('data from all exchanges fro BTCUSD') print(all_exchange_data_BTCUSD) gdax_data = restful_client.per_exchange_data('gdax') print('data from GDAX') print(gdax_data) exchange_count = restful_client.exchange_count() print('exchange count') print(exchange_count) outlier_exchanges = restful_client.outlier_exchanges() print('outlier exchanges') print(outlier_exchanges) ignored_exchanges = restful_client.ignored_exchanges()
from bitcoinaverage import RestfulClient if __name__ == '__main__': secret_key = '' or input('Enter your secret key: ') public_key = '' or input('Enter your public key: ') restful_client = RestfulClient(secret_key, public_key) # convert from BTC to USD conversion_local = restful_client.perform_conversion_local('BTC', 'USD', amount=3) print('3 BTC are worth {} USD'.format(conversion_local['price'])) # convert from EUR to ETH conversion_global = restful_client.perform_conversion_global('EUR', 'ETH', amount=100) print('100 EUR are worth {} ETH'.format(conversion_global['price'])) # get the price of BTCUSD when the transaction for the provided hash was confirmed blockchain_tx_price = restful_client.blockchain_tx_price('BTCUSD', 'f854aebae95150b379cc1187d848d58225f3c4157fe992bcd166f58bd5063449') print(blockchain_tx_price)
from bitcoinaverage import RestfulClient from datetime import datetime, timedelta if __name__ == '__main__': secret_key = '' or input('Enter your secret key: ') public_key = '' or input('Enter your public key: ') restful_client = RestfulClient(secret_key, public_key) # load local history as dict history_local_json = restful_client.history_local('BTCUSD', 'daily', 'json') # save history in history_local.csv restful_client.save_history_local(symbol='BTCUSD', period='daily', csv_path='history_local.csv') # load global history as dict history_global_json = restful_client.history_global('BTCUSD', 'daily', 'json') # save history in history_global.csv format restful_client.save_history_global(symbol='LTCEUR', period='alltime', csv_path='history_global.csv') # get unix format timestamp for 10 minutes ago timestamp = int((datetime.now() - timedelta(minutes=10)).timestamp()) # get all local history data since the specified timestamp (for the last 10 minutes) data_since_timestamp = restful_client.data_since_timestamp_local('BTCUSD', since=timestamp) print('local data for the last 10 minutes (since {} timestamp)'.format(timestamp)) print(data_since_timestamp) timestamp = int((datetime.now() - timedelta(minutes=10)).timestamp()) # get all global history data since the specified timestamp (for the last 10 minutes) data_since_timestamp = restful_client.data_since_timestamp_global('BTCUSD', since=timestamp)
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) assert hasattr(self, "secret_key"), "Bitcoinaverage needs 'secret_key'" assert hasattr(self, "public_key"), "Bitcoinaverage needs 'public_key'" self.rest = RestfulClient(self.secret_key, self.public_key)
from bitcoinaverage import RestfulClient from datetime import datetime, timedelta if __name__ == '__main__': secret_key = '' or input('Enter your secret key: ') public_key = '' or input('Enter your public key: ') restful_client = RestfulClient(secret_key, public_key) # load local history as dict history_local_json = restful_client.history_local('BTCUSD', 'daily', 'json') # save history in history_local.csv restful_client.save_history_local(symbol='BTCUSD', period='daily', csv_path='history_local.csv') # load global history as dict history_global_json = restful_client.history_global( 'BTCUSD', 'daily', 'json') # save history in history_global.csv format restful_client.save_history_global(symbol='LTCEUR', period='alltime', csv_path='history_global.csv') # get unix format timestamp for 10 minutes ago timestamp = int((datetime.now() - timedelta(minutes=10)).timestamp()) # get all local history data since the specified timestamp (for the last 10 minutes) data_since_timestamp = restful_client.data_since_timestamp_local(
def __init__(self, secret_key, public_key): super().__init__() self.client = RestfulClient(secret_key=secret_key, public_key=public_key)
from bitcoinaverage import RestfulClient if __name__ == '__main__': secret_key = '' or input('Enter your secret key: ') public_key = '' or input('Enter your public key: ') restful_client = RestfulClient(secret_key, public_key) # convert from BTC to USD conversion_local = restful_client.perform_conversion_local('BTC', 'USD', amount=3) print('3 BTC are worth {} USD'.format(conversion_local['price'])) # convert from EUR to ETH conversion_global = restful_client.perform_conversion_global('EUR', 'ETH', amount=100) print('100 EUR are worth {} ETH'.format(conversion_global['price'])) # get the price of BTCUSD when the transaction for the provided hash was confirmed blockchain_tx_price = restful_client.blockchain_tx_price( 'BTCUSD', 'f854aebae95150b379cc1187d848d58225f3c4157fe992bcd166f58bd5063449') print(blockchain_tx_price)
from bitcoinaverage import RestfulClient if __name__ == '__main__': secret_key = '' or input('Enter your secret key: ') public_key = '' or input('Enter your public key: ') restful_client = RestfulClient(secret_key, public_key) ticker_all_local = restful_client.ticker_all_local(crypto='LTC', fiat='GBP') print('ticker all local') print(ticker_all_local) ticker_all_global = restful_client.ticker_all_global(crypto='BTC', fiat='USD,EUR') print('ticker all global') print(ticker_all_global) ticker_local_per_symbol = restful_client.ticker_local_per_symbol('BTCUSD') print('Local Ticker for BTCUSD') print(ticker_local_per_symbol) ticker_global_per_symbol = restful_client.ticker_global_per_symbol( 'BTCUSD') print('Global Ticker for BTCUSD') print(ticker_global_per_symbol) ticker_short_local = restful_client.ticker_short_local() print('Local Ticker Short') print(ticker_short_local)