DolphinDB:createAsofJoinEngine函数无法从右表获取数据

问题描述 投票:0回答:1

Asof Join Engine无法从metrics指定的右表获取列数据,但从左表获取数据成功。我的脚本中的指标是 <[LogDateTime, TRANSACTION_SR401.LogDateTime, InstrumentID, Cont, LastPrice, MatchPrice]>。 “Cont”和“MatchPrice”来自右表,其大小写与输入表一致。

以下是我的 DolphinDB 脚本:

share streamTable(1:0, `InstrumentID`TradeDateTime`LimitUpPrice`LimitDownPrice`PreSettlePrice`SettlePrice`LastPrice`Volume`OpenInterest`PreOpenInterest`OpenPrice`HighPrice`LowPrice`Amount`BidPrice`BidVol`AskPrice`AskVol`LogDateTime, [SYMBOL,TIMESTAMP,DOUBLE,DOUBLE,DOUBLE,DOUBLE,DOUBLE,INT,INT,INT,DOUBLE,DOUBLE,DOUBLE,DOUBLE,DOUBLE,INT,DOUBLE,INT,TIMESTAMP]) as EXCHANGE_SR401;

share streamTable(1:0, `UserNo`Sign`Cont`Direct`Offset`Hedge`OrderNo`MatchPrice`MatchQty`FeeCurrency`MatchFee`CoverProfit`MatchDateTime`AddOne`Deleted`MatchNo`UnderlyingID`LogDateTime, [INT,SYMBOL,SYMBOL,STRING,STRING,STRING,STRING,DOUBLE,INT,STRING,DOUBLE,DOUBLE,TIMESTAMP,STRING,STRING,STRING,SYMBOL,TIMESTAMP]) as TRANSACTION_SR401;

share streamTable(1:0, `Timestamp_result`Join_key`timestamp_future`timestamp_option`InstrumentID_future`InstrumentID_option`price_future`price_option, [TIMESTAMP,SYMBOL,TIMESTAMP,TIMESTAMP,SYMBOL,SYMBOL,DOUBLE,DOUBLE]) as PREV_MATCH_SR401;

createAsofJoinEngine(
        name=`aj1,
    leftTable=EXCHANGE_SR401,
    rightTable=TRANSACTION_SR401,
    outputTable=PREV_MATCH_SR401,
    metrics=<[LogDateTime,TRANSACTION_SR401.LogDateTime,InstrumentID,Cont,LastPrice,MatchPrice]>,
    matchingColumn=[[`InstrumentID],[`UnderlyingID]],
    timeColumn=`LogDateTime,
    useSystemTime=false
);

subscribeTable(
        tableName="EXCHANGE_SR401",
    actionName="joinLeft",
    offset=0,
    handler=appendForJoin{`aj1,true},
    msgAsTable=true,
    reconnect=true
);

subscribeTable(                                                           
    tableName="TRANSACTION_SR401",
    actionName="joinRight",
    offset=0,
    handler=appendForJoin{`aj1,false},
    msgAsTable=true,
    reconnect=true
);

以下是我用Python写的示例数据:

_exchange_record = {
        'InstrumentID': 'ZCE|F|SR|401', 
       'TradeDateTime': pd.Timestamp(2023,11,28,21,0,0,250000), 
       'LimitUpPrice': 1, 
       'LimitDownPrice': 1, 
       'PreSettlePrice': 1, 
        'SettlePrice': 1, 
        'LastPrice': 1, 
        'Volume': 1, 
        'OpenInterest': 1, 
        'PreOpenInterest': 1,
        'OpenPrice': 1, 
        'HighPrice': 1, 
        'LowPrice': 1, 
        'Amount': 1, 
        'BidPrice': 1, 
        'BidVol': 1, 
        'AskPrice': 1, 
        'AskVol': 1,
        'LogDateTime': pd.Timestamp(2023,11,28,21,0,0,290000)
    }
    _transaction_record = {
        "UserNo":'000001',
        "Sign": '#/ntjiw/.d',
        "Cont": 'ZCE|O|SR|401C6700',
        "Direct": 'S',
        "Offset": 'O',
        "Hedge": 'T',
        "OrderNo": '202311282100250000',
        "MatchPrice": 2,
        "MatchQty": 2,
        "FeeCurrency": 'CNY' ,
        "MatchFee": 3.1,
        "CoverProfit": 62,
        "MatchDateTime": pd.Timestamp(2023,11,28,21,0,0), 
        "AddOne": '' ,
        "Deleted": '' ,
        "MatchNo": '2023112821005700',
        "UnderlyingID": 'ZCE|F|SR|401', 
        'LogDateTime': pd.Timestamp(2023,11,28,21,0,0,291000)
    }
join streaming dolphindb
1个回答
0
投票

Asof 连接引擎将每个左表记录与时间戳之前的最新右表记录连接起来。在您的脚本中,由于未指定参数delayedTime,当右记录到达时时间戳大于或等于最新左记录的时间戳时,会触发连接操作。但是,由于示例中只有 2 条记录,左表记录无法与具有较早时间戳的任何右表记录匹配。通过添加更多示例,例如将“2023,11,28,21,0,0,280000”添加到“TRANSACTION_SR401.LogDateTime”,您会发现脚本中asof连接引擎的定义是正确的。

© www.soinside.com 2019 - 2024. All rights reserved.