当前位置:网站首页>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
}
}边栏推荐
- Disassembly of Weima prospectus: the electric competition has ended and the intelligent qualifying has just begun
- How to quickly deliver high-value software
- 威马招股书拆解:电动竞争已结束,智能排位赛刚开始
- PHP代码审计1—PHP.ini的那些事
- Teach you how to install win11 system in winpe
- 练习:仿真模拟福彩双色球——中500w巨奖到底有多难?跑跑代码就晓得了。
- JS tool function, self encapsulating a throttling function
- Development of trading system (VI) -- HFT high frequency trading
- PHP代码审计2—这些函数必知必会
- Why can banana be a random number generator? Because it is the "king of radiation" in the fruit industry
猜你喜欢
随机推荐
MySQL根据表前缀批量修改、删除表
Development of trading system (VIII) -- Construction of low delay network
Development of trading system (III) - risk control system
Do you really need automated testing?
俄罗斯AIRI研究院等 | SEMA:利用深度迁移学习进行抗原B细胞构象表征预测
Break the memory wall with CPU scheme? Learn from PayPal stack to expand capacity, and the volume of missed fraud transactions can be reduced to 1/30
Now, the ear is going into the metauniverse
论一个优秀红队人员的自我修养
Tai Chi graphics 60 lines of code to achieve classic papers, 0.7 seconds to get Poisson disk sampling, 100 times faster than numpy
【Proteus仿真】Arduino UNO按键控制数码管闪烁增/减显示
Jilin University 22 spring March "technical economics" assignment assessment-00073
現在,耳朵也要進入元宇宙了
[harmony OS] [ark UI] basic ETS context operations
Crawler grabs the data of Douban group
OpenSUSE environment variable settings
威马招股书拆解:电动竞争已结束,智能排位赛刚开始
虽然传统意义上的互联网早已不复存在,但这并不代表互联网早已消失不再
数学分析_笔记_第3章:极限
2022-06-21-flink-49 (I. SQL manual)
Zuckerberg's latest VR prototype is coming. It is necessary to confuse virtual reality with reality









