-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MDAPI-216][C++][Console] Add PriceLevelBook sample (#66)
- Loading branch information
Showing
14 changed files
with
847 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Copyright (c) 2024 Devexperts LLC. | ||
# SPDX-License-Identifier: MPL-2.0 | ||
|
||
cmake_minimum_required(VERSION 3.21) | ||
|
||
if (POLICY CMP0092) | ||
cmake_policy(SET CMP0092 NEW) | ||
endif () | ||
|
||
if (POLICY CMP0135) | ||
cmake_policy(SET CMP0135 NEW) | ||
endif () | ||
|
||
project(PriceLevelBookSample LANGUAGES CXX) | ||
|
||
set(CMAKE_CXX_STANDARD 20) | ||
set(CMAKE_C_STANDARD 11) | ||
set(CXX_EXTENSIONS OFF) | ||
set(C_EXTENSIONS OFF) | ||
|
||
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") | ||
set(CMAKE_MACOSX_RPATH ON) | ||
set(CMAKE_SKIP_BUILD_RPATH ON) | ||
set(CMAKE_BUILD_WITH_INSTALL_RPATH ON) | ||
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH OFF) | ||
set(CMAKE_BUILD_RPATH_USE_ORIGIN ON) | ||
set(CMAKE_INSTALL_RPATH "@loader_path/../${CMAKE_INSTALL_LIBDIR};@loader_path;@executable_path;@executable_path/../Frameworks") | ||
elseif (UNIX) | ||
set(CMAKE_SKIP_BUILD_RPATH ON) | ||
set(CMAKE_BUILD_WITH_INSTALL_RPATH ON) | ||
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH OFF) | ||
set(CMAKE_BUILD_RPATH_USE_ORIGIN ON) | ||
set(CMAKE_INSTALL_RPATH "$ORIGIN/../${CMAKE_INSTALL_LIBDIR}:$ORIGIN/../lib64:$ORIGIN/../lib:$ORIGIN") | ||
endif () | ||
|
||
add_executable(${PROJECT_NAME} src/main.cpp) | ||
|
||
target_include_directories(${PROJECT_NAME} PRIVATE ../../../third_party/range-v3-0.12/include) | ||
|
||
target_link_libraries(${PROJECT_NAME} PRIVATE dxfcxx::static fmt::fmt-header-only) | ||
|
||
if (DXFCXX_FEATURE_STACKTRACE) | ||
LinkStacktrace(${PROJECT_NAME}) | ||
endif () | ||
|
||
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different | ||
$<TARGET_FILE:dxfcxx::graal> | ||
$<TARGET_FILE_DIR:${PROJECT_NAME}>) | ||
|
||
if (DXFCXX_INSTALL AND DXFCXX_INSTALL_SAMPLES) | ||
install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR}) | ||
|
||
if (WIN32) | ||
install(FILES $<TARGET_FILE:dxfcxx::graal> DESTINATION ${CMAKE_INSTALL_BINDIR}) | ||
endif () | ||
endif () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
// Copyright (c) 2024 Devexperts LLC. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
#pragma once | ||
|
||
#include <dxfeed_graal_cpp_api/api.hpp> | ||
|
||
#include <string> | ||
|
||
/// Represents a price level in a price level book. | ||
struct PriceLevel { | ||
private: | ||
std::optional<std::string> eventSymbol_; | ||
const dxfcpp::IndexedEventSource &eventSource_; | ||
const dxfcpp::Side &side_; | ||
double price_; | ||
double size_; | ||
|
||
public: | ||
/** | ||
* Initializes a new default instance. | ||
*/ | ||
PriceLevel() : eventSource_{dxfcpp::IndexedEventSource::DEFAULT}, side_{dxfcpp::Side::UNDEFINED}, price_{}, size_{} { | ||
} | ||
|
||
/** | ||
* Initializes a new instance by copying an existing price level. | ||
* | ||
* @param pl The price level to copy. | ||
*/ | ||
PriceLevel(const PriceLevel &pl) | ||
: eventSymbol_{pl.eventSymbol_}, eventSource_{pl.eventSource_}, side_{pl.side_}, price_{pl.price_}, | ||
size_(pl.size_) { | ||
} | ||
|
||
/** | ||
* Initializes a new instance using an order. | ||
* | ||
* @param order The order to initialize the price level from. | ||
*/ | ||
explicit PriceLevel(const std::shared_ptr<dxfcpp::OrderBase> &order) | ||
: eventSymbol_{order->getEventSymbolOpt()}, eventSource_{order->getSource()}, side_{order->getOrderSide()}, | ||
price_{order->getPrice()}, size_{order->getSize()} { | ||
} | ||
|
||
/// Returns the optional event symbol. | ||
const std::optional<std::string> &getEventSymbol() const { | ||
return eventSymbol_; | ||
} | ||
|
||
/// Returns the event source. | ||
const dxfcpp::IndexedEventSource &getEventSource() const { | ||
return eventSource_; | ||
} | ||
|
||
/// Returns the side of the price level. | ||
const dxfcpp::Side &getSide() const { | ||
return side_; | ||
} | ||
|
||
/// Returns the price of the price level. | ||
double getPrice() const { | ||
return price_; | ||
} | ||
|
||
/// Returns the size of the price level. | ||
double getSize() const { | ||
return size_; | ||
} | ||
|
||
/** | ||
* Sets the size of the price level. | ||
* | ||
* @param size The new price level size. | ||
*/ | ||
void setSize(const double size) { | ||
size_ = size; | ||
} | ||
|
||
/** | ||
* Compares two price levels without taking price into account. | ||
* | ||
* @param pl1 The first price level to compare. | ||
* @param pl2 The second price level to compare. | ||
* @return Returns `true` if the event symbols are not nullptr, are equal, and the sides are equal. | ||
*/ | ||
friend bool operator==(const std::shared_ptr<PriceLevel> &pl1, const std::shared_ptr<PriceLevel> &pl2) { | ||
if (pl1->getEventSymbol() == std::nullopt || pl2->getEventSymbol() == std::nullopt) { | ||
return false; | ||
} | ||
|
||
if (pl1->getEventSymbol() != pl2->getEventSymbol()) { | ||
return false; | ||
} | ||
|
||
return pl1->getSide() == pl2->getSide(); | ||
} | ||
|
||
/// Returns a string representation of this price level. | ||
std::string toString() const { | ||
return "PriceLevel{" + eventSymbol_.value_or(dxfcpp::String::NUL) + ", source=" + eventSource_.toString() + | ||
", side=" + side_.toString() + ", price=" + dxfcpp::toString(price_) + | ||
", size=" + dxfcpp::toString(size_) + "}"; | ||
} | ||
}; |
Oops, something went wrong.