vn.py量化社区
By Traders, For Traders.
Member
avatar
加入于:
帖子: 3
声望: 1

是该品种的当日所有成交金额,非个人成交回报

Member
avatar
加入于:
帖子: 8
声望: 1

你直接在on_trade中获取然后传入公共变量就行

Member
avatar
加入于:
帖子: 3
声望: 1

CTP行情接口中的Turnover

Member
avatar
加入于:
帖子: 3
声望: 1

自己动手。。。
修改3个地方:
1、ctp_gateway.py
def onRtnDepthMarketData(self, data: dict):
"""
Callback of tick data update.
"""
symbol = data["InstrumentID"]
exchange = symbol_exchange_map.get(symbol, "")
if not exchange:
return

    timestamp = f"{data['ActionDay']} {data['UpdateTime']}.{int(data['UpdateMillisec']/100)}"

    tick = TickData(
        symbol=symbol,
        exchange=exchange,
        datetime=datetime.strptime(timestamp, "%Y%m%d %H:%M:%S.%f"),
        name=symbol_name_map[symbol],
        volume=data["Volume"],
       Turnover=data["Turnover"], #增加
        open_interest=data["OpenInterest"],
        last_price=data["LastPrice"],
        limit_up=data["UpperLimitPrice"],
        limit_down=data["LowerLimitPrice"],
        open_price=data["OpenPrice"],
        high_price=data["HighestPrice"],
        low_price=data["LowestPrice"],
        pre_close=data["PreClosePrice"],
        bid_price_1=data["BidPrice1"],
        ask_price_1=data["AskPrice1"],
        bid_volume_1=data["BidVolume1"],
        ask_volume_1=data["AskVolume1"],
        gateway_name=self.gateway_name
    )
    self.gateway.on_tick(tick) 

2、object.py
class TickData(BaseData):
"""
Tick data contains information about:

    * last trade in market
    * orderbook snapshot
    * intraday market statistics.
"""

symbol: str
exchange: Exchange
datetime: datetime

name: str = ""
volume: float = 0
Turnover: float = 0  ##增加
open_interest: float = 0
last_price: float = 0
last_volume: float = 0
limit_up: float = 0

3、database_sql.py
class DbTickData(ModelBase):
"""
Tick data for database storage.

    Index is defined unique with (datetime, symbol)
    """

    id = AutoField()

    symbol: str = CharField()
    exchange: str = CharField()
    datetime: datetime = DateTimeField()

    name: str = CharField()
    volume: float = FloatField()
    Turnover: float = FloatField()  ##增加
    open_interest: float = FloatField()
    last_price: float = FloatField()
    last_volume: float = FloatField()

.......
def from_tick(tick: TickData):
"""
Generate DbTickData object from TickData.
"""
db_tick = DbTickData()

        db_tick.symbol = tick.symbol
        db_tick.exchange = tick.exchange.value
        db_tick.datetime = tick.datetime
        db_tick.name = tick.name
        db_tick.volume = tick.volume
        db_tick.Turnover = tick.Turnover ##增加
        db_tick.open_interest = tick.open_interest
        db_tick.last_price = tick.last_price
        db_tick.last_volume = tick.last_volume
        db_tick.limit_up = tick.limit_up

.....
def to_tick(self):
"""
Generate TickData object from DbTickData.
"""
tick = TickData(
symbol=self.symbol,
exchange=Exchange(self.exchange),
datetime=self.datetime,
name=self.name,
volume=self.volume,
Turnover=self.Turnover, ##增加
open_interest=self.open_interest,
last_price=self.last_price,
last_volume=self.last_volume,
4、删除原来保存的tick数据库 database.db

5、重新启动vnpy后,tick中已获得Turnover
.

© 2015-2019 上海韦纳软件科技有限公司
备案服务号:沪ICP备18006526号-3