blankly-finance / blankly

🚀 💸 Easily build, backtest and deploy your algo in just a few lines of code. Trade stocks, cryptos, and forex across exchanges w/ one package.
https://package.blankly.finance
GNU Lesser General Public License v3.0
2.11k stars 267 forks source link

return self.websockets[exchange][currency_id] ... KeyError: 'BTC-USDC' #181

Closed timborden closed 2 years ago

timborden commented 2 years ago

Description

Having issues getting started with Blankly + Kucoin

settings.json

{
    "settings": {
        "use_sandbox_websockets": false,
        "websocket_buffer_size": 10000,
        "test_connectivity_on_auth": true,
        "auto_truncate": false,
        "coinbase_pro": {
            "cash": "USD"
        },
        "binance": {
            "cash": "USDT",
            "binance_tld": "com"
        },
        "binance_futures": {
            "cash": "USDT",
            "margin_type": "USDT-M"
        },
        "alpaca": {
            "websocket_stream": "iex",
            "cash": "USD",
            "enable_shorting": true,
            "use_yfinance": false
        },
        "oanda": {
            "cash": "USD"
        },
        "okx": {
            "cash": "USDT"
        },
        "keyless": {
            "cash": "USD"
        },
        "kucoin": {
            "cash": "USDT"
        },
        "ftx": {
            "cash": "USD",
            "ftx_tld": "com"
        },
        "ftx_futures": {
            "cash": "USD",
            "ftx_tld": "com"
        }
    }
}

Error (if applicable)

> python bot.py
init BTC-USDC Symbol: BTC-USDC
Time: 1656588885.4667468
Resolution: 900.0
Variables:
{}

Exception in thread Thread-1 (main):
Traceback (most recent call last):
  File "/Users/timborden/.pyenv/versions/3.10.1/lib/python3.10/threading.py", line 1009, in _bootstrap_inner
    self.run()
  File "/Users/timborden/.pyenv/versions/3.10.1/lib/python3.10/threading.py", line 946, in run
    self._target(*self._args, **self._kwargs)
  File "/Users/timborden/.pyenv/versions/terry-peterson/lib/python3.10/site-packages/blankly/frameworks/strategy/strategy.py", line 156, in main
    self.run_live()
  File "/Users/timborden/.pyenv/versions/terry-peterson/lib/python3.10/site-packages/blankly/frameworks/strategy/strategy.py", line 202, in run_live
    self.ticker_manager.restart_ticker(i[0], i[1])
  File "/Users/timborden/.pyenv/versions/terry-peterson/lib/python3.10/site-packages/blankly/exchanges/managers/websocket_manager.py", line 156, in restart_ticker
    websocket = self.__evaluate_overrides(override_symbol, override_exchange)
  File "/Users/timborden/.pyenv/versions/terry-peterson/lib/python3.10/site-packages/blankly/exchanges/managers/websocket_manager.py", line 62, in __evaluate_overrides
    return self.websockets[exchange][currency_id]
KeyError: 'BTC-USDC'
Traceback (most recent call last):
  File "/Users/timborden/.pyenv/versions/terry-peterson/lib/python3.10/site-packages/blankly/utils/scheduler.py", line 128, in __threading_wait
    func(**kwargs)
  File "/Users/timborden/.pyenv/versions/terry-peterson/lib/python3.10/site-packages/blankly/frameworks/strategy/strategy.py", line 92, in rest_event
    data = self.interface.get_price(symbol)
  File "/Users/timborden/.pyenv/versions/terry-peterson/lib/python3.10/site-packages/blankly/exchanges/interfaces/kucoin/kucoin_interface.py", line 620, in get_price
    if 'msg' in response:
TypeError: argument of type 'NoneType' is not iterable
^CException ignored in: <module 'threading' from '/Users/timborden/.pyenv/versions/3.10.1/lib/python3.10/threading.py'>
Traceback (most recent call last):
  File "/Users/timborden/.pyenv/versions/3.10.1/lib/python3.10/threading.py", line 1560, in _shutdown
    lock.acquire()
KeyboardInterrupt:

Platform Info

Additional context - bot.py

import blankly

SYMBOL = "BTC-USDC"

def init(symbol, state: blankly.StrategyState):
    print("init", symbol, state)

def bar_event(bar, symbol, state: blankly.StrategyState):
    print("bar_event", bar, symbol, state)

def orderbook_event(order, symbol, state: blankly.StrategyState):
    print("orderbook_event", order, symbol, state)

def price_event(price, symbol, state: blankly.StrategyState):
    print("price_event", price, symbol, state)

if __name__ == "__main__":
    exchange = blankly.Kucoin("sandbox")
    strategy = blankly.Strategy(exchange)
    strategy.add_bar_event(bar_event, SYMBOL, resolution='15m', init=init)
    strategy.add_orderbook_event(orderbook_event, SYMBOL)
    strategy.add_price_event(price_event, SYMBOL, resolution='15m')

    strategy.start()
EmersonDove commented 2 years ago

Hey this was a pretty severe error on our end. I just pushed a fix. Try updating pip install blankly --upgrade and see if it works now.

timborden commented 2 years ago

That fixed it...thanks!