def __init__(self, account): self.account = account self.markets = None self.manager_candlestick = KrakenClient.WssClient() self.manager_depth = KrakenClient.WssClient() self.manager_ticker = KrakenClient.WssClient() self.manager_trades = KrakenClient.WssClient() self.started_candlestick = False self.started_depth = False self.started_ticker = False self.started_trades = False
def CryptoArbOrderBookProcess(stopProcessesEvent): try: # Init Kafka producer kafka_producer = KafkaProducer( bootstrap_servers=config['kafka']['address'], value_serializer=lambda v: json.dumps(v).encode('utf-8')) # Init CloudWatch metrics metrics = CWMetrics(config['exchange']['name']) orderbooks = dict() my_client = client.WssClient() my_client.subscribe_public( subscription={ 'name': 'book', 'depth': orderbookDepthInSubscription }, pair=translateNamingFromStandardToKraken( symbolsList=config['exchange']['symbols']), callback=partial(krakenMessageHandler, kafka_producer, metrics, orderbooks)) my_client.start() logger.info('websocket started') stopProcessesEvent.wait() my_client.stop() logger.info('websocket closed') except Exception as error: logger.error(type(error).__name__ + " " + str(error.args)) metrics.putError()
def run_ohlc_websocket(interval: int = 0, pair: str = "XBT/EUR"): if interval == 0: log.warning("No interval window given, using 1 minute") interval = 1 kraken_rest_api_to_psql(interval=interval) log.info(f"Setting up OHLC websocket") client = kraken_client.WssClient() client.subscribe_public(subscription={ "name": "ohlc", "interval": interval }, pair=[pair], callback=store2psql) log.info("⇩ = Insert new OHLC record for this interval window.") log.info("↺ = Update existing record for this interval window.") log.info("♥ = Websocket heartbeat.") log.info("Starting websocket client") client.start()
def connect_ws(): my_client = client.WssClient() my_client.start() my_client.subscribe_public(subscription={'name': 'ohlc'}, pair=['BTC/USD'], callback=my_handler)
def open_connection(self, func): kraken = kraken_client.WssClient() kraken.subscribe_public( subscription={"name": "trade"}, pair=["ETH/USD"], callback=func ) kraken.start()
def run_ticker_websocket(portfolio: Portfolio): log.info(f"Setting up Ticker websocket for {portfolio.pairs}") client = kraken_client.WssClient() client.subscribe_public(subscription={"name": "ticker"}, pair=portfolio.pairs, callback=store2psql) log.info("Starting Ticker websocket") client.start()
def __init__(self, channel_name: str, pairs: list, subscription_args: dict): log.info("Creating Kraken Websocket Client") self.register_api_handler(channel_name) self.websocket = kraken_client.WssClient() # Setup trades log.info( f"Subscribing to {channel_name} channel for pairs: {PAIRS_TO_WATCH}" ) self.websocket.subscribe_public(subscription=subscription_args, pair=PAIRS_TO_WATCH, callback=self.handler)
from kraken_wsclient_py import kraken_wsclient_py as client def my_handler(message): # Here you can do stuff with the messages print(message) my_client = client.WssClient() my_client.subscribe_public(subscription={'name': 'ticker'}, pair=['XBT/USD', 'XBT/EUR'], callback=my_handler) my_client.start()