-
Notifications
You must be signed in to change notification settings - Fork 93
/
Copy pathsend_receive.cpp
72 lines (57 loc) · 2.12 KB
/
send_receive.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
/*!
\file send_receive.cpp
\brief Fast Binary Encoding send & receive example
\author Ivan Shynkarenka
\date 14.05.2018
\copyright MIT License
*/
#include "../proto/proto_protocol.h"
#include <iostream>
class MySender : public FBE::proto::Sender
{
protected:
size_t onSend(const void* data, size_t size) override
{
// Send nothing...
return 0;
}
void onSendLog(const std::string& message) const override
{
std::cout << "onSend: " << message << std::endl;
}
};
class MyReceiver : public FBE::proto::Receiver
{
protected:
void onReceive(const proto::OrderMessage& value) override {}
void onReceive(const proto::BalanceMessage& value) override {}
void onReceive(const proto::AccountMessage& value) override {}
void onReceiveLog(const std::string& message) const override
{
std::cout << "onReceive: " << message << std::endl;
}
};
int main(int argc, char** argv)
{
MySender sender;
// Enable logging
sender.logging(true);
// Create and send a new order
proto::OrderMessage order({ proto::Order({ 1, "EURUSD", proto::OrderSide::buy, proto::OrderType::market, 1.23456, 1000.0 }) });
sender.send(order);
// Create and send a new balance wallet
proto::BalanceMessage balance({ proto::Balance({ "USD", 1000.0 }) });
sender.send(balance);
// Create and send a new account with some orders
proto::AccountMessage account({ proto::Account({ 1, "Test", proto::State::good, { "USD", 1000.0 }, std::make_optional<proto::Balance>({ "EUR", 100.0 }), {} }) });
account.body.orders.emplace_back(1, "EURUSD", proto::OrderSide::buy, proto::OrderType::market, 1.23456, 1000.0);
account.body.orders.emplace_back(2, "EURUSD", proto::OrderSide::sell, proto::OrderType::limit, 1.0, 100.0);
account.body.orders.emplace_back(3, "EURUSD", proto::OrderSide::buy, proto::OrderType::stop, 1.5, 10.0);
sender.send(account);
MyReceiver receiver;
// Enable logging
receiver.logging(true);
// Receive all data from the sender
receiver.receive(sender.buffer().data(), sender.buffer().size());
return 0;
}