Skip to content

Commit

Permalink
Initial icli release
Browse files Browse the repository at this point in the history
Cleaned up for initial release of project started 10 months ago.
  • Loading branch information
mattsta committed Jul 11, 2021
0 parents commit db88c45
Show file tree
Hide file tree
Showing 12 changed files with 4,366 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.env.icli

dist/
cache*/
icli/hist/

*.log
*.json
*.txt
poetry.lock
13 changes: 13 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright 2021 Matt Stancliff <[email protected]>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
317 changes: 317 additions & 0 deletions README.md

Large diffs are not rendered by default.

Binary file added icli/CANYON.MID
Binary file not shown.
Empty file added icli/__init__.py
Empty file.
64 changes: 64 additions & 0 deletions icli/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/usr/bin/env python3

from prompt_toolkit.patch_stdout import patch_stdout
from loguru import logger
from mutil import safeLoop # type: ignore
import asyncio
import icli.cli as cli
import sys

from dotenv import dotenv_values
import os

CONFIG_DEFAULT = dict(
ICLI_IBKR_HOST="127.0.0.1", ICLI_IBKR_PORT=4001, ICLI_REFRESH=3.33
)

CONFIG = {**CONFIG_DEFAULT, **dotenv_values(".env.icli"), **os.environ}

try:
ACCOUNT_ID = CONFIG["ICLI_IBKR_ACCOUNT_ID"]
except:
logger.error(
"Sorry, please provide your IBKR Account ID [U...] in ICLI_IBKR_ACCOUNT_ID"
)
sys.exit(0)

HOST = CONFIG["ICLI_IBKR_HOST"]
PORT = int(CONFIG["ICLI_IBKR_PORT"])
REFRESH = float(CONFIG["ICLI_REFRESH"])


async def initcli():
app = cli.IBKRCmdlineApp(
accountId=ACCOUNT_ID, toolbarUpdateInterval=REFRESH, host=HOST, port=PORT
)
await app.setup()
if sys.stdin.isatty():
# patch entire application with prompt-toolkit-compatible stdout
with patch_stdout(raw=True):
try:
await app.dorepl()
except SystemExit:
# known good exit condition
...
else:
# NOT IMPLEMENTED HERE, HOLDOVER FROM TCLI
await app.consumeStdin()

app.stop()


def runit():
"""Entry point for icli script and __main__ for entire package."""
try:
asyncio.run(initcli())
except KeyboardInterrupt:
# known good exit condition
...
except:
logger.exception("bad bad so bad bad")


if __name__ == "__main__":
runit()
Loading

0 comments on commit db88c45

Please sign in to comment.