合约信息管理器
More...
#include <instrument_manager.hpp>
合约信息管理器
负责合约信息的加载、查询和更新操作。 系统启动时从配置文件加载合约静态信息,运行时从行情更新涨跌停价格。
- 线程安全
- 所有公共方法都是线程安全的,使用互斥锁保护内部数据。
- 使用示例
if (inst) {
}
合约信息管理器
Definition instrument_manager.hpp:47
bool updateLimitPrices(const std::string &instrumentId, double upperLimit, double lowerLimit)
更新涨跌停价格
Definition instrument_manager.cpp:303
const Instrument * getInstrument(const std::string &instrumentId) const
获取合约信息
Definition instrument_manager.cpp:265
bool loadFromConfig(const std::string &configPath)
从配置文件加载合约信息
Definition instrument_manager.cpp:176
合约静态信息
Definition instrument.hpp:48
double calculateMargin(double price, int64_t volume) const
计算开仓保证金
Definition instrument.hpp:127
◆ InstrumentManager() [1/2]
| fix40::InstrumentManager::InstrumentManager |
( |
| ) |
|
|
default |
◆ ~InstrumentManager()
| fix40::InstrumentManager::~InstrumentManager |
( |
| ) |
|
|
default |
◆ InstrumentManager() [2/2]
◆ addInstrument()
| void fix40::InstrumentManager::addInstrument |
( |
const Instrument & |
instrument | ) |
|
添加单个合约
手动添加合约信息,主要用于测试。
- Parameters
-
- Note
- 如果合约ID已存在,将覆盖原有合约信息,不会发出警告。 这是设计意图,允许更新合约参数(如保证金率变化)。
◆ addInstruments()
| void fix40::InstrumentManager::addInstruments |
( |
const std::vector< Instrument > & |
instruments | ) |
|
批量添加合约
- Parameters
-
- Note
- 如果合约ID已存在,将覆盖原有合约信息,不会发出警告。
◆ clear()
| void fix40::InstrumentManager::clear |
( |
| ) |
|
◆ getAllInstrumentIds()
| std::vector< std::string > fix40::InstrumentManager::getAllInstrumentIds |
( |
| ) |
const |
◆ getInstrument()
| const Instrument * fix40::InstrumentManager::getInstrument |
( |
const std::string & |
instrumentId | ) |
const |
获取合约信息
- Parameters
-
- Returns
- 合约信息指针,不存在时返回 nullptr
- Note
- 返回的指针在下次修改操作前有效
◆ getInstrumentCopy()
| std::optional< Instrument > fix40::InstrumentManager::getInstrumentCopy |
( |
const std::string & |
instrumentId | ) |
const |
获取合约信息(可选类型)
- Parameters
-
- Returns
- 合约信息的副本,不存在时返回 std::nullopt
◆ getInstrumentsByExchange()
| std::vector< std::string > fix40::InstrumentManager::getInstrumentsByExchange |
( |
const std::string & |
exchangeId | ) |
const |
按交易所获取所有合约
- Parameters
-
| exchangeId | 交易所代码(如 "CFFEX") |
- Returns
- 该交易所的所有合约代码列表
◆ getInstrumentsByProduct()
| std::vector< std::string > fix40::InstrumentManager::getInstrumentsByProduct |
( |
const std::string & |
productId | ) |
const |
按品种获取所有合约
- Parameters
-
- Returns
- 该品种的所有合约代码列表
◆ hasInstrument()
| bool fix40::InstrumentManager::hasInstrument |
( |
const std::string & |
instrumentId | ) |
const |
检查合约是否存在
- Parameters
-
- Returns
- 存在返回 true
◆ loadFromConfig()
| bool fix40::InstrumentManager::loadFromConfig |
( |
const std::string & |
configPath | ) |
|
从配置文件加载合约信息
解析JSON格式的配置文件,加载合约静态信息。
- Parameters
-
- Returns
- 加载成功返回 true,失败返回 false
- 配置文件格式
{
"instruments": [
{
"instrumentId": "IF2601",
"exchangeId": "CFFEX",
"productId": "IF",
"priceTick": 0.2,
"volumeMultiple": 300,
"marginRate": 0.12
}
]
}
◆ operator=()
◆ searchByPrefix()
| std::vector< std::string > fix40::InstrumentManager::searchByPrefix |
( |
const std::string & |
prefix, |
|
|
size_t |
limit = 10 |
|
) |
| const |
按前缀搜索合约
用于实现合约代码的自动补全功能。
- Parameters
-
| prefix | 合约代码前缀(如 "IF") |
| limit | 返回结果数量上限(默认 10) |
- Returns
- 匹配的合约代码列表(按字母排序)
- 使用示例
auto results = mgr.searchByPrefix("IF", 5);
◆ size()
| size_t fix40::InstrumentManager::size |
( |
| ) |
const |
◆ updateLimitPrices()
| bool fix40::InstrumentManager::updateLimitPrices |
( |
const std::string & |
instrumentId, |
|
|
double |
upperLimit, |
|
|
double |
lowerLimit |
|
) |
| |
更新涨跌停价格
从行情数据更新合约的涨跌停价格。
- Parameters
-
| instrumentId | 合约代码 |
| upperLimit | 涨停价 |
| lowerLimit | 跌停价 |
- Returns
- 更新成功返回 true,合约不存在返回 false
◆ updatePreSettlementPrice()
| bool fix40::InstrumentManager::updatePreSettlementPrice |
( |
const std::string & |
instrumentId, |
|
|
double |
preSettlementPrice |
|
) |
| |
更新昨结算价
- Parameters
-
| instrumentId | 合约代码 |
| preSettlementPrice | 昨结算价 |
- Returns
- 更新成功返回 true,合约不存在返回 false
The documentation for this class was generated from the following files: