FIX 4.0 Demo 1.0
Loading...
Searching...
No Matches
instrument_manager.hpp
Go to the documentation of this file.
1
9#pragma once
10
11#include <string>
12#include <unordered_map>
13#include <optional>
14#include <mutex>
15#include <vector>
17
18namespace fix40 {
19
48public:
49 // -------------------------------------------------------------------------
50 // 构造函数
51 // -------------------------------------------------------------------------
52
56 InstrumentManager() = default;
57
61 ~InstrumentManager() = default;
62
63 // 禁用拷贝
66
67 // -------------------------------------------------------------------------
68 // 加载方法
69 // -------------------------------------------------------------------------
70
95 bool loadFromConfig(const std::string& configPath);
96
107 void addInstrument(const Instrument& instrument);
108
116 void addInstruments(const std::vector<Instrument>& instruments);
117
118 // -------------------------------------------------------------------------
119 // 查询方法
120 // -------------------------------------------------------------------------
121
130 const Instrument* getInstrument(const std::string& instrumentId) const;
131
138 std::optional<Instrument> getInstrumentCopy(const std::string& instrumentId) const;
139
146 bool hasInstrument(const std::string& instrumentId) const;
147
153 std::vector<std::string> getAllInstrumentIds() const;
154
160 size_t size() const;
161
177 std::vector<std::string> searchByPrefix(const std::string& prefix, size_t limit = 10) const;
178
185 std::vector<std::string> getInstrumentsByProduct(const std::string& productId) const;
186
193 std::vector<std::string> getInstrumentsByExchange(const std::string& exchangeId) const;
194
195 // -------------------------------------------------------------------------
196 // 更新方法
197 // -------------------------------------------------------------------------
198
209 bool updateLimitPrices(const std::string& instrumentId,
210 double upperLimit, double lowerLimit);
211
219 bool updatePreSettlementPrice(const std::string& instrumentId,
220 double preSettlementPrice);
221
222 // -------------------------------------------------------------------------
223 // 清理方法
224 // -------------------------------------------------------------------------
225
229 void clear();
230
231private:
233 std::unordered_map<std::string, Instrument> instruments_;
234
236 mutable std::mutex mutex_;
237};
238
239} // namespace fix40
合约信息管理器
Definition instrument_manager.hpp:47
void clear()
清空所有合约
Definition instrument_manager.cpp:325
bool updateLimitPrices(const std::string &instrumentId, double upperLimit, double lowerLimit)
更新涨跌停价格
Definition instrument_manager.cpp:303
void addInstruments(const std::vector< Instrument > &instruments)
批量添加合约
Definition instrument_manager.cpp:258
std::vector< std::string > getInstrumentsByExchange(const std::string &exchangeId) const
按交易所获取所有合约
Definition instrument_manager.cpp:373
const Instrument * getInstrument(const std::string &instrumentId) const
获取合约信息
Definition instrument_manager.cpp:265
~InstrumentManager()=default
析构函数
bool loadFromConfig(const std::string &configPath)
从配置文件加载合约信息
Definition instrument_manager.cpp:176
std::vector< std::string > getInstrumentsByProduct(const std::string &productId) const
按品种获取所有合约
Definition instrument_manager.cpp:358
InstrumentManager(const InstrumentManager &)=delete
std::vector< std::string > getAllInstrumentIds() const
获取所有合约代码
Definition instrument_manager.cpp:288
InstrumentManager & operator=(const InstrumentManager &)=delete
void addInstrument(const Instrument &instrument)
添加单个合约
Definition instrument_manager.cpp:253
bool updatePreSettlementPrice(const std::string &instrumentId, double preSettlementPrice)
更新昨结算价
Definition instrument_manager.cpp:314
std::vector< std::string > searchByPrefix(const std::string &prefix, size_t limit=10) const
按前缀搜索合约
Definition instrument_manager.cpp:330
size_t size() const
获取合约数量
Definition instrument_manager.cpp:298
bool hasInstrument(const std::string &instrumentId) const
检查合约是否存在
Definition instrument_manager.cpp:283
std::optional< Instrument > getInstrumentCopy(const std::string &instrumentId) const
获取合约信息(可选类型)
Definition instrument_manager.cpp:274
InstrumentManager()=default
默认构造函数
合约信息数据结构
Definition matching_engine.hpp:23
合约静态信息
Definition instrument.hpp:48