mattsta / icli

interactive brokers ibkr api command line interface cli giving you the fastest way to lose all your money
Other
84 stars 19 forks source link

Basic understanding how to start? #5

Open aravindnadumane opened 4 months ago

aravindnadumane commented 4 months ago

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 commented 4 months ago

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 commented 3 months ago

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 commented 3 months ago

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 commented 2 months ago

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 commented 2 months ago

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 commented 1 month ago

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 commented 1 month ago

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