Giter VIP home page Giter VIP logo

tx's Introduction

Tx

Tx is a strategy trading platform based on kdb+, specifically tailored for China's stock and futures markets.

tx's People

Contributors

craycn avatar itfin avatar wbcpeter3000 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tx's Issues

wlog type error on ftbt .z.wc

Tx/core/base.q

Line 79 in 450c243

wlog:{[x;y;z]if[(`int$`.enum.loglevels$x)>`int$`.enum.loglevels$.conf.loglevel;:()];z:$[10h=type z;z;-3!z];.db.LOG,:(x;y;z;now[]);pub[`syslog;enlist `sym`typ`msg!(x;y;z)];};

.db.LOGlogtimetimestamp 类型。 core/base.q 中的 now[] 也返回
timestamp. 但是, feed/backtest/ftbacktest.q 中的 now[] 返回的是 time
类型。 至少默认值是 0Nt:

.ctrl[`btdate`bttime]:(0Nd;0Nt);
now:{.ctrl`bttime};ntd:{.ctrl`btdate};

ftbt 中的 .z.wc 查询会触发这个 type error .

也许可以这样:

wlog:{[x;y;z]if[(`int$`.enum.loglevels$x)>`int$`.enum.loglevels$.conf.loglevel;:()];z:$[10h=type z;z;-3!z];.db.LOG,:(x;y;z;$[null n:now[];0Np;`timestamp$n]);pub[`syslog;enlist `sym`typ`msg!(x;y;z)];};

$[null n:now[];0Np;`timestamp$n]

代替 now[].

计算lv2时应考虑平衡状态

记录一个目前可能存在的问题,短期来看也没有快速的解决方案,于是先放在这里。

对于使用l2match和l2order来合成订单簿并通过gbbo函数获取最优价格的情况,需要考虑目前订单簿是否处于“平衡状态”。

在深交所的场景下,可能会出现已经收到一笔订单(l2order)且这笔订单一定成交,但是成交回报(l2match)还未推送过来。在这种情况下,订单簿处于"非平衡状态",此时调用gbbo函数可能会存在一定的误差。

A potential issue with the upd.Trade function in fectp.q

Based on "CTP客户端开发指南V3.5-中文":

在综合交易平台和交易所中,每笔报单都有 3 组唯一序列号,保证其与其他报单是不重复的。

  1. FrontID + SessionID + OrderRef
  2. ExchangeID + TraderID + OrderLocalID
  3. ExchangeID + OrderSysID

Should a small part of .upd.Trade in fectp.q change from

if[null .db[.ctrl.O;z;`sym];z:exec first id from .db[.ctrl.O] where ordid=w];

to

if[null .db[.ctrl.O;z;`sym];z:exec first id from .db[.ctrl.O] where ordid=w,ex=`$y`ExchangeID];

So add ,exex=`$y`ExchangeID in the where clause

可以考虑不允许策略做全行情订阅(需要对ftbase.q的.upd.quote内调用的realsyms做调整)

可以考虑不允许策略做全行情订阅

因为这样操作可能会留下很多隐患,例如堵住ft等等

需要对ftbase.q的.upd.quote内调用的realsyms做调整

// before
realsyms:{[x;y]
 $[11h<>abs type sl:.db.Ts[x;`syms];
   y;
  0=count sl;
   y;
   y inter sl]
  }; /[tsid;syms]

// after
realsyms:{[x;y]
 $[11h<>abs type sl:.db.Ts[x;`syms];
   `$();
  0=count sl;
   `$();
   y inter sl]
  }; /[tsid;syms]

A potential issue with the .upd.quotenew function in fectp.q

在.upd.quotenew中, linkid被记录为调用quoteInsert函数的返回值:

 .temp.r:r:ctpcall[`quoteInsert;(.conf.ctp`broker`user),(fs2s fs;k1;`int$aq;`int$bq;ap;bp;ctpposefct[ape;ex];ctpposefct[bpe;ex];.enum`HF_Speculation;.enum`HF_Speculation;.enum.ctptex ex)];
 .db.QT[k;`linkid]:`$string first r;

问题是这个返回值并没有太大意义,反而从其他关于linkid逻辑的推断,这个linkid应该被记录为RequestID,而非quoteInsert函数的返回值,例如在.upd.Order中有一段这样的逻辑,其中w就是RequestID:

 if[(null .db[.ctrl.O;z;`sym])&(0<w:y`RequestID);
  if[not null k:exec first id from .db.QT where linkid=`$string w;z1:z;z:.db.QT[k;$[.enum[`D_Buy]=y`Direction;`bid;`aid]]]
  ];

在.upd.QuoteInsertErr也有类似体现,其中x[9]就是RequestID

.upd.QuoteInsertErr:{[x].temp.IL,:enlist x;if[null k:exec first id from .db.QT where linkid=`$string x[9];:()];.db.QT[k;`status`reason`msg`rtime]:(.enum`REJECTED;x[15];x[16];now[]);.db[.ctrl.O;.db.QT[k;`bid];`status`reason`msg`rtime]:.db.QT[k;`status`reason`msg`rtime];.db[.ctrl.O;.db.QT[k;`oid];`status`reason`msg`rtime]:.db.QT[k;`status`reason`msg`rtime];ackquote[k];}; /���۾ܾ�

所以一个可能的改进是让ctpcall函数同时返回requestID?

A potential issue with the .timer.ftsim function in ftbase.q

Would

