forked from 51bitquant/howtrader
-
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.
- Loading branch information
1 parent
78c845d
commit 591b77d
Showing
1 changed file
with
65 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,65 @@ | ||
|
||
from time import sleep | ||
from logging import INFO | ||
|
||
from howtrader.event import EventEngine | ||
from howtrader.trader.setting import SETTINGS | ||
from howtrader.trader.engine import MainEngine, LogEngine | ||
|
||
from howtrader.gateway.binance import BinanceSpotGateway, BinanceUsdtGateway | ||
from howtrader.gateway.okx import OkxGateway | ||
from howtrader.app.cta_strategy import CtaStrategyApp, CtaEngine | ||
from howtrader.app.cta_strategy.base import EVENT_CTA_LOG | ||
|
||
|
||
SETTINGS["log.active"] = True | ||
SETTINGS["log.level"] = INFO | ||
SETTINGS["log.console"] = True | ||
|
||
okx_gateway_setting = { | ||
"key": "", | ||
"secret": "", | ||
"passphrase": "", | ||
"proxy_host": "", | ||
"proxy_port": 0, | ||
"server": "REAL" | ||
} | ||
|
||
|
||
def run(): | ||
""" | ||
Running in the child process. | ||
""" | ||
SETTINGS["log.file"] = True | ||
|
||
event_engine = EventEngine() | ||
main_engine: MainEngine = MainEngine(event_engine) | ||
main_engine.add_gateway(OkxGateway) | ||
cta_engine: CtaEngine = main_engine.add_app(CtaStrategyApp) | ||
main_engine.write_log("setup main engine") | ||
|
||
log_engine: LogEngine = main_engine.get_engine("log") | ||
event_engine.register(EVENT_CTA_LOG, log_engine.process_log_event) | ||
main_engine.write_log("register event listener") | ||
|
||
main_engine.connect(okx_gateway_setting, "OKX") | ||
main_engine.write_log("connect OKX gateway") | ||
|
||
sleep(10) | ||
|
||
cta_engine.init_engine() | ||
main_engine.write_log("set up cta engine") | ||
|
||
cta_engine.init_all_strategies() | ||
sleep(60) # Leave enough time to complete strategy initialization | ||
main_engine.write_log("init cta strategies") | ||
|
||
cta_engine.start_all_strategies() | ||
main_engine.write_log("start cta strategies") | ||
|
||
while True: | ||
sleep(10) | ||
|
||
|
||
if __name__ == "__main__": | ||
run() |