diff --git a/example.db b/example.db index ba8d1ba..ece04f1 100644 Binary files a/example.db and b/example.db differ diff --git a/sfgrid.py b/sfgrid.py index 9370acf..e47ffd7 100644 --- a/sfgrid.py +++ b/sfgrid.py @@ -4,7 +4,7 @@ import time, sys sys.stdout.reconfigure(encoding='utf-8') # 设置标准输出编码为UTF-8 import strategy_db from trade_thread import StockTradeThread -from util import getInstrumentName +from util import getInstrumentName, interact from xtquant.xttrader import XtQuantTrader from xtquant.xttype import StockAccount @@ -93,10 +93,6 @@ class SFGridController: else: print("\n当前无委托记录") - def interact(self): - """执行后进入repl模式""" - import code - code.InteractiveConsole(locals=globals()).interact() def init_stock_trade_threads(self): for stock_code in self.instrument_pool: @@ -104,8 +100,10 @@ class SFGridController: new_job.name = f"StockTradeThread-{stock_code}" new_job.start() - def stock_trade_thread(self, stock_code): - print(f"启动标的交易线程 {stock_code} {getInstrumentName(stock_code)}\n") + def start_stock_trade_thread(self, stock: strategy_db.TradeTarget): + stock.name = f"StockTradeThread-{stock.stock_code}" + stock.start() + print(f"启动标的交易线程 {stock.stock_code} {getInstrumentName(stock.stock_code)}\n") threading.Event().wait(2) # 模拟交易操作的等待时间 @@ -117,6 +115,6 @@ if __name__ == '__main__': ctrl.init_stock_trade_threads() # 交互阻塞 - ctrl.interact() + interact() diff --git a/strategy_db.py b/strategy_db.py index 08d84db..dd9930b 100644 --- a/strategy_db.py +++ b/strategy_db.py @@ -1,4 +1,4 @@ -from peewee import SqliteDatabase, Model, CharField, IntegerField, FloatField +from peewee import SqliteDatabase, Model, CharField, IntegerField, FloatField, BooleanField # 连接到SQLite数据库 db = SqliteDatabase('example.db') @@ -17,4 +17,5 @@ class TradeTarget(BaseModel): last_trade_price = FloatField() current_buy_price = FloatField() current_sell_price = FloatField() - status = IntegerField(default=1) # 1表示启用,0表示停止 \ No newline at end of file + status = IntegerField(default=0) # 1表示启用,0表示停止 + enabled = BooleanField(default=False) # 是否启用该标的 \ No newline at end of file diff --git a/util.py b/util.py index 9d6a238..dd475c0 100644 --- a/util.py +++ b/util.py @@ -15,4 +15,10 @@ def getStockPosition(stock_code: str, xt_trader: xttrader.XtQuantTrader, account if pos.stock_code == stock_code: volume = pos.m_nVolume break - return volume \ No newline at end of file + return volume + + +def interact(): + """执行后进入repl模式""" + import code + code.InteractiveConsole(locals=globals()).interact() \ No newline at end of file