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

Exception: While running tt pf positions beta-weighting after choosing N #11

Open
ionescu77 opened this issue Dec 13, 2024 · 6 comments

Comments

@ionescu77
Copy link

ionescu77 commented Dec 13, 2024

Intro

Hello,

I find the terminal very practical on a daily basis, great initiative with the project.
Thank you!

Two months ago, after a sabbatical I started a small account with tasty.
Then I discovered your project on reddit.
I was also thinking of brushing-up my python skills and was thinking of using the tasty API, but then you are way ahead.

Environment

  • Macbook Air M1 (MacOS Sequoia 15.1.1)
  • I created a directory and a new venv which I sourced
  • I am running python --version Python 3.13.1
  • I installed using pip install tastytrade-cli
  • I checked the config but did not change anything yet

Error Description

  • I ran tt pf positions
  • I got a nice table of portfolio positions
  • and I also got a beta-weighting warning
  • I chose N because I did not want to close any position
  • but then the program exited with an exception:
tt pf positions
Username:
Password:
1) *********** Individual (default)
Please choose an account: 1
                                                      Positions
┏━━━━┳━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━━┓
┃ #  ┃ Symbol                ┃ Qty ┃  Day P/L ┃ Total P/L ┃ Mark Price ┃ IV Rank ┃ β Delta ┃   Net Liq ┃ Indicators ┃
┡━━━━╇━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━╇━━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━━┩
│ 1  │ BAC   250321C00046000 │   1 │   -$2.50 │  -$281.42 │      $2.58 │    27.4 │   31.50 │   $258.50 │    E 28    │
│ 2  │ BAC   250321C00048000 │  -1 │  -$11.50 │   $182.46 │      $1.54 │    27.4 │  -14.32 │  -$153.50 │    E 28    │
│ 3  │ CPNG  250321C00023000 │   1 │    $2.00 │  -$236.03 │      $2.97 │    22.3 │   33.55 │   $297.00 │            │

# portfolio items

│ 25 │ YOU   250516C00036000 │  -1 │   -$2.50 │   $128.48 │      $1.52 │    57.0 │   -9.51 │  -$152.50 │            │
├────┼───────────────────────┼─────┼──────────┼───────────┼────────────┼─────────┼─────────┼───────────┼────────────┤
│    │                       │     │ -$xxx.xx │ -$xxxx.xx │            │         │  265.68 │  $xxxx.45 │            │
└────┴───────────────────────┴─────┴──────────┴───────────┴────────────┴─────────┴─────────┴───────────┴────────────┘
Warning: Portfolio beta-weighting misses target of 0 substantially!
Close out a position? y/N N
an error occurred during closing of asynchronous generator <async_generator object Connection.send_context at 0x1064bc7b0>
asyncgen: <async_generator object Connection.send_context at 0x1064bc7b0>
Traceback (most recent call last):
  File "/Users/razvansky/tasty-client/lib/python3.13/site-packages/asyncclick/core.py", line 1130, in main
    ctx.exit()
    ~~~~~~~~^^
  File "/Users/razvansky/tasty-client/lib/python3.13/site-packages/asyncclick/core.py", line 731, in exit
    raise Exit(code)
asyncclick.exceptions.Exit: 0

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/razvansky/tasty-client/lib/python3.13/site-packages/anyio/_backends/_asyncio.py", line 2347, in run
    return runner.run(wrapper())
           ~~~~~~~~~~^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.13.1/Frameworks/Python.framework/Versions/3.13/lib/python3.13/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.13.1/Frameworks/Python.framework/Versions/3.13/lib/python3.13/asyncio/base_events.py", line 707, in run_until_complete
    self.run_forever()
    ~~~~~~~~~~~~~~~~^^
  File "/opt/homebrew/Cellar/[email protected]/3.13.1/Frameworks/Python.framework/Versions/3.13/lib/python3.13/asyncio/base_events.py", line 678, in run_forever
    self._run_once()
    ~~~~~~~~~~~~~~^^
  File "/opt/homebrew/Cellar/[email protected]/3.13.1/Frameworks/Python.framework/Versions/3.13/lib/python3.13/asyncio/base_events.py", line 2033, in _run_once
    handle._run()
    ~~~~~~~~~~~^^
  File "/opt/homebrew/Cellar/[email protected]/3.13.1/Frameworks/Python.framework/Versions/3.13/lib/python3.13/asyncio/events.py", line 89, in _run
    self._context.run(self._callback, *self._args)
    ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/razvansky/tasty-client/lib/python3.13/site-packages/anyio/_backends/_asyncio.py", line 2335, in wrapper
    return await func(*args)
           ^^^^^^^^^^^^^^^^^
  File "/Users/razvansky/tasty-client/lib/python3.13/site-packages/asyncclick/core.py", line 1208, in _main
    return await main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/razvansky/tasty-client/lib/python3.13/site-packages/asyncclick/core.py", line 1148, in main
    sys.exit(e.exit_code)
    ~~~~~~~~^^^^^^^^^^^^^
