-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathfix_application.cpp
More file actions
99 lines (80 loc) · 3.36 KB
/
Copy pathfix_application.cpp
File metadata and controls
99 lines (80 loc) · 3.36 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
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
93
94
95
96
97
98
99
// Copyright (C) Mike Kipnis - DistributedATS
#include "fix_application.h"
#include "ws_server.h"
void fix_application::toAdmin(FIX::Message& message, const FIX::SessionID& sessionID)
{
const FIX::Header& header = message.getHeader();
const FIX::MsgType& msgType = FIELD_GET_REF(header, MsgType);
// Convert FIX message to JSON and add common fields
auto json_obj = distributed_ats::fix_json::fix_to_json(message);
json_obj["session_qualifier"] = sessionID.getSessionQualifier();
json_obj["data_type"] = "FIX";
json_obj["success"] = true;
auto json_str = boost::json::serialize(json_obj);
if (msgType == FIX::MsgType_Logon) {
if (auto session = _ws_session.lock()) {
auto ws_logon = session->get_pending_logon();
std::cout << "\nSending Logon: " << sessionID
<< " | Pending Logon: " << ws_logon << std::endl;
// Set Username
FIX::Username userName(sessionID.getSenderCompID());
message.setField(userName);
// Set Password from WebSocket logon
FIX::Password password;
ws_logon.getField(password);
message.setField(password);
// Print JSON log
std::cout << "Sending Logon JSON: " << json_str << std::endl;
}
}
else if (msgType == FIX::MsgType_Logout) {
std::cout << "Logout JSON: " << json_str << std::endl;
}
// Optional: log via QuickFIX
if (auto fix_session = FIX::Session::lookupSession(sessionID)) {
if (auto log = fix_session->getLog()) {
log->onEvent(json_str);
}
}
}
void fix_application::fromAdmin(const FIX::Message& message, const FIX::SessionID& sessionId)
{
// Convert FIX message to JSON
auto json_obj = distributed_ats::fix_json::fix_to_json(message);
json_obj["session_qualifier"] = sessionId.getSessionQualifier();
json_obj["data_type"] = "FIX";
json_obj["success"] = true;
auto json_str = boost::json::serialize(json_obj);
// Send JSON to WebSocket session
if (auto session = _ws_session.lock()) {
session->send_string(json_str);
}
// Log the JSON message using QuickFIX logger
if (auto fix_session = FIX::Session::lookupSession(sessionId)) {
if (auto log = fix_session->getLog()) {
log->onEvent(json_str); // Log as a general event
// If you prefer, you could also log as incoming FIX message:
// log->onIncoming(message, sessionId);
}
}
}
void fix_application::fromApp(const FIX::Message& message, const FIX::SessionID& sessionId)
{
// Convert FIX message to JSON
auto json_obj = distributed_ats::fix_json::fix_to_json(message);
json_obj["session_qualifier"] = sessionId.getSessionQualifier();
json_obj["data_type"] = "FIX";
json_obj["success"] = true;
auto json_str = boost::json::serialize(json_obj);
// Send to your WebSocket session
if (auto session = _ws_session.lock()) {
session->send_string(json_str);
}
// Log the JSON message using QuickFIX logger
if (auto fix_session = FIX::Session::lookupSession(sessionId)) {
if (auto log = fix_session->getLog()) {
log->onEvent(json_str); // Log as an event
// log->onIncoming(message, sessionId);
}
}
}