forked from mattsta/icli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleaned up for initial release of project started 10 months ago.
- Loading branch information
0 parents
commit db88c45
Showing
12 changed files
with
4,366 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Oops, something went wrong.