leoncvlt / cryptodex

📈 Python tool to automate & streamline the management of a personal cryptocurrency-based index fund
7 stars 7 forks source link

KeyError #3

Open zzzpotato opened 3 years ago

zzzpotato commented 3 years ago

I cannot seem to get past this error. Any input or recommendations?


[09:21:01] DEBUG    Starting new HTTPS connection (1): api.coingecko.com:443                                                                                                 connectionpool.py:971
⠙ Connecting to exchange...           DEBUG    https://api.coingecko.com:443 "GET /api/v3/coins/markets?vs_currency=usd HTTP/1.1" 200 None                                                              connectionpool.py:452
           DEBUG    Starting new HTTPS connection (1): api.kraken.com:443                                                                                                    connectionpool.py:971
⠸ Connecting to exchange...           DEBUG    https://api.kraken.com:443 "POST /0/private/Balance HTTP/1.1" 200 None                                                                                   connectionpool.py:452
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ /usr/lib/python3.8/runpy.py:194 in _run_module_as_main                                           │
│                                                                                                  │
│   191 │   main_globals = sys.modules["__main__"].__dict__                                        │
│   192 │   if alter_argv:                                                                         │
│   193 │   │   sys.argv[0] = mod_spec.origin                                                      │
│ ❱ 194 │   return _run_code(code, main_globals, None,                                             │
│   195 │   │   │   │   │    "__main__", mod_spec)                                                 │
│   196                                                                                            │
│   197 def run_module(mod_name, init_globals=None,                                                │
│                                                                                                  │
│ /usr/lib/python3.8/runpy.py:87 in _run_code                                                      │
│                                                                                                  │
│    84 │   │   │   │   │      __loader__ = loader,                                                │
│    85 │   │   │   │   │      __package__ = pkg_name,                                             │
│    86 │   │   │   │   │      __spec__ = mod_spec)                                                │
│ ❱  87 │   exec(code, run_globals)                                                                │
│    88 │   return run_globals                                                                     │
│    89                                                                                            │
│    90 def _run_module_code(code, init_globals=None,                                              │
│                                                                                                  │
│ /home/ubuntu/cryptodex/cryptodex/__main__.py:221 in <module>                                     │
│                                                                                                  │
│   218                                                                                            │
│   219 if __name__ == "__main__":                                                                 │
│   220 │   try:                                                                                   │
│ ❱ 221 │   │   app()                                                                              │
│   222 │   except KeyboardInterrupt:                                                              │
│   223 │   │   log.critical("Interrupted by user")                                                │
│   224 │   │   try:                                                                               │
│                                                                                                  │
│ /home/ubuntu/.local/lib/python3.8/site-packages/click/core.py:829 in __call__                    │
│                                                                                                  │
│    826 │                                                                                         │
│    827 │   def __call__(self, *args, **kwargs):                                                  │
│    828 │   │   """Alias for :meth:`main`."""                                                     │
│ ❱  829 │   │   return self.main(*args, **kwargs)                                                 │
│    830                                                                                           │
│    831                                                                                           │
│    832 class Command(BaseCommand):                                                               │
│                                                                                                  │
│ /home/ubuntu/.local/lib/python3.8/site-packages/click/core.py:782 in main                        │
│                                                                                                  │
│    779 │   │   try:                                                                              │
│    780 │   │   │   try:                                                                          │
│    781 │   │   │   │   with self.make_context(prog_name, args, **extra) as ctx:                  │
│ ❱  782 │   │   │   │   │   rv = self.invoke(ctx)                                                 │
│    783 │   │   │   │   │   if not standalone_mode:                                               │
│    784 │   │   │   │   │   │   return rv                                                         │
│    785 │   │   │   │   │   # it's not safe to `ctx.exit(rv)` here!                               │
│                                                                                                  │
│ /home/ubuntu/.local/lib/python3.8/site-packages/click_shell/core.py:164 in invoke                │
│                                                                                                  │
│   161 │   def invoke(self, ctx):                                                                 │
│   162 │   │   # Call super() first.  This ensures that we call the method body of our instance   │
│   163 │   │   # in case it's something other than `pass`                                         │
│ ❱ 164 │   │   ret = super(Shell, self).invoke(ctx)                                               │
│   165 │   │                                                                                      │
│   166 │   │   if not ctx.protected_args and not ctx.invoked_subcommand:                          │
│   167 │   │   │   # Set this to None so that it doesn't get printed out in usage messages        │
│                                                                                                  │
│ /home/ubuntu/.local/lib/python3.8/site-packages/click/core.py:1236 in invoke                     │
│                                                                                                  │
│   1233 │   │   │   # list (which means that no subcommand actually was executed).                │
│   1234 │   │   │   if self.invoke_without_command:                                               │
│   1235 │   │   │   │   if not self.chain:                                                        │
│ ❱ 1236 │   │   │   │   │   return Command.invoke(self, ctx)                                      │
│   1237 │   │   │   │   with ctx:                                                                 │
│   1238 │   │   │   │   │   Command.invoke(self, ctx)                                             │
│   1239 │   │   │   │   │   return _process_result([])                                            │
│                                                                                                  │
│ /home/ubuntu/.local/lib/python3.8/site-packages/click/core.py:1066 in invoke                     │
│                                                                                                  │
│   1063 │   │   """                                                                               │
│   1064 │   │   _maybe_show_deprecated_notice(self)                                               │
│   1065 │   │   if self.callback is not None:                                                     │
│ ❱ 1066 │   │   │   return ctx.invoke(self.callback, **ctx.params)                                │
│   1067                                                                                           │
│   1068                                                                                           │
│   1069 class MultiCommand(Command):                                                              │
│                                                                                                  │
│ /home/ubuntu/.local/lib/python3.8/site-packages/click/core.py:610 in invoke                      │
│                                                                                                  │
│    607 │   │   args = args[2:]                                                                   │
│    608 │   │   with augment_usage_errors(self):                                                  │
│    609 │   │   │   with ctx:                                                                     │
│ ❱  610 │   │   │   │   return callback(*args, **kwargs)                                          │
│    611 │                                                                                         │
│    612 │   def forward(*args, **kwargs):  # noqa: B902                                           │
│    613 │   │   """Similar to :meth:`invoke` but fills in default keyword                         │
│                                                                                                  │
│ /home/ubuntu/.local/lib/python3.8/site-packages/click/decorators.py:21 in new_func               │
│                                                                                                  │
│    18 │   """                                                                                    │
│    19 │                                                                                          │
│    20 │   def new_func(*args, **kwargs):                                                         │
│ ❱  21 │   │   return f(get_current_context(), *args, **kwargs)                                   │
│    22 │                                                                                          │
│    23 │   return update_wrapper(new_func, f)                                                     │
│                                                                                                  │
│ /home/ubuntu/cryptodex/cryptodex/__main__.py:89 in app                                           │
│                                                                                                  │
│    86 │   │   data["exchange"]["key"], data["exchange"]["secret"]                                │
│    87 │   )                                                                                      │
│    88 │   with console.status("[bold green]Connecting to exchange..."):                          │
│ ❱  89 │   │   portfolio.connect(exchange)                                                        │
│    90 │   ctx.obj = State(portfolio, exchange, currency)                                         │
│                                                                                                  │
│ /home/ubuntu/cryptodex/cryptodex/portfolio.py:57 in connect                                      │
│                                                                                                  │
│    54 │   │   self.holdings = []                                                                 │
│    55 │   │   cg = CoinGeckoAPI()                                                                │
│    56 │   │   market_data = cg.get_coins_markets(self.currency)                                  │
│ ❱  57 │   │   owned_assets = exchange.get_owned_assets()                                         │
│    58 │   │   available_assets = exchange.get_available_assets(self.currency)                    │
│    59 │   │   excluded_assets = [asset.lower() for asset in self.model["exclude"]]               │
│                                                                                                  │
│ /home/ubuntu/cryptodex/cryptodex/exchanges/kraken.py:45 in get_owned_assets                      │
│                                                                                                  │
│   42 │   def get_owned_assets(self):                                                             │
│   43 │   │   return {                                                                            │
│   44 │   │   │   key.lower(): value                                                              │
│ ❱ 45 │   │   │   for key, value in self.api.query_private("Balance")["result"].items()           │
│   46 │   │   │   #if float(value) > 0                                                            │
│   47 │   │   }                                                                                   │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
KeyError: 'result'
leoncvlt commented 2 years ago

Seems like it can't fetch your Kraken balance, are you sure the API keys are setup correctly? Do you have any balance available on it at all? (Haven't tested a case when there's no liquidity in the Kraken account)

zzzpotato commented 2 years ago

I do not have a balance. API all looks good. It may just need an exception to zero balance.