FIX 4.0 Demo 1.0
Loading...
Searching...
No Matches
fix40::Instrument Struct Reference

合约静态信息 More...

#include <instrument.hpp>

Collaboration diagram for fix40::Instrument:
Collaboration graph

Public Member Functions

 Instrument ()
 默认构造函数
 
 Instrument (const std::string &instId, const std::string &exchId, const std::string &prodId, double tick, int multiple, double margin)
 带基本参数的构造函数
 
double calculateMargin (double price, int64_t volume) const
 计算开仓保证金
 
bool isPriceValid (double price) const
 检查价格是否在涨跌停范围内
 
bool isPriceTickValid (double price) const
 检查价格是否符合最小变动价位
 
void updateLimitPrices (double upper, double lower)
 更新涨跌停价格
 
bool operator== (const Instrument &other) const
 相等比较操作符
 
bool operator!= (const Instrument &other) const
 不等比较操作符
 

Public Attributes

std::string instrumentId
 合约代码(如 "IF2601")
 
std::string exchangeId
 交易所代码(如 "CFFEX")
 
std::string productId
 品种代码(如 "IF")
 
double priceTick
 最小变动价位(如 0.2)
 
int volumeMultiple
 合约乘数(如 300)
 
double marginRate
 保证金率(如 0.12 表示 12)
 
double upperLimitPrice
 涨停价
 
double lowerLimitPrice
 跌停价
 
double preSettlementPrice
 昨结算价
 

Detailed Description

合约静态信息

期货合约的基本属性,包含交易规则相关的参数。 系统通过此结构进行保证金计算和价格有效性检查。

保证金计算
保证金 = 价格 × 数量 × 合约乘数 × 保证金率
使用示例
inst.instrumentId = "IF2601";
inst.exchangeId = "CFFEX";
inst.volumeMultiple = 300;
inst.marginRate = 0.12; // 12%
inst.priceTick = 0.2;
// 计算开仓保证金
double margin = inst.calculateMargin(4000.0, 2);
// margin = 4000 * 2 * 300 * 0.12 = 288000
// 检查价格有效性
bool valid = inst.isPriceValid(4050.0);
合约静态信息
Definition instrument.hpp:48
bool isPriceValid(double price) const
检查价格是否在涨跌停范围内
Definition instrument.hpp:141
double calculateMargin(double price, int64_t volume) const
计算开仓保证金
Definition instrument.hpp:127
double priceTick
最小变动价位(如 0.2)
Definition instrument.hpp:59
double marginRate
保证金率(如 0.12 表示 12)
Definition instrument.hpp:61
int volumeMultiple
合约乘数(如 300)
Definition instrument.hpp:60
std::string instrumentId
合约代码(如 "IF2601")
Definition instrument.hpp:52
std::string exchangeId
交易所代码(如 "CFFEX")
Definition instrument.hpp:53

Constructor & Destructor Documentation

◆ Instrument() [1/2]

fix40::Instrument::Instrument ( )
inline

默认构造函数

初始化所有数值字段为 0。

◆ Instrument() [2/2]

fix40::Instrument::Instrument ( const std::string &  instId,
const std::string &  exchId,
const std::string &  prodId,
double  tick,
int  multiple,
double  margin 
)
inline

带基本参数的构造函数

Parameters
instId合约代码
exchId交易所代码
prodId品种代码
tick最小变动价位
multiple合约乘数
margin保证金率

Member Function Documentation

◆ calculateMargin()

double fix40::Instrument::calculateMargin ( double  price,
int64_t  volume 
) const
inline

计算开仓保证金

根据价格和数量计算所需的保证金。

Parameters
price开仓价格
volume开仓数量(手数)
Returns
所需保证金金额
计算公式
保证金 = 价格 × 数量 × 合约乘数 × 保证金率
Here is the caller graph for this function:

◆ isPriceTickValid()

bool fix40::Instrument::isPriceTickValid ( double  price) const
inline

检查价格是否符合最小变动价位

验证给定价格是否是最小变动价位的整数倍。

Parameters
price待检查的价格
Returns
如果价格符合最小变动价位返回 true
Note
使用容差比较以处理浮点数精度问题

◆ isPriceValid()

bool fix40::Instrument::isPriceValid ( double  price) const
inline

检查价格是否在涨跌停范围内

验证给定价格是否在当日涨跌停价格范围内。

Parameters
price待检查的价格
Returns
如果价格在有效范围内返回 true
Note
如果涨跌停价格未设置(为0),则认为价格有效
Here is the caller graph for this function:

◆ operator!=()

bool fix40::Instrument::operator!= ( const Instrument other) const
inline

不等比较操作符

Parameters
other另一个合约
Returns
如果任意字段不相等则返回 true

◆ operator==()

bool fix40::Instrument::operator== ( const Instrument other) const
inline

相等比较操作符

比较两个合约的所有字段是否相等。

Parameters
other另一个合约
Returns
如果所有字段相等则返回 true
Note
此操作符使用精确比较,适用于序列化/反序列化的 round-trip 测试。 如需比较计算结果,请使用带容差的比较方法。

◆ updateLimitPrices()

void fix40::Instrument::updateLimitPrices ( double  upper,
double  lower 
)
inline

更新涨跌停价格

从行情数据更新涨跌停价格。

Parameters
upper涨停价
lower跌停价

Member Data Documentation

◆ exchangeId

std::string fix40::Instrument::exchangeId

交易所代码(如 "CFFEX")

◆ instrumentId

std::string fix40::Instrument::instrumentId

合约代码(如 "IF2601")

◆ lowerLimitPrice

double fix40::Instrument::lowerLimitPrice

跌停价

◆ marginRate

double fix40::Instrument::marginRate

保证金率(如 0.12 表示 12)

◆ preSettlementPrice

double fix40::Instrument::preSettlementPrice

昨结算价

◆ priceTick

double fix40::Instrument::priceTick

最小变动价位(如 0.2)

◆ productId

std::string fix40::Instrument::productId

品种代码(如 "IF")

◆ upperLimitPrice

double fix40::Instrument::upperLimitPrice

涨停价

◆ volumeMultiple

int fix40::Instrument::volumeMultiple

合约乘数(如 300)


The documentation for this struct was generated from the following file: