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

Basic understanding how to start? #5

Open
aravindnadumane opened this issue Feb 16, 2024 · 7 comments
Open

Basic understanding how to start? #5

aravindnadumane opened this issue Feb 16, 2024 · 7 comments

Comments

@aravindnadumane
Copy link

Hi there,
Good that you have created some tool like this but I fail to understand how to use it. I'm just a noob to python but i have been using/writing in Unix as well as perl scripts.

I merely installed pyhton3, pipx, poetry and than you installation command you gave.

and try to run the tool (hoping that it is installed somewhere else and saved in the PATH. But nothing comes out. Could you please give some elobaration in your usage deescription so someone noob like me can also understand how to use it ?
image

@mattsta
Copy link
Owner

mattsta commented Mar 4, 2024

It's probably very close to working! Try: poetry run icli so it runs inside the poetry virtual environment holding all the related packages.

It will also need your account id and gateway port (if different than the default of 4001) as described in the readme somewhere: https://github.com/mattsta/icli?tab=readme-ov-file#download-icli

@vsr2158
Copy link

vsr2158 commented Mar 30, 2024

vim env.sh

#!/bin/bash

export ICLI_IBKR_ACCOUNT_ID="U12345678"
export ICLI_IBKR_HOST='127.0.0.1'
export ICLI_IBKR_PORT='7496'
export ICLI_REFRESH='2'

then
chmod +x env.sh

then

source env.sh

then poetry run icli

@mattsta
Copy link
Owner

mattsta commented Mar 30, 2024

That is one way.

It also supports a .env.icli file where you can place those values directly into a file and they are read on startup (noted in the README). Also, command lines support single-line temporary variables so you can also do:

> ICLI_IBKR_ACCOUNT_ID=U12345678 ICLI_REFRESH=2 poetry run icli

@edlang
Copy link

edlang commented May 2, 2024

I'm receiving another error in a fresh install, with or without the .env.cli file. Looks like the else result should be two single quotes, not two double quotes.

Traceback (most recent call last):                                                                                                                            │
  File "<string>", line 1, in <module>                                                                                                                        │
  File "/usr/lib/python3.11/importlib/__init__.py", line 126, in import_module                                                                                │
    return _bootstrap._gcd_import(name[level:], package, level)                                                                                               │
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                               │
  File "<frozen importlib._bootstrap>", line 1206, in _gcd_import                                                                                             │
  File "<frozen importlib._bootstrap>", line 1178, in _find_and_load                                                                                          │
  File "<frozen importlib._bootstrap>", line 1149, in _find_and_load_unlocked                                                                                 │
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked                                                                                           │
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module                                                                                     │
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed                                                                                │
  File "/home/edlang/src/repos/icli/icli/__main__.py", line 7, in <module>                                                                                    │
    import icli.cli as cli                                                                                                                                    │
  File ".../src/repos/icli/icli/cli.py", line 2260                                                                                                   │
    f"{fmtPricePad(usePrice, decimals=decimals)} ±{fmtEquitySpread(c.ask - usePrice) if c.ask >= usePrice else "":<6}",                                       │
                                                                                                                       ^                                      │
SyntaxError: f-string: expecting '}'                                                                                                                          │

@mattsta
Copy link
Owner

mattsta commented May 2, 2024

oh, good catch. It's using a python 3.12 string feature but I should probably fix it so it works on older versions.

Until I can fix it in the repo, for now you could just change the section from:

>= usePrice else "":<6}"

to:

>= usePrice else '':<6}"

and it should work for that case.

@loucal
Copy link

loucal commented May 15, 2024

Thank you @mattsta, I was able to figure that out and actually considered posting it as a pull req, glad I saw this :)

Not sure if this is the best place for this, but I'd also like to get this working but I suspect an issue with ib_async (and also the retired ib_insync) which I posted here . My apologies for tagging you in both, if you have any time to lend insight to this I would really appreciate it, but thank you for your contributions either way!

Here is what my poetry run icli output is (with ENV vars properly set up)

2024-05-14 10:04:09.541 | INFO     | icli.helpers:<module>:53 - Futures Next Roll-Forward Date: 2024-06-17
2024-05-14 10:04:10.152 | INFO     | icli.cli:reconnect:2680 - Connecting to IBKR API...
2024-05-14 10:04:14.163 | ERROR    | icli.cli:reconnect:2741 - [] Failed to connect to IB Gateway, trying again...
2024-05-14 10:04:21.171 | ERROR    | icli.cli:reconnect:2741 - [] Failed to connect to IB Gateway, trying again...
2024-05-14 10:04:28.179 | ERROR    | icli.cli:reconnect:2741 - [] Failed to connect to IB Gateway, trying again...
2024-05-14 10:04:35.187 | ERROR    | icli.cli:reconnect:2741 - [] Failed to connect to IB Gateway, trying again...
^C2024-05-14 10:04:39.012 | ERROR    | icli.cli:reconnect:2741 - [] Failed to connect to IB Gateway, trying again...
^C2024-05-14 10:04:40.041 | WARNING  | icli.cli:reconnect:2751 - Exit requested during sleep. Goodbye.

Each of those Failed to connect comes up the second the "allow" dialog in TWS comes up. Whitelisting doesn't help and neither does extending the timeout because something is causing a disconnect just as we have success.

Just a little background, I have been successfully using the ib_insync library for trading through TWS for years up until 2 or 3 weeks ago when all these issues started. Strangely, the old ruby implementation from ibkr connects and submits trades successfully, its just very annoying to use and many of the augmenting libraries are obsolete. Not to get off topic, just to say I did verify that TWS is still set up correctly as it always has been for API connections.

@loucal
Copy link

loucal commented May 16, 2024

Despite my issues above connecting through TWS, I was able to start icli successfully by running the IB Gateway on localhost 👍

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

5 participants