forked from jasonweiyi/XAPI2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCSubscribeManager2.cpp
More file actions
67 lines (56 loc) · 1.1 KB
/
CSubscribeManager2.cpp
File metadata and controls
67 lines (56 loc) · 1.1 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
#include "stdafx.h"
#include "CSubscribeManager2.h"
CSubscribeManager2::CSubscribeManager2()
{
}
CSubscribeManager2::~CSubscribeManager2()
{
}
// 订阅,返回需要API订阅的合约
set<string> CSubscribeManager2::Subscribe(string sym, set<string> ss)
{
auto it = m_maps.find(sym);
if (it == m_maps.end())
{
m_maps.insert(pair<string, set<string>>(sym, ss));
}
else
{
m_maps[sym] = ss;
}
return ss;
}
// 取消订阅,返回需要API取消的合约
set<string> CSubscribeManager2::Unsubscribe(string sym)
{
m_maps.erase(sym);
return GetChildenInstruments();
}
set<string> CSubscribeManager2::GetChildenInstruments()
{
lock_guard<mutex> cl(m_cs);
set<string> ss;
for (auto i = m_maps.begin(); i != m_maps.end(); ++i)
{
for (auto j = i->second.begin(); j != i->second.end(); ++j)
{
ss.insert(j->data());
}
}
return ss;
}
set<string> CSubscribeManager2::GetParentInstruments()
{
lock_guard<mutex> cl(m_cs);
set<string> ss;
for (auto i = m_maps.begin(); i != m_maps.end(); ++i)
{
ss.insert(i->first);
}
return ss;
}
void CSubscribeManager2::Clear()
{
lock_guard<mutex> cl(m_cs);
m_maps.clear();
}