From af9e9449282f33ee5da4559431ac594aab6eb470 Mon Sep 17 00:00:00 2001 From: David Brazda Date: Wed, 12 Apr 2023 21:00:03 +0200 Subject: [PATCH] first commit --- .gitignore | 2 + .gtignore | 34 + .vscode/launch.json | 18 + .vscode/settings.json | 6 + requirements.txt | 96 + setup.py | 9 + testy/archive/.gtignore | 27 + .../__pycache__/config.cpython-311.pyc | Bin 0 -> 304 bytes testy/archive/alpacaGetHistoryBars.py | 52 + testy/archive/alpacabacktrader/test.py | 51 + testy/archive/alpacaexampleslive.py | 172 + testy/archive/alpacagetlasttrades.py | 39 + testy/archive/alpacapyexampleshistorical.py | 66 + testy/archive/alpacawebsocketsimple.py | 74 + testy/archive/async.py | 47 + testy/archive/changeiterable.py | 57 + testy/archive/classscope.py | 38 + testy/archive/config.py | 3 + testy/archive/hello_panel_world.py | 5 + testy/archive/interpolace.py | 17 + testy/archive/multiprocess.py | 31 + testy/archive/test.ipynb | 145 + testy/archive/test.py | 66 + testy/archive/testqueue.py | 1 + testy/archive/threadcondition.py | 35 + testy/archive/thready.py | 54 + testy/changeiterable (kopie).py | 74 + testy/changeiterable.py | 70 + testy/dash_backtest_results.py | 9915 +++++++++++++++++ testy/dash_save_html.py | 151 + testy/debugprints.py | 38 + testy/decorator_test.py | 70 + testy/gethistorytrades.py | 34 + testy/loghandlers.py | 49 + testy/modulmistoclass-websocket.py | 88 + testy/pandasinsert.py | 75 + testy/pracesdatumem.py | 133 + testy/printoverride.py | 19 + testy/testExecList-bisect.py | 233 + testy/testExecList-standard.py | 354 + testy/testServices.py | 22 + testy/testStore | 57 + testy/testTIMIT | 12 + testy/testloadfromcache.py | 86 + testy/threadclassestest.py | 165 + testy/websocketFastApi.py | 111 + testy/websocketFastApiConnManager.py | 111 + v2realbot/ENTRY_backtest_strategy.py | 90 + v2realbot/ENTRY_backtest_strategyKOKA-ok.py | 99 + v2realbot/ENTRY_backtest_strategyVykladaci.py | 243 + v2realbot/ENTRY_backtest_strategyWatched.py | 103 + v2realbot/ENTRY_latency_roundtrip.py | 70 + .../ENTRY_strategy_vykladaci_REFACTOR.py | 5 + ...NAL_MA_VYK_10s_AGGR_mastrategyvykladaci.py | 200 + v2realbot/__init__.py | 0 .../__pycache__/__init__.cpython-310.pyc | Bin 0 -> 172 bytes v2realbot/__pycache__/config.cpython-310.pyc | Bin 0 -> 2465 bytes v2realbot/backtesting/__init__.py | 0 .../__pycache__/__init__.cpython-310.pyc | Bin 0 -> 184 bytes .../__pycache__/__init__.cpython-311.pyc | Bin 0 -> 198 bytes .../__pycache__/backtester.cpython-310.pyc | Bin 0 -> 17942 bytes .../__pycache__/backtester.cpython-311.pyc | Bin 0 -> 36426 bytes v2realbot/backtesting/backtester.py | 816 ++ v2realbot/common/__init__.py | 0 .../__pycache__/__init__.cpython-310.pyc | Bin 0 -> 179 bytes .../__pycache__/__init__.cpython-311.pyc | Bin 0 -> 193 bytes .../common/__pycache__/model.cpython-310.pyc | Bin 0 -> 3130 bytes .../common/__pycache__/model.cpython-311.pyc | Bin 0 -> 4797 bytes v2realbot/common/model.py | 100 + v2realbot/conf.toml | 100 + v2realbot/config.py | 74 + v2realbot/controller/__init__.py | 0 .../__pycache__/__init__.cpython-311.pyc | Bin 0 -> 197 bytes .../__pycache__/services.cpython-311.pyc | Bin 0 -> 17658 bytes v2realbot/controller/services.py | 317 + v2realbot/emptystrategy.py | 27 + v2realbot/enums/__init__.py | 0 .../__pycache__/__init__.cpython-310.pyc | Bin 0 -> 178 bytes .../__pycache__/__init__.cpython-311.pyc | Bin 0 -> 192 bytes .../enums/__pycache__/enums.cpython-310.pyc | Bin 0 -> 1924 bytes .../enums/__pycache__/enums.cpython-311.pyc | Bin 0 -> 2698 bytes .../enums/__pycache__/myenums.cpython-311.pyc | Bin 0 -> 2361 bytes v2realbot/enums/enums.py | 47 + v2realbot/indicators/__init__.py | 0 .../__pycache__/__init__.cpython-310.pyc | Bin 0 -> 183 bytes .../__pycache__/__init__.cpython-311.pyc | Bin 0 -> 197 bytes .../__pycache__/indicators.cpython-310.pyc | Bin 0 -> 1289 bytes .../__pycache__/indicators.cpython-311.pyc | Bin 0 -> 2154 bytes v2realbot/indicators/indicators.py | 36 + v2realbot/indicators/moving_averages.py | 119 + v2realbot/interfaces/__init__.py | 0 .../__pycache__/__init__.cpython-310.pyc | Bin 0 -> 183 bytes .../__pycache__/__init__.cpython-311.pyc | Bin 0 -> 197 bytes .../backtest_interface.cpython-310.pyc | Bin 0 -> 3106 bytes .../backtest_interface.cpython-311.pyc | Bin 0 -> 5069 bytes .../general_interface.cpython-310.pyc | Bin 0 -> 2026 bytes .../general_interface.cpython-311.pyc | Bin 0 -> 2529 bytes .../live_interface.cpython-310.pyc | Bin 0 -> 5269 bytes .../live_interface.cpython-311.pyc | Bin 0 -> 9094 bytes .../__pycache__/orders.cpython-311.pyc | Bin 0 -> 20767 bytes .../__pycache__/orderupdates.cpython-311.pyc | Bin 0 -> 3433 bytes v2realbot/interfaces/backtest_interface.py | 67 + v2realbot/interfaces/general_interface.py | 42 + v2realbot/interfaces/live_interface.py | 187 + v2realbot/loader/__init__.py | 0 .../__pycache__/__init__.cpython-310.pyc | Bin 0 -> 179 bytes .../__pycache__/__init__.cpython-311.pyc | Bin 0 -> 193 bytes .../__pycache__/aggregator.cpython-310.pyc | Bin 0 -> 6490 bytes .../__pycache__/aggregator.cpython-311.pyc | Bin 0 -> 12100 bytes .../order_updates_streamer.cpython-310.pyc | Bin 0 -> 1830 bytes .../order_updates_streamer.cpython-311.pyc | Bin 0 -> 2785 bytes .../trade_offline_streamer.cpython-310.pyc | Bin 0 -> 5089 bytes .../trade_offline_streamer.cpython-311.pyc | Bin 0 -> 10210 bytes .../trade_ws_streamer.cpython-310.pyc | Bin 0 -> 3553 bytes .../trade_ws_streamer.cpython-311.pyc | Bin 0 -> 6185 bytes v2realbot/loader/aggregator.py | 329 + v2realbot/loader/order_updates_streamer.py | 44 + v2realbot/loader/trade_offline_streamer.py | 207 + v2realbot/loader/trade_ws_streamer.py | 136 + v2realbot/main.py | 270 + v2realbot/static/index.html | 252 + .../static/js/dataTables.bootstrap.min.css | 1 + .../static/js/dataTables.bootstrap.min.js | 8 + v2realbot/static/js/jquery.dataTables.min.js | 166 + v2realbot/static/js/jquery.serializejson.js | 338 + v2realbot/static/js/mychart.js | 57 + v2realbot/static/js/mytables.js | 441 + v2realbot/static/js/mywebsocket.js | 107 + v2realbot/strategy/StrategyOrderLimitKOKA.py | 86 + .../strategy/StrategyOrderLimitVykladaci.py | 122 + v2realbot/strategy/__init__.py | 0 ...trategyOrderLimitVykladaci.cpython-310.pyc | Bin 0 -> 5054 bytes .../__pycache__/__init__.cpython-310.pyc | Bin 0 -> 181 bytes .../__pycache__/__init__.cpython-311.pyc | Bin 0 -> 195 bytes .../strategy/__pycache__/base.cpython-310.pyc | Bin 0 -> 11681 bytes .../strategy/__pycache__/base.cpython-311.pyc | Bin 0 -> 23995 bytes .../__pycache__/strategy.cpython-311.pyc | Bin 0 -> 10613 bytes .../strategyOrderLimit.cpython-311.pyc | Bin 0 -> 8568 bytes .../strategyOrderLimitKOKA.cpython-311.pyc | Bin 0 -> 7691 bytes ...trategyOrderLimitVykladaci.cpython-311.pyc | Bin 0 -> 10158 bytes .../strategyOrderLimitWatched.cpython-311.pyc | Bin 0 -> 6742 bytes .../strategyType_Limit.cpython-311.pyc | Bin 0 -> 7672 bytes v2realbot/strategy/base.py | 449 + v2realbot/strategy/strategyOrderLimit.py | 99 + .../strategy/strategyOrderLimitWatched.py | 68 + v2realbot/strategy/strategyType_Limit.py | 163 + v2realbot/utils/__init__.py | 0 .../__pycache__/__init__.cpython-310.pyc | Bin 0 -> 178 bytes .../__pycache__/__init__.cpython-311.pyc | Bin 0 -> 192 bytes .../dash_save_html.cpython-310.pyc | Bin 0 -> 3618 bytes .../dash_save_html.cpython-311.pyc | Bin 0 -> 5793 bytes .../utils/__pycache__/tlog.cpython-310.pyc | Bin 0 -> 1271 bytes .../utils/__pycache__/tlog.cpython-311.pyc | Bin 0 -> 2319 bytes .../utils/__pycache__/utils.cpython-310.pyc | Bin 0 -> 6923 bytes .../utils/__pycache__/utils.cpython-311.pyc | Bin 0 -> 12065 bytes v2realbot/utils/dash_save_html.py | 97 + v2realbot/utils/tlog.py | 40 + v2realbot/utils/utils.py | 188 + 158 files changed, 19422 insertions(+) create mode 100644 .gitignore create mode 100644 .gtignore create mode 100644 .vscode/launch.json create mode 100644 .vscode/settings.json create mode 100644 requirements.txt create mode 100644 setup.py create mode 100644 testy/archive/.gtignore create mode 100644 testy/archive/__pycache__/config.cpython-311.pyc create mode 100644 testy/archive/alpacaGetHistoryBars.py create mode 100644 testy/archive/alpacabacktrader/test.py create mode 100644 testy/archive/alpacaexampleslive.py create mode 100644 testy/archive/alpacagetlasttrades.py create mode 100644 testy/archive/alpacapyexampleshistorical.py create mode 100644 testy/archive/alpacawebsocketsimple.py create mode 100644 testy/archive/async.py create mode 100644 testy/archive/changeiterable.py create mode 100644 testy/archive/classscope.py create mode 100644 testy/archive/config.py create mode 100644 testy/archive/hello_panel_world.py create mode 100644 testy/archive/interpolace.py create mode 100644 testy/archive/multiprocess.py create mode 100644 testy/archive/test.ipynb create mode 100644 testy/archive/test.py create mode 100644 testy/archive/testqueue.py create mode 100644 testy/archive/threadcondition.py create mode 100644 testy/archive/thready.py create mode 100644 testy/changeiterable (kopie).py create mode 100644 testy/changeiterable.py create mode 100644 testy/dash_backtest_results.py create mode 100644 testy/dash_save_html.py create mode 100644 testy/debugprints.py create mode 100644 testy/decorator_test.py create mode 100644 testy/gethistorytrades.py create mode 100644 testy/loghandlers.py create mode 100644 testy/modulmistoclass-websocket.py create mode 100644 testy/pandasinsert.py create mode 100644 testy/pracesdatumem.py create mode 100644 testy/printoverride.py create mode 100644 testy/testExecList-bisect.py create mode 100644 testy/testExecList-standard.py create mode 100644 testy/testServices.py create mode 100644 testy/testStore create mode 100644 testy/testTIMIT create mode 100644 testy/testloadfromcache.py create mode 100644 testy/threadclassestest.py create mode 100644 testy/websocketFastApi.py create mode 100644 testy/websocketFastApiConnManager.py create mode 100644 v2realbot/ENTRY_backtest_strategy.py create mode 100644 v2realbot/ENTRY_backtest_strategyKOKA-ok.py create mode 100644 v2realbot/ENTRY_backtest_strategyVykladaci.py create mode 100644 v2realbot/ENTRY_backtest_strategyWatched.py create mode 100644 v2realbot/ENTRY_latency_roundtrip.py create mode 100644 v2realbot/ENTRY_strategy_vykladaci_REFACTOR.py create mode 100644 v2realbot/FINAL_MA_VYK_10s_AGGR_mastrategyvykladaci.py create mode 100644 v2realbot/__init__.py create mode 100644 v2realbot/__pycache__/__init__.cpython-310.pyc create mode 100644 v2realbot/__pycache__/config.cpython-310.pyc create mode 100644 v2realbot/backtesting/__init__.py create mode 100644 v2realbot/backtesting/__pycache__/__init__.cpython-310.pyc create mode 100644 v2realbot/backtesting/__pycache__/__init__.cpython-311.pyc create mode 100644 v2realbot/backtesting/__pycache__/backtester.cpython-310.pyc create mode 100644 v2realbot/backtesting/__pycache__/backtester.cpython-311.pyc create mode 100644 v2realbot/backtesting/backtester.py create mode 100644 v2realbot/common/__init__.py create mode 100644 v2realbot/common/__pycache__/__init__.cpython-310.pyc create mode 100644 v2realbot/common/__pycache__/__init__.cpython-311.pyc create mode 100644 v2realbot/common/__pycache__/model.cpython-310.pyc create mode 100644 v2realbot/common/__pycache__/model.cpython-311.pyc create mode 100644 v2realbot/common/model.py create mode 100644 v2realbot/conf.toml create mode 100644 v2realbot/config.py create mode 100644 v2realbot/controller/__init__.py create mode 100644 v2realbot/controller/__pycache__/__init__.cpython-311.pyc create mode 100644 v2realbot/controller/__pycache__/services.cpython-311.pyc create mode 100644 v2realbot/controller/services.py create mode 100644 v2realbot/emptystrategy.py create mode 100644 v2realbot/enums/__init__.py create mode 100644 v2realbot/enums/__pycache__/__init__.cpython-310.pyc create mode 100644 v2realbot/enums/__pycache__/__init__.cpython-311.pyc create mode 100644 v2realbot/enums/__pycache__/enums.cpython-310.pyc create mode 100644 v2realbot/enums/__pycache__/enums.cpython-311.pyc create mode 100644 v2realbot/enums/__pycache__/myenums.cpython-311.pyc create mode 100644 v2realbot/enums/enums.py create mode 100644 v2realbot/indicators/__init__.py create mode 100644 v2realbot/indicators/__pycache__/__init__.cpython-310.pyc create mode 100644 v2realbot/indicators/__pycache__/__init__.cpython-311.pyc create mode 100644 v2realbot/indicators/__pycache__/indicators.cpython-310.pyc create mode 100644 v2realbot/indicators/__pycache__/indicators.cpython-311.pyc create mode 100644 v2realbot/indicators/indicators.py create mode 100644 v2realbot/indicators/moving_averages.py create mode 100644 v2realbot/interfaces/__init__.py create mode 100644 v2realbot/interfaces/__pycache__/__init__.cpython-310.pyc create mode 100644 v2realbot/interfaces/__pycache__/__init__.cpython-311.pyc create mode 100644 v2realbot/interfaces/__pycache__/backtest_interface.cpython-310.pyc create mode 100644 v2realbot/interfaces/__pycache__/backtest_interface.cpython-311.pyc create mode 100644 v2realbot/interfaces/__pycache__/general_interface.cpython-310.pyc create mode 100644 v2realbot/interfaces/__pycache__/general_interface.cpython-311.pyc create mode 100644 v2realbot/interfaces/__pycache__/live_interface.cpython-310.pyc create mode 100644 v2realbot/interfaces/__pycache__/live_interface.cpython-311.pyc create mode 100644 v2realbot/interfaces/__pycache__/orders.cpython-311.pyc create mode 100644 v2realbot/interfaces/__pycache__/orderupdates.cpython-311.pyc create mode 100644 v2realbot/interfaces/backtest_interface.py create mode 100644 v2realbot/interfaces/general_interface.py create mode 100644 v2realbot/interfaces/live_interface.py create mode 100644 v2realbot/loader/__init__.py create mode 100644 v2realbot/loader/__pycache__/__init__.cpython-310.pyc create mode 100644 v2realbot/loader/__pycache__/__init__.cpython-311.pyc create mode 100644 v2realbot/loader/__pycache__/aggregator.cpython-310.pyc create mode 100644 v2realbot/loader/__pycache__/aggregator.cpython-311.pyc create mode 100644 v2realbot/loader/__pycache__/order_updates_streamer.cpython-310.pyc create mode 100644 v2realbot/loader/__pycache__/order_updates_streamer.cpython-311.pyc create mode 100644 v2realbot/loader/__pycache__/trade_offline_streamer.cpython-310.pyc create mode 100644 v2realbot/loader/__pycache__/trade_offline_streamer.cpython-311.pyc create mode 100644 v2realbot/loader/__pycache__/trade_ws_streamer.cpython-310.pyc create mode 100644 v2realbot/loader/__pycache__/trade_ws_streamer.cpython-311.pyc create mode 100644 v2realbot/loader/aggregator.py create mode 100644 v2realbot/loader/order_updates_streamer.py create mode 100644 v2realbot/loader/trade_offline_streamer.py create mode 100644 v2realbot/loader/trade_ws_streamer.py create mode 100644 v2realbot/main.py create mode 100644 v2realbot/static/index.html create mode 100644 v2realbot/static/js/dataTables.bootstrap.min.css create mode 100644 v2realbot/static/js/dataTables.bootstrap.min.js create mode 100644 v2realbot/static/js/jquery.dataTables.min.js create mode 100644 v2realbot/static/js/jquery.serializejson.js create mode 100644 v2realbot/static/js/mychart.js create mode 100644 v2realbot/static/js/mytables.js create mode 100644 v2realbot/static/js/mywebsocket.js create mode 100644 v2realbot/strategy/StrategyOrderLimitKOKA.py create mode 100644 v2realbot/strategy/StrategyOrderLimitVykladaci.py create mode 100644 v2realbot/strategy/__init__.py create mode 100644 v2realbot/strategy/__pycache__/StrategyOrderLimitVykladaci.cpython-310.pyc create mode 100644 v2realbot/strategy/__pycache__/__init__.cpython-310.pyc create mode 100644 v2realbot/strategy/__pycache__/__init__.cpython-311.pyc create mode 100644 v2realbot/strategy/__pycache__/base.cpython-310.pyc create mode 100644 v2realbot/strategy/__pycache__/base.cpython-311.pyc create mode 100644 v2realbot/strategy/__pycache__/strategy.cpython-311.pyc create mode 100644 v2realbot/strategy/__pycache__/strategyOrderLimit.cpython-311.pyc create mode 100644 v2realbot/strategy/__pycache__/strategyOrderLimitKOKA.cpython-311.pyc create mode 100644 v2realbot/strategy/__pycache__/strategyOrderLimitVykladaci.cpython-311.pyc create mode 100644 v2realbot/strategy/__pycache__/strategyOrderLimitWatched.cpython-311.pyc create mode 100644 v2realbot/strategy/__pycache__/strategyType_Limit.cpython-311.pyc create mode 100644 v2realbot/strategy/base.py create mode 100644 v2realbot/strategy/strategyOrderLimit.py create mode 100644 v2realbot/strategy/strategyOrderLimitWatched.py create mode 100644 v2realbot/strategy/strategyType_Limit.py create mode 100644 v2realbot/utils/__init__.py create mode 100644 v2realbot/utils/__pycache__/__init__.cpython-310.pyc create mode 100644 v2realbot/utils/__pycache__/__init__.cpython-311.pyc create mode 100644 v2realbot/utils/__pycache__/dash_save_html.cpython-310.pyc create mode 100644 v2realbot/utils/__pycache__/dash_save_html.cpython-311.pyc create mode 100644 v2realbot/utils/__pycache__/tlog.cpython-310.pyc create mode 100644 v2realbot/utils/__pycache__/tlog.cpython-311.pyc create mode 100644 v2realbot/utils/__pycache__/utils.cpython-310.pyc create mode 100644 v2realbot/utils/__pycache__/utils.cpython-311.pyc create mode 100644 v2realbot/utils/dash_save_html.py create mode 100644 v2realbot/utils/tlog.py create mode 100644 v2realbot/utils/utils.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..74eee65 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/.DS_Store +/v2realbot.egg-info \ No newline at end of file diff --git a/.gtignore b/.gtignore new file mode 100644 index 0000000..076d5aa --- /dev/null +++ b/.gtignore @@ -0,0 +1,34 @@ +/__pycache__/ +/backtestresults/ +/cache/ +/v2realbot/backtestresults/ +/v2realbot/cache/ +/v2realbot/__pycache__/ +/.vscode/ + +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..c3cea39 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,18 @@ +{ + // Pro informace o možných atributech použijte technologii IntelliSense. + // Umístěním ukazatele myši zobrazíte popisy existujících atributů. + // Další informace najdete tady: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Python: Aktuální soubor", + "type": "python", + "request": "launch", + "program": "${file}", + "cwd": "${workspaceFolder}", + "env": {"PYTHONPATH": "${workspaceFolder}:${workspaceFolder}/bld"}, + "console": "integratedTerminal", + "justMyCode": true + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..d4dd544 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "python.analysis.logLevel": "Trace", + "terminal.integrated.env.osx": { + "PYTHONPATH": "${workspaceFolder}/" + } +} \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..1bf72ea --- /dev/null +++ b/requirements.txt @@ -0,0 +1,96 @@ +alpaca==1.0.0 +alpaca-py==0.7.1 +altair==4.2.2 +anyio==3.6.2 +appdirs==1.4.4 +asttokens==2.2.1 +attrs==22.2.0 +better-exceptions==0.3.3 +bleach==6.0.0 +blinker==1.5 +cachetools==5.3.0 +certifi==2022.12.7 +chardet==5.1.0 +charset-normalizer==3.0.1 +click==8.1.3 +contourpy==1.0.7 +cycler==0.11.0 +dash==2.9.1 +dash-bootstrap-components==1.4.1 +dash-core-components==2.0.0 +dash-html-components==2.0.0 +dash-table==5.0.0 +decorator==5.1.1 +entrypoints==0.4 +executing==1.2.0 +fastapi==0.95.0 +Flask==2.2.3 +fonttools==4.39.0 +gitdb==4.0.10 +GitPython==3.1.31 +h11==0.14.0 +icecream==2.1.3 +idna==3.4 +importlib-metadata==6.1.0 +itsdangerous==2.1.2 +jsonschema==4.17.3 +kiwisolver==1.4.4 +Markdown==3.4.3 +markdown-it-py==2.2.0 +MarkupSafe==2.1.2 +mdurl==0.1.2 +msgpack==1.0.4 +newtulipy==0.4.6 +numpy==1.24.2 +packaging==23.0 +pandas==1.5.3 +param==1.13.0 +Pillow==9.4.0 +plotly==5.13.1 +proto-plus==1.22.2 +protobuf==3.20.3 +pyarrow==11.0.0 +pyasn1==0.4.8 +pyasn1-modules==0.2.8 +pyct==0.5.0 +pydantic==1.10.5 +pydeck==0.8.0 +Pygments==2.14.0 +Pympler==1.0.1 +pyparsing==3.0.9 +pyrsistent==0.19.3 +pysos==1.3.0 +python-dateutil==2.8.2 +python-dotenv==1.0.0 +pytz==2022.7.1 +pytz-deprecation-shim==0.1.0.post0 +pyviz-comms==2.2.1 +PyYAML==6.0 +requests==2.28.2 +rich==13.3.1 +rsa==4.9 +seaborn==0.12.2 +semver==2.13.0 +six==1.16.0 +smmap==5.0.0 +sniffio==1.3.0 +sseclient-py==1.7.2 +starlette==0.26.1 +streamlit==1.20.0 +structlog==23.1.0 +tenacity==8.2.2 +toml==0.10.2 +tomli==2.0.1 +toolz==0.12.0 +tornado==6.2 +tqdm==4.65.0 +typing_extensions==4.5.0 +tzdata==2023.2 +tzlocal==4.3 +urllib3==1.26.14 +uvicorn==0.21.1 +validators==0.20.0 +webencodings==0.5.1 +websockets==10.4 +Werkzeug==2.2.3 +zipp==3.15.0 diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..7e3d135 --- /dev/null +++ b/setup.py @@ -0,0 +1,9 @@ +from setuptools import find_packages, setup + +setup(name='v2realbot', + version='0.9', + description='Realbot trader', + author='David Brazda', + author_email='davidbrazda61@gmail.com', + packages=find_packages() + ) \ No newline at end of file diff --git a/testy/archive/.gtignore b/testy/archive/.gtignore new file mode 100644 index 0000000..75004fa --- /dev/null +++ b/testy/archive/.gtignore @@ -0,0 +1,27 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST +cache/ \ No newline at end of file diff --git a/testy/archive/__pycache__/config.cpython-311.pyc b/testy/archive/__pycache__/config.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..a6089956a72f96ad536c3f43dec8217eac9a1b8d GIT binary patch literal 304 zcmZ3^%ge<81c~=qQgVRwV-N=h7@>^MLO{lJh7^V@GEIF_k`i+~ONt}RGs2>B zk^&+reqLH;x?Vx$FAkgB{FKt1RJ$T>pt&HY6iWb!56p~=j5oLx8rW~} Snm2IW5EN?Q1HmFrpd 35\u001b[0m stockBarRequest \u001b[39m=\u001b[39m StockBarsRequest(symbol_or_symbols\u001b[39m=\u001b[39;49m[\u001b[39m\"\u001b[39;49m\u001b[39mBAC\u001b[39;49m\u001b[39m\"\u001b[39;49m], start\u001b[39m=\u001b[39;49mtime_from,end\u001b[39m=\u001b[39;49mtime_to, timeframe\u001b[39m=\u001b[39;49m\u001b[39m\"\u001b[39;49m\u001b[39m15s\u001b[39;49m\u001b[39m\"\u001b[39;49m)\n\u001b[1;32m 37\u001b[0m \u001b[39m#zavolam na clientovi metodu s request objektem, vrací se mi Dict[str, Quote] - obj.Quote pro kazdy symbol\u001b[39;00m\n\u001b[1;32m 38\u001b[0m \u001b[39m#latestQuoteObject = stock_client.get_stock_latest_quote(latestQuoteRequest)\u001b[39;00m\n\u001b[1;32m 39\u001b[0m \u001b[39m#tradesResponse = stock_client.get_stock_trades(stockTradeRequest).df\u001b[39;00m\n\u001b[1;32m 40\u001b[0m stocksResponse \u001b[39m=\u001b[39m stock_client\u001b[39m.\u001b[39mget_stock_bars(stockBarRequest)\u001b[39m.\u001b[39mdf\n", + "File \u001b[0;32m~/Documents/Development/python/trading/.venv/lib/python3.11/site-packages/alpaca/data/requests.py:45\u001b[0m, in \u001b[0;36mBaseTimeseriesDataRequest.__init__\u001b[0;34m(self, **data)\u001b[0m\n\u001b[1;32m 37\u001b[0m \u001b[39mif\u001b[39;00m (\n\u001b[1;32m 38\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mend\u001b[39m\u001b[39m\"\u001b[39m \u001b[39min\u001b[39;00m data\n\u001b[1;32m 39\u001b[0m \u001b[39mand\u001b[39;00m data[\u001b[39m\"\u001b[39m\u001b[39mend\u001b[39m\u001b[39m\"\u001b[39m] \u001b[39mis\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39mNone\u001b[39;00m\n\u001b[1;32m 40\u001b[0m \u001b[39mand\u001b[39;00m \u001b[39misinstance\u001b[39m(data[\u001b[39m\"\u001b[39m\u001b[39mend\u001b[39m\u001b[39m\"\u001b[39m], datetime)\n\u001b[1;32m 41\u001b[0m \u001b[39mand\u001b[39;00m data[\u001b[39m\"\u001b[39m\u001b[39mend\u001b[39m\u001b[39m\"\u001b[39m]\u001b[39m.\u001b[39mtzinfo \u001b[39mis\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39mNone\u001b[39;00m\n\u001b[1;32m 42\u001b[0m ):\n\u001b[1;32m 43\u001b[0m data[\u001b[39m\"\u001b[39m\u001b[39mend\u001b[39m\u001b[39m\"\u001b[39m] \u001b[39m=\u001b[39m data[\u001b[39m\"\u001b[39m\u001b[39mend\u001b[39m\u001b[39m\"\u001b[39m]\u001b[39m.\u001b[39mastimezone(pytz\u001b[39m.\u001b[39mutc)\u001b[39m.\u001b[39mreplace(tzinfo\u001b[39m=\u001b[39m\u001b[39mNone\u001b[39;00m)\n\u001b[0;32m---> 45\u001b[0m \u001b[39msuper\u001b[39;49m()\u001b[39m.\u001b[39;49m\u001b[39m__init__\u001b[39;49m(\u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mdata)\n", + "File \u001b[0;32m~/Documents/Development/python/trading/.venv/lib/python3.11/site-packages/pydantic/main.py:342\u001b[0m, in \u001b[0;36mpydantic.main.BaseModel.__init__\u001b[0;34m()\u001b[0m\n", + "\u001b[0;31mValidationError\u001b[0m: 1 validation error for StockBarsRequest\ntimeframe\n instance of TimeFrame expected (type=type_error.arbitrary_type; expected_arbitrary_type=TimeFrame)" + ] + } + ], + "source": [ + "# 2 clients for historical data StockHistoricalDataClient (needs keys), CryptoHistoricalDataClient\n", + "# 2 clients for real time data CryptoDataStream, StockDataStream\n", + "\n", + "\n", + "# naimportuju si daneho clienta\n", + "from alpaca.data.historical import StockHistoricalDataClient, CryptoHistoricalDataClient\n", + "\n", + "#pokdu pouzivam historicke data(tzn. REST) tak si naimportuju dany request object\n", + "from alpaca.data.requests import StockLatestQuoteRequest, StockBarsRequest, StockTradesRequest\n", + "\n", + "#objekty se kterymi pak pracuju (jsou soucasi package výše, tady jen informačně)\n", + "from alpaca.data import Quote, Trade, Snapshot, Bar\n", + "from alpaca.data.models import BarSet, QuoteSet, TradeSet\n", + "\n", + "\n", + "from config import API_KEY, SECRET_KEY\n", + "import datetime\n", + "import pandas as pd\n", + "\n", + "# vytvorim si clienta\n", + "stock_client = StockHistoricalDataClient(API_KEY, SECRET_KEY, raw_data=False)\n", + "\n", + "sloupce=[\"symbol\",\"timestamp\",\"exchange\",\"price\",\"size\",\"id\",\"conditions\",\"tape\"]\n", + "\n", + "# deklarace globalniho df s timeindexem\n", + "#gdf = pd.DataFrame(columns=sloupce, index=pd.to_datetime([]))\n", + "\n", + "time_from = datetime.datetime(2023, 2, 17, 14, 50, 0, 0)\n", + "time_to = datetime.datetime(2023, 2, 17, 14, 55, 1, 0)\n", + "#print(time_from)\n", + "\n", + "# vytvorim request objekt\n", + "#latestQuoteRequest = StockLatestQuoteRequest(symbol_or_symbols=[\"SPY\", \"GLD\", \"TLT\"])\n", + "stockTradeRequest = StockTradesRequest(symbol_or_symbols=[\"BAC\"], start=time_from,end=time_to)\n", + "stockBarRequest = StockBarsRequest(symbol_or_symbols=[\"BAC\"], start=time_from,end=time_to, timeframe=\"15s\")\n", + "\n", + "#zavolam na clientovi metodu s request objektem, vrací se mi Dict[str, Quote] - obj.Quote pro kazdy symbol\n", + "#latestQuoteObject = stock_client.get_stock_latest_quote(latestQuoteRequest)\n", + "#tradesResponse = stock_client.get_stock_trades(stockTradeRequest).df\n", + "stocksResponse = stock_client.get_stock_bars(stockBarRequest).df\n", + "\n", + "#data = [{'t': '2023-02-17T14:50:00.582845696Z', 'x': 'D', 'p': 34.83, 's': 1, 'c': [' ', 'I'], 'i': 71675642337847, 'z': 'A'}, {'t': '2023-02-17T14:50:00.948229632Z', 'x': 'D', 'p': 34.8383, 's': 10, 'c': [' ', 'I'], 'i': 79371872323411, 'z': 'A'}]\n", + "# data = [{ 'conditions': [' ', 'I'],\n", + "# 'exchange': 'D',\n", + "# 'id': 71675642337847,\n", + "# 'price': 34.83,\n", + "# 'size': 1.0,\n", + "# 'symbol': 'BAC',\n", + "# 'tape': 'A',\n", + "# 'timestamp': datetime.datetime(2023, 2, 17, 14, 50, 0, 582845, tzinfo=datetime.timezone.utc)}, { 'conditions': [' ', 'I'],\n", + "# 'exchange': 'D',\n", + "# 'id': 79371872323411,\n", + "# 'price': 34.8383,\n", + "# 'size': 10.0,\n", + "# 'symbol': 'BAC',\n", + "# 'tape': 'A',\n", + "# 'timestamp': datetime.datetime(2023, 2, 17, 14, 50, 0, 948229, tzinfo=datetime.timezone.utc)}, { 'conditions': [' ', 'I'],\n", + "# 'exchange': 'D',\n", + "# 'id': 71675642400306,\n", + "# 'price': 34.835,\n", + "# 'size': 1.0,\n", + "# 'symbol': 'BAC',\n", + "# 'tape': 'A',\n", + "# 'timestamp': datetime.datetime(2023, 2, 17, 14, 50, 1, 870989, tzinfo=datetime.timezone.utc)}, { 'conditions': [' ', 'I'],\n", + "# 'exchange': 'D',\n", + "# 'id': 71675642400308,\n", + "# 'price': 34.84,\n", + "# 'size': 100.0,\n", + "# 'symbol': 'BAC',\n", + "# 'tape': 'A',\n", + "# 'timestamp': datetime.datetime(2023, 2, 17, 14, 55, 0, 88460, tzinfo=datetime.timezone.utc)}]\n", + "# datetime.datetime(2023, 2, 17, 14, 50, 0, 948229, tzinfo=datetime.timezone.utc)\n", + "#data = tradesResponse\n", + "\n", + "#gdf = pd.DataFrame.from_dict(data=data, orient='index')\n", + "#gdf = pd.DataFrame(data)\n", + "\n", + "#gdf = pd.DataFrame(tradesResponse.data[\"BAC\"])\n", + "\n", + "# works with raw data\n", + "#gdf = pd.DataFrame([t for t in tradesResponse[\"BAC\"]], columns=sloupce)\n", + "\n", + "#gdf = tradesResponse.df\n", + "print(stocksResponse)\n", + "# print(tradesResponse)\n", + "#print(tradesResponse[\"BAC\"])\n", + "# print(tradesResponse.data[\"BAC\"])\n", + "\n", + "# positions_df = pd.concat((pd.DataFrame(position).set_index(0) for position in positions),axis=1)\n", + "# positions_df = positions_df.T.apply(pd.to_numeric, errors='ignore').T # convert strings to numeric\n", + "# For orders:\n", + "# orders_df = pd.concat((pd.DataFrame(order).set_index(0) for order in orders),axis=1).T\n" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": ".venv", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.10" + }, + "orig_nbformat": 4, + "vscode": { + "interpreter": { + "hash": "9391835cf7167c62e8e53032533e4da7e63c83f818ef5f19912128bc45706236" + } + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/testy/archive/test.py b/testy/archive/test.py new file mode 100644 index 0000000..44c929c --- /dev/null +++ b/testy/archive/test.py @@ -0,0 +1,66 @@ +from alpaca.data.live import StockDataStream +from alpaca.common.enums import BaseURL +import datetime +import pandas as pd +from alpaca.data.models import Bar, Quote, Trade +import csv +from config import API_KEY, SECRET_KEY + +key = 'PKHVMXQA09IVXALL92JR' +secret = 'FmPwQRFIl7jhLRrXee0Ui73zM9NmAf5O4VH2tyAf' + +# keys required for stock historical data client +#client = StockHistoricalDataClient(key, secret) + +# keys required +client = StockDataStream(api_key=API_KEY,secret_key=SECRET_KEY) + +df_glob = pd.DataFrame(columns=['timestamp','symbol', 'exchange','size','price','id','conditions','tape']) + +file = open('Trades.txt', 'w') + +# async handler +async def quote_data_handler(data): + #global df_glob + #f_loc = pd.DataFrame(data) + #df_glob = df_glob.append(df_loc, ignore_index=True) + # quote data will arrive here + print(data) + ne = str(data) + "\n" + file.write(ne) + #print(data.timestamp,data.symbol, data.price, data.size, data.exchange, data.id, data.conditios,tape) + print("-"*40) + +#client.subscribe_updated_bars(quote_data_handler, "BAC") +#client.subscribe_quotes(quote_data_handler, "BAC") +client.subscribe_trades(quote_data_handler, "BAC") + +print("pred spustenim run") +try: + client.run() + #print(df) +except Exception as err: + print(f"{type(err).__name__} was raised: {err}") + print("globalni dataframe") + print(df_glob) + file.close() + +print(df_glob) + +# timestamp symbol exchange size price id conditions tape 0 1 +# 0 NaN NaN NaN NaN NaN NaN NaN NaN symbol BAC +# 1 NaN NaN NaN NaN NaN NaN NaN NaN timestamp 2023-02-15 19:47:19.430511+00:00 +# 2 NaN NaN NaN NaN NaN NaN NaN NaN exchange V +# 3 NaN NaN NaN NaN NaN NaN NaN NaN price 35.52 +# 4 NaN NaN NaN NaN NaN NaN NaN NaN size 50.0 +# .. ... ... ... ... ... ... ... ... ... ... +# 59 NaN NaN NaN NaN NaN NaN NaN NaN price 35.51 +# 60 NaN NaN NaN NaN NaN NaN NaN NaN size 7.0 +# 61 NaN NaN NaN NaN NaN NaN NaN NaN id 56493486924086 +# 62 NaN NaN NaN NaN NaN NaN NaN NaN conditions [ , I] +# 63 NaN NaN NaN NaN NaN NaN NaN NaN tape A + + order_data_json = request.get_json() + + # validate data + MarketOrderRequest(**order_data_json) \ No newline at end of file diff --git a/testy/archive/testqueue.py b/testy/archive/testqueue.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/testy/archive/testqueue.py @@ -0,0 +1 @@ + diff --git a/testy/archive/threadcondition.py b/testy/archive/threadcondition.py new file mode 100644 index 0000000..27b4705 --- /dev/null +++ b/testy/archive/threadcondition.py @@ -0,0 +1,35 @@ +# A condition variable allows one or more threads to wait until they are +# notified by another thread. + +import threading +import time +import logging + +logging.basicConfig(level=logging.DEBUG, + format='(%(threadName)-9s) %(message)s',) + +def consumer(cv): + logging.debug('Consumer thread started ...') + with cv: + logging.debug('Consumer waiting ...') + cv.wait() + logging.debug('Consumer consumed the resource') + +def producer(cv): + logging.debug('Producer thread started ...') + with cv: + logging.debug('Making resource available') + logging.debug('Notifying to all consumers') + cv.notify_all() + +if __name__ == '__main__': + condition = threading.Condition() + cs1 = threading.Thread(name='consumer1', target=consumer, args=(condition,)) + cs2 = threading.Thread(name='consumer2', target=consumer, args=(condition,)) + pd = threading.Thread(name='producer', target=producer, args=(condition,)) + + cs1.start() + time.sleep(2) + cs2.start() + time.sleep(2) + pd.start() \ No newline at end of file diff --git a/testy/archive/thready.py b/testy/archive/thready.py new file mode 100644 index 0000000..df5ecac --- /dev/null +++ b/testy/archive/thready.py @@ -0,0 +1,54 @@ +# pouziti threadu - narozdil od asyncio - nemame pod tim uplnou kontrolu a ridi to knihovna +# thready jsou výhodne pro naročné IO operace, např. loadery, requestory, scrapery, ukladače atp. +# how to share data between Threads +# 1.Sharing a boolean variable with a threading.Event. + # declare in unset or false state + # event = threading.Event() + # if event.is_set(): # check if set + # event.set() # set the event true + # event.clear() # or false + +# 2.Protecting global shared data with a threading.Lock. + # lock = threading.Lock() + # with lock: + # variable = variable + 10 + +# 3.Sharing data with a queue.Queue. Queue can be shared between threads. + # create a queue + # queue = Queue() #create FIFO + # queue.put(i) #enque + # data = queue.get() #dequeue + +# dale je tu condition - takova roura mezi consumerem a producerem + # cond = threading.Condition() + # cond.wait() #consumer waiting + # cond.notifyAll() #producer notifiying consumer, they can continue + # consumer threads wait for the Condition to be set before continuing. + # The producer thread is responsible for setting the condition and notifying the other threads + # that they can continue. Více v sam.test filu. + + +import threading + +def do_first(): + print("Running do_first line 1") + print("Running do_first line 2") + print("Running do_first line 3") + +def do_second(): + print("Running do_second line 1") + print("Running do_second line 2") + print("Running do_second line 3") + +def main(): + t1 = threading.Thread(target=do_first) + t2 = threading.Thread(target=do_second) + + # Start threads + t1.start(), t2.start() + + # Wait threads to complete + t1.join(), t2.join() + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/testy/changeiterable (kopie).py b/testy/changeiterable (kopie).py new file mode 100644 index 0000000..8ec9b26 --- /dev/null +++ b/testy/changeiterable (kopie).py @@ -0,0 +1,74 @@ +from uuid import UUID, uuid4 +from alpaca.trading.enums import OrderSide, OrderStatus, TradeEvent, OrderClass, OrderType, TimeInForce +#from utils import AttributeDict +from rich import print +from typing import Any, Optional, List, Union +from datetime import datetime, date +from pydantic import BaseModel +from common.model import Order +# to test change iterable (adding items) while iterating +import asyncio + +class Notif: + def __init__(self,time): + self.time = time + +open_orders: list = [] + +for i in range(1,10): + open_orders.append(Order(id=uuid4(), + submitted_at = datetime.utcnow(), + qty=1, + order_type=OrderType.MARKET, + symbol = "BAC", + status = OrderStatus.ACCEPTED, + side = OrderSide.BUY)) + +print("cele pole objektu",open_orders) + +# Here, 'reversed' returns a lazy iterator, so it's performant! reversed(l): + +#musi fungovat removing stare a pridavani novych + +#this list contains all not processed notification, that we try to process during this iteration +#if time is not right we leave the message for next iter +#if time is right we process the message (- note it can trigger additional open_orders, that are added to queue) + +async def apenduj(): + global open_orders + open_orders.append("cago") + # if notif.time % 2 == 0 and notif.time < 300: + # open_orders.append(Notif(notif.time+50)) + +todel = [] +for i in open_orders: + #print("*******start iterace polozky", i.time) + print(i) + print("removing element",i) + res = asyncio.run(apenduj()) + todel.append(i) + print("*****konec iterace", i) + print() + +print("to del", todel) +#removing processed from the list +for i in todel: + open_orders.remove(i) + + +print("cely list po skonceni vseho") +for i in open_orders: print(i.id) + + + +"""" +pred iteraci se zavola synchroné +EXECUTE open orders(time) + - pokusi se vytvorit vsechny otevrene ordery do daneho casu (casu dalsi iterace) + - podporuje i volani callbacku a to vcetne pokynu vytvoreneho z pokynu + - tento novy pokyn muze byt i take exekuovan pokud se vcetne roundtripu vejde do daneho casu + pripadne soucasne vytvoreni i exekuci pokynu + + +""" + diff --git a/testy/changeiterable.py b/testy/changeiterable.py new file mode 100644 index 0000000..6bfb695 --- /dev/null +++ b/testy/changeiterable.py @@ -0,0 +1,70 @@ +from uuid import UUID, uuid4 +from alpaca.trading.enums import OrderSide, OrderStatus, TradeEvent, OrderClass, OrderType, TimeInForce +#from utils import AttributeDict +from rich import print +from typing import Any, Optional, List, Union +from datetime import datetime, date +from pydantic import BaseModel +from common.model import Order +# to test change iterable (adding items) while iterating + +class Notif: + def __init__(self,time): + self.time = time + +open_orders: list(Order) = [] + +for i in range(1,10): + open_orders.append(Order(id=uuid4()), + submitted_at = datetime.utcnow(), + symbol = "BAC", + status = OrderStatus.ACCEPTED, + side = OrderSide.BUY) + +print("cele pole objektu",open_orders) + +# Here, 'reversed' returns a lazy iterator, so it's performant! reversed(l): + +#musi fungovat removing stare a pridavani novych + +#this list contains all not processed notification, that we try to process during this iteration +#if time is not right we leave the message for next iter +#if time is right we process the message (- note it can trigger additional open_orders, that are added to queue) + +def process_message(notif: Notif): + global open_orders + pass + # if notif.time % 2 == 0 and notif.time < 300: + # open_orders.append(Notif(notif.time+50)) + +todel = [] +for i in open_orders: + #print("*******start iterace polozky", i.time) + process_message(i.id) + print("removing element",i.id) + todel.append(i) + print("*****konec iterace", i.id) + print() + +print("to del", todel) +#removing processed from the list +for i in todel: + open_orders.remove(i) + + +print("cely list po skonceni vseho") +for i in open_orders: print(i.id) + + + +"""" +pred iteraci se zavola synchroné +EXECUTE open orders(time) + - pokusi se vytvorit vsechny otevrene ordery do daneho casu (casu dalsi iterace) + - podporuje i volani callbacku a to vcetne pokynu vytvoreneho z pokynu + - tento novy pokyn muze byt i take exekuovan pokud se vcetne roundtripu vejde do daneho casu + pripadne soucasne vytvoreni i exekuci pokynu + + +""" + diff --git a/testy/dash_backtest_results.py b/testy/dash_backtest_results.py new file mode 100644 index 0000000..6ee5ce7 --- /dev/null +++ b/testy/dash_backtest_results.py @@ -0,0 +1,9915 @@ +import os,sys +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +import dash +import pandas as pd +import dash_bootstrap_components as dbc +from dash.dependencies import Input, Output +from dash import dcc, html, dash_table +from uuid import UUID, uuid4 +from alpaca.trading.enums import OrderSide, OrderStatus, TradeEvent, OrderType +from common.model import TradeUpdate, Order +from rich import print +import threading +import asyncio +from config import BT_DELAYS +from utils.utils import AttributeDict, ltp, zoneNY, trunc, count_decimals +from utils.tlog import tlog +from datetime import datetime +import pandas as pd +import matplotlib.pyplot as plt +import seaborn; seaborn.set() +import mplfinance as mpf +import plotly.graph_objects as go +from plotly.subplots import make_subplots +import numpy as np +from bisect import bisect_left +from backtesting.backtester import Backtester +from uuid import UUID +import datetime +from html.parser import HTMLParser +import requests + + +###html saver +def patch_file(file_path: str, content: bytes, extra: dict = None) -> bytes: + if file_path == 'index.html': + index_html_content = content.decode('utf8') + extra_jsons = f''' + var patched_jsons_content={{ + {','.join(["'/" + k + "':" + v.decode("utf8") + "" for k, v in extra.items()])} + }}; + ''' + patched_content = index_html_content.replace( + '