Repository navigation
Expand file tree
/
Copy pathCSyntheticManager.cpp
More file actions
148 lines (134 loc) · 3.31 KB
/
Copy pathCSyntheticManager.cpp
File metadata and controls
148 lines (134 loc) · 3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#include "stdafx.h"
#include "CSyntheticManager.h"
#include <string.h>
CSyntheticManager::CSyntheticManager()
{
}
CSyntheticManager::~CSyntheticManager()
{
for (auto iter = m_map_by_product.begin(); iter != m_map_by_product.end(); iter++)
{
delete iter->second;
}
m_map_by_product.clear();
for (auto iter = m_map_by_instrument.begin(); iter != m_map_by_instrument.end(); iter++)
{
delete[] iter->second;
}
m_map_by_instrument.clear();
}
CSyntheticMarketData* CSyntheticManager::Register(const char* product, set<string> emits, map<string, double> legs, CSyntheticCalculate* pCal)
{
// 用于注册多少个合成合约
CSyntheticMarketData* pSMD = nullptr;
auto it = m_map_by_product.find(product);
if (it == m_map_by_product.end())
{
pSMD = new CSyntheticMarketData(product, emits, pCal);
m_map_by_product.insert(pair<string, CSyntheticMarketData*>(product, pSMD));
}
else
{
pSMD = it->second;
}
// 登记需要用到多少实际合约
for (auto iter = legs.begin(); iter != legs.end(); iter++)
{
char* pBuf = nullptr;
auto it = m_map_by_instrument.find(iter->first);
if (it == m_map_by_instrument.end())
{
// 创建
pBuf = new char[LEG_DATA_BUF_LEN]();
memset(pBuf, 0, LEG_DATA_BUF_LEN);
m_map_by_instrument.insert(pair<string, char*>(iter->first, pBuf));
}
else
{
pBuf = it->second;
}
pSMD->Create(iter->first.c_str(), iter->second, pBuf);
// 关联实盘合约与所能合成的合约
auto it2 = m_map_set_by_instrument.find(iter->first);
if (it2 == m_map_set_by_instrument.end())
{
auto p = set<CSyntheticMarketData*>();
p.insert(pSMD);
m_map_set_by_instrument.insert(pair<string, set<CSyntheticMarketData*>>(iter->first, p));
}
else
{
it2->second.insert(pSMD);
}
}
// 不管有没有用到权重,更新一下
//pSMD->UpdateWeight();
return pSMD;
}
set<string> CSyntheticManager::UnRegister(const char* product)
{
auto it = m_map_by_product.find(product);
if (it == m_map_by_product.end())
{
// 没找到,这是开玩笑的吧
set<string> ss;
return ss;
}
else
{
// 找到合成器指针
auto p = it->second;
// 找到了,需要得到用到了哪些合约
auto ss = p->GetInstruments();
for (auto s1 = ss.begin(); s1 != ss.end(); s1++)
{
auto s2 = m_map_set_by_instrument.find(s1->data());
if (s2 == m_map_set_by_instrument.end())
{
// 没找到,这是开玩笑的吧
}
else
{
// 将此实际合约可以组合成的合成器删了
s2->second.erase(p);
if (s2->second.size() == 0)
{
// 没有要订的,需要删除
m_map_by_instrument.erase(s1->data());
}
}
}
m_map_by_product.erase(product);
return ss;
}
}
char* CSyntheticManager::Update(const char* instrument, void* pData, int size)
{
auto it = m_map_by_instrument.find(instrument);
if (it == m_map_by_instrument.end())
{
// 没找到
return nullptr;
}
else
{
//// 用第一个字节标记数据已经收到
//*it->second = 1;
//memcpy(it->second+1, pData, size);
memcpy(it->second, pData, size);
return it->second;
}
}
set<CSyntheticMarketData*> CSyntheticManager::GetByInstrument(const char* instrument)
{
auto it2 = m_map_set_by_instrument.find(instrument);
if (it2 == m_map_set_by_instrument.end())
{
auto p = set<CSyntheticMarketData*>();
return p;
}
else
{
return it2->second;
}
}