diff --git a/examples/vn_trader/run.py b/examples/vn_trader/run.py index 58a7d4a8..fb06ef2a 100644 --- a/examples/vn_trader/run.py +++ b/examples/vn_trader/run.py @@ -7,8 +7,8 @@ from vnpy.trader.ui import MainWindow, create_qapp # from vnpy.gateway.bitmex import BitmexGateway # from vnpy.gateway.futu import FutuGateway # from vnpy.gateway.ib import IbGateway -# from vnpy.gateway.ctp import CtpGateway -from vnpy.gateway.ctptest import CtptestGateway +from vnpy.gateway.ctp import CtpGateway +# from vnpy.gateway.ctptest import CtptestGateway # from vnpy.gateway.femas import FemasGateway # from vnpy.gateway.tiger import TigerGateway # from vnpy.gateway.oes import OesGateway @@ -22,7 +22,7 @@ from vnpy.gateway.ctptest import CtptestGateway # from vnpy.app.cta_strategy import CtaStrategyApp # from vnpy.app.csv_loader import CsvLoaderApp -# from vnpy.app.algo_trading import AlgoTradingApp +from vnpy.app.algo_trading import AlgoTradingApp # from vnpy.app.cta_backtester import CtaBacktesterApp # from vnpy.app.data_recorder import DataRecorderApp # from vnpy.app.risk_manager import RiskManagerApp @@ -38,8 +38,8 @@ def main(): # main_engine.add_gateway(BinanceGateway) # main_engine.add_gateway(XtpGateway) - # main_engine.add_gateway(CtpGateway) - main_engine.add_gateway(CtptestGateway) + main_engine.add_gateway(CtpGateway) + # main_engine.add_gateway(CtptestGateway) # main_engine.add_gateway(FemasGateway) # main_engine.add_gateway(IbGateway) # main_engine.add_gateway(FutuGateway) @@ -56,7 +56,7 @@ def main(): # main_engine.add_app(CtaStrategyApp) # main_engine.add_app(CtaBacktesterApp) # main_engine.add_app(CsvLoaderApp) - # main_engine.add_app(AlgoTradingApp) + main_engine.add_app(AlgoTradingApp) # main_engine.add_app(DataRecorderApp) # main_engine.add_app(RiskManagerApp) diff --git a/vnpy/app/algo_trading/algos/grid_algo.py b/vnpy/app/algo_trading/algos/grid_algo.py index 914def91..9c140a08 100644 --- a/vnpy/app/algo_trading/algos/grid_algo.py +++ b/vnpy/app/algo_trading/algos/grid_algo.py @@ -20,7 +20,7 @@ class GridAlgo(AlgoTemplate): } variables = [ - "last_pos", + "last_pos", "timer_count", "vt_orderid", "traded", @@ -59,7 +59,7 @@ class GridAlgo(AlgoTemplate): def on_tick(self, tick: TickData): """""" self.last_tick = tick - + def on_timer(self): """""" if not self.last_tick: @@ -68,15 +68,17 @@ class GridAlgo(AlgoTemplate): self.timer_count += 1 if self.timer_count < self.interval: self.put_variables_event() - return + return self.timer_count = 0 - + if self.vt_orderid: - self.cancel_all() + self.cancel_all() # Calculate target volume to buy - target_buy_distance = (self.price - self.last_tick.ask_price_1) / self.step_price - target_buy_position = math.floor(target_buy_distance) * self.step_volume + target_buy_distance = ( + self.price - self.last_tick.ask_price_1) / self.step_price + target_buy_position = math.floor( + target_buy_distance) * self.step_volume target_buy_volume = target_buy_position - self.last_pos # Buy when price dropping @@ -86,10 +88,12 @@ class GridAlgo(AlgoTemplate): self.last_tick.ask_price_1, min(target_buy_volume, self.last_tick.ask_volume_1) ) - + # Calculate target volume to sell - target_sell_distance = (self.price - self.last_tick.bid_price_1) / self.step_price - target_sell_position = math.ceil(target_sell_distance) * self.step_volume + target_sell_distance = ( + self.price - self.last_tick.bid_price_1) / self.step_price + target_sell_position = math.ceil( + target_sell_distance) * self.step_volume target_sell_volume = self.last_pos - target_sell_position # Sell when price rising @@ -117,7 +121,7 @@ class GridAlgo(AlgoTemplate): self.stop() else: self.put_variables_event() - + def update_last_pos(self, pos, trade: TradeData): """""" if trade.direction == Direction.LONG: diff --git a/vnpy/app/algo_trading/ui/display.py b/vnpy/app/algo_trading/ui/display.py index 4f7b9502..5bbbe2e5 100644 --- a/vnpy/app/algo_trading/ui/display.py +++ b/vnpy/app/algo_trading/ui/display.py @@ -12,5 +12,16 @@ NAME_DISPLAY_MAP = { "timer_count": "本轮读秒", "total_count": "累计读秒", "template_name": "算法模板", - "display_volume": "挂出数量" + "display_volume": "挂出数量", + "stop_price": "触发价格", + "price_add": "委托超价", + "trade_count": "交易次数限制", + "step_price": "网格交易间距", + "step_volume": "网格交易数量", + "order_type": "类型", + "active_vt_symbol": "主动腿", + "passive_vt_symbol": "被动腿", + "spread_up": "价差上限", + "spread_down": "价差下限", + "max_pos": "最大持仓" }