if[($[1b~.conf`fillwith0qty;0n;0]>=r`cumqty)&(not fs2e[s] in `FOREX`METAL)&(not s like "SP*")&(not 1b~.conf[`fillauction]);:()];

be

if[($[1b~.conf`fillwith0qty;0n;0]>=r`cumqty)&(not fs2e[s] in `FOREX`METAL)&(not s like "SP*")&(not s like "IPS*")&(not 1b~.conf[`fillauction]);:()];

?

So basically add (not s like "IPS*") in the if conditions

A potential issue with imptradex impshcxl and .upd.l2order functions in handling order ids from ftbase.q.

在ftbase.q处理lv2数据的过程中,使用形如gid+10000*origid(oid)的形式确定唯一订单可能存在部分隐患。

其中的隐含假设是gid(即channel_no)是4位数以下的),而这一点在行情api中并没有明确规定。

可能更加稳妥的方法是将两个数据拼起来,例如"I"$string[gid],string[origid]

这样处理的缺点在于cast开销较大

受到相关影响的函数包括imptrade imshcxl .upd.l2order

A query regarding the handling of SP and IPS instruments within the .upd.Trade function in fectp.q.

SP和IPS订单的成交推送规则是什么?是不是只推送构成SP和IPS的单腿订单,不推送SP和IPS订单?

根据fectp.q文件的.upd.Trade

.upd.Trade:{[x]
 .temp.L9,:enlist y:`BrokerID`InvestorID`InstrumentID`OrderRef`UserID`ExchangeID`TradeID`Direction`OrderSysID`ParticipantID`ClientID`TradingRole`ExchangeInstID`OffsetFlag`HedgeFlag`Price`Volume`TradeDate`TradeTime`TradeType`PriceSource`TraderID`OrderLocalID`ClearingPartID`BusinessUnit`SequenceNo`TradingDay`SettlementID`BrokerOrderSeq`TradeSource!x;
 z:idfe2ft `$y`OrderRef;
 w:`$y`OrderSysID;
 if[null .db[.ctrl.O;z;`sym];z:exec first id from .db[.ctrl.O] where ordid=w];
 if[(null fs:.db[.ctrl.O;z;`sym]);:()];
 q:`float$y`Volume;
 p:y`Price;
 lq:0f^.db[.ctrl.O;z;`cumqty];
 lp:0f^.db[.ctrl.O;z;`avgpx];
 if[(fs like "SP*")|(fs like "IPS*");
  s0:`$y`InstrumentID;
  s1:first sl:`$"&" vs last " " vs string fs2s fs;
  s2:last sl;
  if[0=count .db[.ctrl.O;z;`x0];.db[.ctrl.O;z;`x0]:enlist .enum`nulldict];
  qfld:$[s0=s1;`lcumqty;`scumqty];
  pfld:$[s0=s1;`lavgpx;`savgpx];
  lq0:0f^ffill .db[.ctrl.O;z;`x0;0;qfld];
  .db[.ctrl.O;z;`x0]:enlist .db[.ctrl.O;z;`x0;0],(qfld,pfld)!(q+lq0;((q*p)+lq0*0f^ffill .db[.ctrl.O;z;`x0;0;pfld])%(q+lq0));
  $[(cq<=lq)|((0f^ffill .db[.ctrl.O;z;`x0;0;`lcumqty])<>cq:0f^ffill .db[.ctrl.O;z;`x0;0;`scumqty]);
   :();
   [q:cq-lq;p:((cq*(0f^ffill .db[.ctrl.O;z;`x0;0;`lavgpx])-0f^ffill .db[.ctrl.O;z;`x0;0;`savgpx])-lq*lp)%q]
   ]
  ];
 .db[.ctrl.O;z;`ftime`lastqty`lastpx`cumqty`avgpx]:(now[];q;p;q+lq;((q*p)+(lq*lp))%(q+lq));
 lwarn[`trade;(z;`$y`OrderRef;lq;q;.db[.ctrl.O;z;`cumqty])];
 if[(.db[.ctrl.O;z;`cstatus]=.enum`CANCELED)&(.db[.ctrl.O;z;`status]<>.enum`CANCELED);
  if[.db[.ctrl.O;z;`cumqty]>=.temp.DelayedCancel[z];
   .db[.ctrl.O;z;`status]:.enum`CANCELED]];
   execrpt[z];
 };

对于SP和IPS订单有这样的处理:

 if[(fs like "SP*")|(fs like "IPS*");
  s0:`$y`InstrumentID;
  s1:first sl:`$"&" vs last " " vs string fs2s fs;
  s2:last sl;
  if[0=count .db[.ctrl.O;z;`x0];.db[.ctrl.O;z;`x0]:enlist .enum`nulldict];
  qfld:$[s0=s1;`lcumqty;`scumqty];
  pfld:$[s0=s1;`lavgpx;`savgpx];

其中的疑问对于SP和IPS订单的成交推送规则是什么?
以SP I2003&I2004为例子,目前代码的逻辑像是认为在SP I2003&I2004成交后,交易所只会单独推送I2003和I2004,而且不会推送SP I2003&I2004的成交信息?也就是说,推送回来的OrderRef是报SP时发出的OrderRef,但s0(InstrumentID)只会是单腿的?

否则,SP I2003&I2004、I2003和I2004都推送的话,上述代码块的执行可能就会有瑕疵,表现在当推送SP I2003&I2004时,s0<>s1,于是qfld成为scumqty,pfld成为savgpx:

  qfld:$[s0=s1;`lcumqty;`scumqty];
  pfld:$[s0=s1;`lavgpx;`savgpx];

这个情况应该并不是最初的设计?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.