diff --git a/tests/trader/run.py b/tests/trader/run.py index 130aa088..58a7d4a8 100644 --- a/tests/trader/run.py +++ b/tests/trader/run.py @@ -3,12 +3,12 @@ from vnpy.event import EventEngine from vnpy.trader.engine import MainEngine from vnpy.trader.ui import MainWindow, create_qapp -from vnpy.gateway.binance import BinanceGateway +# from vnpy.gateway.binance import BinanceGateway # 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.ctptest import CtptestGateway # from vnpy.gateway.femas import FemasGateway # from vnpy.gateway.tiger import TigerGateway # from vnpy.gateway.oes import OesGateway @@ -36,10 +36,10 @@ def main(): main_engine = MainEngine(event_engine) - main_engine.add_gateway(BinanceGateway) + # main_engine.add_gateway(BinanceGateway) # main_engine.add_gateway(XtpGateway) # main_engine.add_gateway(CtpGateway) - # main_engine.add_gateway(CtptestGateway) + main_engine.add_gateway(CtptestGateway) # main_engine.add_gateway(FemasGateway) # main_engine.add_gateway(IbGateway) # main_engine.add_gateway(FutuGateway) diff --git a/vnpy/gateway/ctp/ctp_gateway.py b/vnpy/gateway/ctp/ctp_gateway.py index 78255313..6512c41e 100644 --- a/vnpy/gateway/ctp/ctp_gateway.py +++ b/vnpy/gateway/ctp/ctp_gateway.py @@ -294,6 +294,7 @@ class CtpMdApi(MdApi): datetime=datetime.strptime(timestamp, "%Y%m%d %H:%M:%S.%f"), name=symbol_name_map[symbol], volume=data["Volume"], + open_interest=data["OpenInterest"], last_price=data["LastPrice"], limit_up=data["UpperLimitPrice"], limit_down=data["LowerLimitPrice"], diff --git a/vnpy/trader/object.py b/vnpy/trader/object.py index 952c0360..ca7f7e0e 100644 --- a/vnpy/trader/object.py +++ b/vnpy/trader/object.py @@ -36,6 +36,7 @@ class TickData(BaseData): name: str = "" volume: float = 0 + open_interest: float = 0 last_price: float = 0 last_volume: float = 0 limit_up: float = 0 @@ -87,6 +88,7 @@ class BarData(BaseData): interval: Interval = None volume: float = 0 + open_interest: float = 0 open_price: float = 0 high_price: float = 0 low_price: float = 0 diff --git a/vnpy/trader/utility.py b/vnpy/trader/utility.py index 1843b31f..a154e175 100644 --- a/vnpy/trader/utility.py +++ b/vnpy/trader/utility.py @@ -177,11 +177,13 @@ class BarGenerator: high_price=tick.last_price, low_price=tick.last_price, close_price=tick.last_price, + open_interest=tick.open_interest ) else: self.bar.high_price = max(self.bar.high_price, tick.last_price) self.bar.low_price = min(self.bar.low_price, tick.last_price) self.bar.close_price = tick.last_price + self.bar.open_interest = tick.open_interest self.bar.datetime = tick.datetime if self.last_tick: @@ -221,6 +223,7 @@ class BarGenerator: # Update close price/volume into window bar self.window_bar.close_price = bar.close_price self.window_bar.volume += int(bar.volume) + self.window_bar.open_interest = bar.open_interest # Check if window bar completed finished = False