-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtick_gen.hpp
69 lines (53 loc) · 1.89 KB
/
tick_gen.hpp
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
#ifndef _TICK_GEN_HPP_
#define _TICK_GEN_HPP_
#include <cstdlib>
#include <ctime>
#include <functional>
#include <map>
#include <set>
#include <vector>
#include "data_source.hpp"
class MarketData;
class TickGen : public IDataSource {
public:
TickGen() { std::srand(0); }
void Subscribe(std::function<void(MarketData&)> func, std::set<std::string> tickers) {
for (auto& ticker : tickers) {
auto iter = callback_map.find(ticker);
if (iter == callback_map.end()) {
callback_map[ticker] = {};
}
callback_map[ticker].push_back(func);
}
}
void TestRun() {
std::vector<MarketData> mdvector;
mdvector.emplace_back("AAPL", 2000000, 2050000, 2020000);
mdvector.emplace_back("IBM", 1000000, 1050000, 1020000);
mdvector.emplace_back("IBM", 1000000, 1050000, 1020000);
mdvector.emplace_back("IBM", 1010000, 1050000, 1020000);
mdvector.emplace_back("IBM", 990000, 1050000, 1020000);
mdvector.emplace_back("IBM", 1000000, 1100000, 900000);
for (auto& md : mdvector) {
if (callback_map.find(md.ticker) != callback_map.end()) {
for (auto& callback : callback_map[md.ticker]) {
callback(md);
}
}
}
}
void Start() {
while (true) {
// find a random ticker to generate market data update
// Rand x% to move last price vs the previous
// Rand y% from last price lower to get the bid
// Rand z% from last price higher to get the ask
// if the ticker is in the tickers list. call the call back, send market data
// wait for a random period of time.
}
}
private:
std::vector<std::string> tickers;
std::map<std::string, std::vector<std::function<void(MarketData&)>>> callback_map;
};
#endif