Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix case missmatch for KrakenFutures symbols #1040

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

carloe
Copy link
Contributor

@carloe carloe commented Jun 5, 2024

This old workaround seems to break things. I have this code:

def main():
    loop = asyncio.get_event_loop()
    f.add_feed(KrakenFutures(symbols=['BTC-USD-PERP'], channels=[TRADES], callbacks={...}))

    k = KrakenFutures()
    print(k.exchange_symbol_mapping)

    f.run(start_loop=False)
    loop.call_later(60, stop)
    loop.run_forever()

Which produces this output:

{'PF_XBTUSD': 'BTC-USD-PERP',  ... }

And once I get the following error.

2024-06-05 17:24:43,728 : INFO : KRAKEN_FUTURES.ws.2: closed connection 'WebSocketClientProtocol'
2024-06-05 17:24:43,728 : ERROR : KRAKEN_FUTURES.ws.2: encountered an exception, reconnecting in 1.0 seconds
Traceback (most recent call last):
  File ".../site-packages/cryptofeed/exchange.py", line 132, in exchange_symbol_to_std_symbol
    return self.exchange_symbol_mapping[symbol]
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
KeyError: 'pf_xbtusd'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File ".../site-packages/cryptofeed/connection_handler.py", line 69, in _create_connection
    await self._handler(connection, self.handler)
  File ".../site-packages/cryptofeed/connection_handler.py", line 119, in _handler
    await handler(message, connection, self.conn.last_message)
  File ".../site-packages/cryptofeed/exchanges/kraken_futures.py", line 250, in message_handler
    pair = self.exchange_symbol_to_std_symbol(msg['product_id'].lower())
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../site-packages/cryptofeed/exchange.py", line 137, in exchange_symbol_to_std_symbol
    raise UnsupportedSymbol(f'{symbol} is not supported on {self.id}')
cryptofeed.exceptions.UnsupportedSymbol: pf_xbtusd is not supported on KRAKEN_FUTURES
2024-06-05 17:24:44,731 : DEBUG : KRAKEN_FUTURES.ws.2: connecting to wss://futures.kraken.com/ws/v1
2024-06-05 17:24:45,013 : INFO : KRAKEN_FUTURES.ws.2: closed connection 'WebSocketClientProtocol'
2024-06-05 17:24:45,013 : ERROR : KRAKEN_FUTURES.ws.2: encountered an exception, reconnecting in 1.0 seconds
Traceback (most recent call last):
  File ".../site-packages/cryptofeed/exchange.py", line 132, in exchange_symbol_to_std_symbol
    return self.exchange_symbol_mapping[symbol]
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
KeyError: 'pf_xbtusd'

The problem seems to come from this old workaround(?). Without .lower() my code above runs without issues.

# As per Kraken support: websocket product_id is uppercase version of the REST API symbols
pair = self.exchange_symbol_to_std_symbol(msg['product_id'].lower())

  • - Tested
  • - Changelog updated
  • - Tests run and pass
  • - Flake8 run and all errors/warnings resolved
  • - Contributors file updated (optional)

@bmoscon
Copy link
Owner

bmoscon commented Aug 28, 2024

@carloe can you resolve the conflicts? then I can merge this.

Copy link
Owner

@bmoscon bmoscon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix merge conflicts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants