forked from dxFeed/dxfeed-c-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPriceLevelBookNG.cpp
90 lines (71 loc) · 2.85 KB
/
PriceLevelBookNG.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
/*
* The contents of this file are subject to the Mozilla Public License Version
* 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Initial Developer of the Original Code is Devexperts LLC.
* Portions created by the Initial Developer are Copyright (C) 2010
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
*/
extern "C" {
#include "PriceLevelBookNG.h"
}
#include "PriceLevelBookNG.hpp"
extern "C" {
dxf_price_level_book_v2_t dx_create_price_level_book_v2(dxf_connection_t connection, dxf_const_string_t symbol,
const char* source, int levels_number) {
auto plb = dx::PriceLevelBook::create(connection, dx::StringConverter::wStringToUtf8(symbol), std::string(source),
levels_number < 0 ? 0 : static_cast<std::size_t>(levels_number));
return static_cast<dxf_price_level_book_v2_t>(plb);
}
int dx_close_price_level_book_v2(dxf_price_level_book_v2_t book) {
if (book == nullptr) {
return false;
}
delete static_cast<dx::PriceLevelBook*>(book);
return true;
}
int dx_set_price_level_book_listeners_v2(dxf_price_level_book_v2_t book,
dxf_price_level_book_listener_t onNewBookHandler,
dxf_price_level_book_listener_t onBookUpdateHandler,
dxf_price_level_book_inc_listener_t onIncrementalChangeHandler,
void* userData) {
if (book == nullptr) return false;
auto* plb = static_cast<dx::PriceLevelBook*>(book);
if (userData) {
plb->setUserData(userData);
}
if (onNewBookHandler != nullptr) {
plb->setOnNewBook([onNewBookHandler](const dx::PriceLevelChanges& changes, void* userData) {
dx::PriceLevelBookDataBundle bundle{changes};
onNewBookHandler(&bundle.priceLevelBookData, userData);
});
}
if (onBookUpdateHandler != nullptr) {
plb->setOnBookUpdate([onBookUpdateHandler](const dx::PriceLevelChanges& changes, void* userData) {
dx::PriceLevelBookDataBundle bundle{changes};
onBookUpdateHandler(&bundle.priceLevelBookData, userData);
});
}
if (onIncrementalChangeHandler != nullptr) {
plb->setOnIncrementalChange(
[onIncrementalChangeHandler](const dx::PriceLevelChangesSet& changesSet, void* userData) {
dx::PriceLevelBookDataBundle removalsBundle{changesSet.removals};
dx::PriceLevelBookDataBundle additionsBundle{changesSet.additions};
dx::PriceLevelBookDataBundle updatesBundle{changesSet.updates};
onIncrementalChangeHandler(&removalsBundle.priceLevelBookData, &additionsBundle.priceLevelBookData,
&updatesBundle.priceLevelBookData, userData);
});
}
return true;
}
}