Beispiel #1
0
def poll_cmc():

    # Setup
    headers = {
        'Accepts': 'application/json',
        'X-CMC_PRO_API_KEY': '522e4a07-85df-49e5-8b10-db5c64372920',
    }
    session = Session()
    session.headers.update(headers)

    try:
        while True:
            response = session.get(BTCD_URL)

            data = loads(response.text)['data']
            quick_write(BTCD_FILE, str(data['btc_dominance']))

            quote = data['quote']['USD']
            quick_write(TMC_FILE, str(quote['total_market_cap']))
            quick_write(TV_FILE, str(quote['total_volume_24h']))
            quick_write(AV_FILE, str(quote['altcoin_volume_24h']))
            quick_write(AMC_FILE, str(quote['altcoin_market_cap']))

            sleep(CMC_BETWEEN_ITERS)

    except (ConnectionError, Timeout, TooManyRedirects) as e:
        print(e)
    except KeyboardInterrupt:
        print('Bitcoin Dominance polling interrupted.')
Beispiel #2
0
 async def update(self, observable, message):
     if 'params' in message and 'channel' in message[
             'params'] and 'data' in message['params']:
         channel = message['params']['channel']
         quick_write(f'{channel}.json', dumps(message['params']['data']))
     else:
         print('--- (!) Uncaught message:')
         pp.pprint(message)
Beispiel #3
0
def poll_deribit():
    try:
        rest = DeribitRest(auth=False)

        while True:
            hv = rest.historical_volatility('BTC')[-1][1]

            quick_write(HV_FILE, str(hv))

            sleep(DERIBIT_BETWEEN_ITERS)

    except KeyboardInterrupt:
        print('Deribit polling interrupted.')
Beispiel #4
0
 def write(self):
     with LOCK:
         for name, content in {
                 PRICE_FILE: str(self.price),
                 BUY_FLOW_FILE: str(self.buy_flow),
                 SELL_FLOW_FILE: str(self.sell_flow),
                 OPEN_INTEREST_FILE: str(self.open_interest),
                 PRICE_HISTORY_FILE: dumps(list(self.price_history)),
                 SELL_FLOW_HISTORY_FILE:
                 dumps(list(self.sell_flow_history)),
                 BUY_FLOW_HISTORY_FILE: dumps(list(self.buy_flow_history)),
                 OPEN_INTEREST_HISTORY_FILE:
                 dumps(list(self.open_interest_history)),
                 OPEN_INTERESTS_FILE: dumps(self.open_interests),
                 RECENT_TRADES_FILE: dumps(list(self.recent_trades),
                                           default=str),
         }.items():
             quick_write(name, content)
Beispiel #5
0
# from time import sleep
from pprint import PrettyPrinter

pp = PrettyPrinter()

INSTRUMENTS_FILE = 'instruments.json'

# Init rest client
rest = DeribitRest(auth=False)

# Get all futures contract names
instruments = [
    data['instrument_name'] for data in
    rest.public_api.public_get_instruments_get('BTC', kind='future')['result']
]
quick_write(INSTRUMENTS_FILE, dumps(instruments))

# Derive instrument's quote channels
futures_channels = []  #[f'quote.{instrument}' for instrument in instruments]

# All public channels
public_channels = futures_channels

# All private channels
private_channels = [f'user.portfolio.BTC']


class Writer(AObserver):
    def __init__(self):
        pass
Beispiel #6
0
 def update():
     with urlopen(FNG_URL) as fng:
         quick_write(FNG_FILE, dumps(loads(fng.read())))