当前位置:网站首页>Hello CTP (V) -- CTP position calculation
Hello CTP (V) -- CTP position calculation
2022-06-25 04:03:00 【Tianshan old demon】
One 、CTP Position
LongOpenPosition: Long opening volume
LongOpenFrozen: Long positions are frozen
LongYdPosition: Long yesterday
LongTdPosition: Bulls today
LongCloseTdFrozen: Long flat positions are frozen
LongCloseYdFrozen: Long flat positions froze yesterday
ShortOpenPosition: Short opening volume
ShortTdPosition: Short positions
ShortYdPosition: Short yesterday
ShortCloseTdFrozen: Short positions are frozen
ShortCloseYdFrozen: Short positions were frozen yesterday
LongFrozenAmount: Long frozen amount
ShortFrozenAmount: Short frozen amount
FrozenMargin: Freeze the deposit
FrozenCommission: Freeze handling charges
Two 、 Bin query
1、 Bin query
The current position status of the account will be obtained when the trading system is started , Only by querying CTP obtain . If there is an order or transaction in the course of trading , There will be corresponding position freeze and position change , because CTP Query flow control and ensure the real-time update of positions , Usually update the position status according to the order return .
2、 Bin query API
Bin query request API:
virtual int ReqQryInvestorPosition(CThostFtdcQryInvestorPositionField *pQryInvestorPosition, int nRequestID) = 0;
Position return callback function :
virtual void OnRspQryInvestorPosition(CThostFtdcInvestorPositionField *pInvestorPosition, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
3、 Position calculation
CThostFtdcInvestorPositionField The returned bin fields are as follows :
BrokerID: Brokerage code
InvestorID: Investor code
PosiDirection: Long and short positions
HedgeFlag: Speculative hedging flag
PositionDate: Position date
YdPosition: Last day's position
Position: Current position
LongFrozen: Long freeze
ShortFrozen: Short freeze
LongFrozenAmount: Opening frozen amount
ShortFrozenAmount: Opening frozen amount
OpenVolume: Opening volume
CloseVolume: Closing volume
OpenAmount: Opening amount
CloseAmount: Closing amount
PositionCost: Position cost
PreMargin: Last occupied deposit
UseMargin: Take up the deposit
FrozenMargin: Freeze the deposit
FrozenCash: Freeze funds
FrozenCommission: Freeze handling charges
CashIn: Fund balance
Commission: Service Charge
CloseProfit: Closing profit and loss
PositionProfit: Position profit and loss
PreSettlementPrice: Last settlement price
SettlementPrice: This settlement price
SettlementID: Settlement No
OpenCost: Opening cost
ExchangeMargin: Exchange margin
CombPosition: The closing portfolio forms a position
CombLongFrozen: Combined multi head freezing
CombShortFrozen: Combined short freeze
CloseProfitByDate: Mark to market daily to close the profit and loss
CloseProfitByTrade: Profit and loss of hedging and closing positions one by one
TodayPosition: Today's new opening
MarginRateByMoney: Margin rate
MarginRateByVolume: Margin rate ( Number of hands )
StrikeFrozen: Execute freeze
StrikeFrozenAmount: Execute frozen amount
ExchangeID: Exchange code
YdStrikeFrozen: Execute the freezing of yesterday's warehouse
InvestUnitID: Investment unit code
InstrumentID: Contract code
CTP The position query results will be pushed in batches according to the long and short positions of the account contract ,PosiDirection The field values for THOST_FTDC_PD_Long('2') Indicates a long position ,THOST_FTDC_PD_Short('3') Indicates a short position .
LongPosition = Position
ShortPosition = Position
LongOpenPosition = OpenVolume
ShortOpenPositon = OpenVolume
LongClosePosition = CloseVolume
ShortClosePosition = CloseVolume
CurrentYdPosition = Position - TodayPosition
YdPosition = YdPosition
- Real time position calculation
1、 Closing operations
CTP Transaction return and order return are in the return data ,Direction The field values for THOST_FTDC_D_Buy('0') It means buying ,THOST_FTDC_D_Sell('1') It means sell .OffsetFlag The field value of Kaiping identification is THOST_FTDC_OF_Open('0') It means opening a position ,THOST_FTDC_OF_Close('1') It means closing the position ,THOST_FTDC_OF_ForceClose('2') Strong flat ,THOST_FTDC_OF_CloseToday('3') It means Pingjin ,THOST_FTDC_OF_CloseYesterday('4') It means yesterday ,THOST_FTDC_OF_ForceOff('5') Indicates forced reduction ,THOST_FTDC_OF_LocalForceClose('6') Indicates the local strong level .
CICC's positions are not divided into current positions and yesterday's positions , Once the position is opened , All yesterday positions of bulls or bears will be regarded as today's positions , Therefore, the closing return will only return THOST_FTDC_OF_Close('1'), Need basis Direction And contract positions LongTdPosition、ShortTdPosition Judge . If LongTdPosition、ShortTdPosition Greater than 0, The closing operation is to close the current position , Otherwise, it will be a flat position .
2、 Transaction return position calculation
virtual void OnRtnTrade(CThostFtdcTradeField *pTrade);
CThostFtdcTradeField The fields are as follows :
BrokerID: Brokerage code
InvestorID: Investor code
OrderRef: Entry reference
UserID: user designation codes
ExchangeID: Exchange code
TradeID: Transaction No
Direction: Business direction
OrderSysID: Exchange entry No
ParticipantID: Membership code
OffsetFlag: Kaiping logo
HedgeFlag: Speculative hedging identification
Price: Price
Volume: Number
TradeType: Transaction type
TraderID: Trader code
OrderLocalID: Local entry number
SettlementID: Settlement No
InstrumentID: Contract code
if(pTrade->Direction == THOST_FTDC_D_Buy && pTrade->OffsetFlag[0] == THOST_FTDC_OF_Close)
{
if(ShortTdPosition > 0)
{
// Close Short Today Position
}
else
{
// Close Short YesToday Position
}
}
else if(pTrade->Direction == THOST_FTDC_D_Sell && pTrade->OffsetFlag[0] == THOST_FTDC_OF_Close)
{
if(LongTdPosition > 0)
{
// Close Long Today Position
}
else
{
// Close Long YesToday Position
}
}3、 Calculation of return position of entry
virtual void OnRtnOrder(CThostFtdcOrderField *pOrder);
CThostFtdcOrderField The fields are as follows :
BrokerID: Brokerage code
InvestorID: Investor code
OrderRef: Entry reference
UserID: user designation codes
OrderPriceType: Price terms of the entry
Direction: Business direction
CombOffsetFlag: Combined leveling logo
CombHedgeFlag: Portfolio speculative hedging identification
LimitPrice: Price
VolumeTotalOriginal: Number
TimeCondition: Validity type
VolumeCondition: Volume type
MinVolume: Minimum volume
ContingentCondition: The trigger condition
StopPrice: Stop-loss price
ForceCloseReason: Qiang Ping's reason
RequestID: Request number
OrderLocalID: Local entry number
ExchangeID: Exchange code
ParticipantID: Membership code
TraderID: Trader code
OrderSubmitStatus: Declaration submission status
SettlementID: Settlement No
OrderSysID: Exchange entry No
OrderStatus: Entry status
OrderType: Entry type
VolumeTraded: Number of transactions today
VolumeTotal: The remaining quantity
FrontID: Prefix number
SessionID: Session number
StatusMsg: Order status information
AccountID: Fund account number
InstrumentID: Contract code
VolumeTraded: Number of transactions today
VolumeTotal: The remaining quantity
VolumeTotalOriginal: Number
if(pOrder->Direction == THOST_FTDC_D_Buy && pOrder->CombOffsetFlag[0] == THOST_FTDC_OF_Close)
{
if(ShortTdPosition > 0)
{
// Close Short Today Position
}
else
{
// Close Short YesToday Position
}
}
else if(pOrder->Direction == THOST_FTDC_D_Sell && pOrder->CombOffsetFlag[0] == THOST_FTDC_OF_Close)
{
if(LongTdPosition > 0)
{
// Close Long Today Position
}
else
{
// Close Long YesToday Position
}
}边栏推荐
- Comprehensive operation of financial risk management X of Dongcai
- 亚马逊在中国的另一面
- Crawler grabs the idea of reading on wechat
- Comprehensive assignment of thesis writing instruction of Dongcai
- web3.eth. Getpendingtransactions() returns null?
- Create SQLite table with shell script and add SQL statement -- General
- Preparedstatement principle of preventing SQL injection
- Demonstration of combination of dream CAD cloud map and GIS
- Development of trading system (II) -- market data
- About PLSQL error initialization failure
猜你喜欢

Development of trading system (VI) -- HFT high frequency trading

Maintenant, les oreilles vont entrer dans le métacosme.

AI writes its own code to let agents evolve! The big model of openai has the flavor of "human thought"

The more AI evolves, the more it resembles the human brain! Meta found the "prefrontal cortex" of the machine. AI scholars and neuroscientists were surprised

ICML 2022 | ByteDance AI Lab proposes a multimodal model: x-vlm, learning multi granularity alignment of vision and language

Does it count as staying up late to sleep at 2:00 and get up at 10:00? Unless you can do it every day

(ultra detailed onenet TCP protocol access) arduino+esp8266-01s accesses the Internet of things platform, uploads real-time collected data /tcp transparent transmission (and how to obtain and write Lu

ZABBIX installation pit avoidance Guide

The programmer reality show is coming again! Hulan, as the host, carried the lamp to fill the knowledge. The SSS boss had a bachelor's degree in pharmacy. Zhu Jun and Zhang Min from Tsinghua joined th

Trading system development (IV) - trading counter system
随机推荐
Work assessment of pharmacotherapeutics of Jilin University in March of the 22nd spring -00064
Tensorflow, danger! Google itself is the one who abandoned it
Intel 13代酷睿首次露出真面目:68MB缓存提升明显
Development of trading system (III) - risk control system
The problem that only the home page can be accessed under openSUSE Apache laravel
Work assessment of Biopharmaceutics of Jilin University in March of the 22nd spring -00031
Tianshu night reading notes - 8.4 diskperf disassembly
MySQL modifies and deletes tables in batches according to the table prefix
微信小程序中的列表渲染
“语法糖”——我的编程新知
How far is the memory computing integrated chip from popularization? Listen to what practitioners say | collision school x post friction intelligence
[harmony OS] [arkui] ETS development graphics and animation drawing
Musk was sued for $258billion in MLM claims. TSMC announced the 2nm process. The Chinese Academy of Sciences found that the lunar soil contained water in the form of hydroxyl. Today, more big news is
Work assessment of Biopharmaceutics of Jilin University in March of the 22nd spring -00005
X86 CPU, critical! The latest vulnerability has caused heated discussion. Hackers can remotely steal keys. Intel "all processors" are affected
Dr. Sun Jian was commemorated at the CVPR conference. The best student thesis was awarded to Tongji Ali. Lifeifei won the huangxutao Memorial Award
MySQL根据表前缀批量修改、删除表
Interview with Mo Tianlun | ivorysql wangzhibin - ivorysql, an Oracle compatible open source database based on PostgreSQL
Teach you how to install win11 system in winpe
BGP biplane architecture