-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathdeal_log_base_t.cpp
93 lines (74 loc) · 2.36 KB
/
deal_log_base_t.cpp
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
#include "deal_log_base_t.h"
namespace trading
{
//-------------------------------------------------------------------
//-------------------------------------------------------------------
deal_log_base_t::deal_log_base_t()
{
}
//-------------------------------------------------------------------
//-------------------------------------------------------------------
deal_log_base_t::~deal_log_base_t()
{
}
//-------------------------------------------------------------------
//-------------------------------------------------------------------
vol_t deal_log_base_t::operator[](double price) const
{
auto it = m_deals.find(price);
if (it != m_deals.end())
return it->second;
else
return 0;
}
//-------------------------------------------------------------------
//-------------------------------------------------------------------
void deal_log_base_t::set(double price, vol_t volume)
{
if (volume <= 0)
{
m_deals.erase(price);
if (m_deals.empty())
m_state = deal_type_t::undefined;
}
else
m_deals[price] = volume;
}
//-------------------------------------------------------------------
//-------------------------------------------------------------------
vector<double> deal_log_base_t::sells() const
{
if (m_state == deal_type_t::sell)
{
vector<double> sells;
for (auto it = m_deals.begin(); it != m_deals.end(); it++)
if (it->second > 0)
sells.push_back(it->first);
return sells;
}
else
return vector<double>();
}
//-------------------------------------------------------------------
//-------------------------------------------------------------------
vector<double> deal_log_base_t::buys() const
{
if (m_state == deal_type_t::buy)
{
vector<double> buys;
for (auto it = m_deals.rbegin(); it != m_deals.rend(); it++)
if (it->second > 0)
buys.push_back(it->first);
return buys;
}
else
return vector<double>();
}
//-------------------------------------------------------------------
//-------------------------------------------------------------------
void deal_log_base_t::add_deal(const deal_base_t &deal)
{
}
//-------------------------------------------------------------------
//-------------------------------------------------------------------
}