SystemExit: 0

During handling of the above exception, another exception occurred:

RuntimeError: aclose(): asynchronous generator is already running
Task was destroyed but it is pending!
task: <Task pending name='Task-7' coro=<<async_generator_athrow without __name__>()> wait_for=<Future pending cb=[shield.<locals>._outer_done_callback() at /opt/homebrew/Cellar/[email protected]/3.13.1/Frameworks/Python.framework/Versions/3.13/lib/python3.13/asyncio/tasks.py:975, Task.task_wakeup()]>>

I did not go deep into the code yet, as I wanted first to have a look at the current state of the app.

I was thinking about writing a quick-start guide or readme if you need some help with the project.

Best regards,

Raz

@ionescu77
Copy link
Author

ionescu77 commented Dec 13, 2024

Okay so the application is exiting as intended I guess (default or N user selection):

close = get_confirmation("Close out a position? y/N ", default=False)

   close = get_confirmation("Close out a position? y/N ", default=False)
    if not close:
        return

I just thought there's an error. Might be due to the async parts for streaming the data from tasty.

@ionescu77 ionescu77 closed this as not planned Won't fix, can't repro, duplicate, stale Dec 13, 2024
@Graeme22
Copy link
Contributor

Graeme22 commented Dec 13, 2024

Hey, thanks for opening! You're right that this isn't a "real" error, however we don't really want to display it! Turns out closing the data streamer isn't handled correctly in the SDK v9.4, so if you downgrade to v9.3 for now you won't see the annoying messages. I'll fix this in the next SDK release, so it'll be fixed by upgrading to v9.5 down the road. So I'm going to reopen this actually.

@Graeme22 Graeme22 reopened this Dec 13, 2024
@ionescu77
Copy link
Author

Hi, quick update.

I have cloned the repo and installed using make install, following the instructions for contributors (I wanted to try to fix the error).

  • make sure uv is installed
  • git clone the repo
  • cd into tastytrade-cli directory
  • run make install
  • source the venv: source .venv/bin/activate
  • run tt pf positions
  • after entering user/pass I got the table with my portfolio positions
  • got the beta-weighting warning and pressed enter for default N
  • script exited nicelly, no errors or warnings this time
Warning: Portfolio beta-weighting misses target of 0 substantially!
Close out a position? y/N N

The only difference is first when encountering this issue I have manually created a venv and installed tastytrade-client with pip.

Both environments seem to run the same verion

tt --version
tt, version 0.4

@Graeme22
Copy link
Contributor

Between now and when you opened the issue, the SDK version 9.5 has been released! So that's why it's working now. I'll close this when I update the CLI to use the latest SDK version.

@ionescu77
Copy link
Author

ionescu77 commented Dec 20, 2024

I can confirm, after updating the tastytrade package with pip I get no more exceptions in my original venv.

pip list --outdated
Package       Version   Latest     Type
------------- --------- ---------- -----
certifi       2024.8.30 2024.12.14 wheel
pydantic      2.10.3    2.10.4     wheel
pydantic_core 2.27.1    2.27.2     wheel
tastytrade    9.4       9.5        wheel

❯ pip install --upgrade tastytrade

    Uninstalling tastytrade-9.4:
      Successfully uninstalled tastytrade-9.4
Successfully installed tastytrade-9.5

Thank you, I will play with the cli and let you know! Maybe I can write some notes and some docs.

@Graeme22
Copy link
Contributor

I can confirm, after updating the tastytrade package with pip I get no more exceptions in my original venv.

pip list --outdated
Package       Version   Latest     Type
------------- --------- ---------- -----
certifi       2024.8.30 2024.12.14 wheel
pydantic      2.10.3    2.10.4     wheel
pydantic_core 2.27.1    2.27.2     wheel
tastytrade    9.4       9.5        wheel

❯ pip install --upgrade tastytrade

    Uninstalling tastytrade-9.4:
      Successfully uninstalled tastytrade-9.4
Successfully installed tastytrade-9.5

Thank you, I will play with the cli and let you know! Maybe I can write some notes and some docs.

Go for it! Would be appreciated :)

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

No branches or pull requests

2 participants