-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathorderbook.cpp
More file actions
35 lines (31 loc) · 847 Bytes
/
orderbook.cpp
File metadata and controls
35 lines (31 loc) · 847 Bytes
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
#include "orderbook.h"
#include <iostream>
Orderbook::Orderbook(int buy, int sell, std::string url) {
buyCurrency = buy;
sellCurrency = sell;
Url = url;
}
/*
* Function: update()
*
* Synopsis: It implements API transactions. Dummy now.
*/
void Orderbook::update() {
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_real_distribution<> disPrice(0.03, 30.0);
std::uniform_real_distribution<> disAmount(100.0, 3000.0);
for (int i = 0; i < 10; ++i) {
long double amount = disAmount(gen);
long double price = disPrice(gen);
table.push_back(new Column(amount, price));
}
sort(table.begin(), table.end(), [](Column *a, Column *b) {return a->price < b->price;});
}
Column* Orderbook::get(int idx) {
if (idx >= table.size()) {
printf("out of range of orderbook\n");
return NULL;
}
return table[idx];
}