|
| 1 | +# Introduction |
| 2 | + |
| 3 | +Xapi-cpp is a C++ library that provides a simple and easy-to-use API for interacting with the xStation5 trading platform. |
| 4 | +Built on top of the Boost libraries, it leverages Boost’s powerful and widely adopted capabilities, particularly for network-based applications. Boost provides robust, high-performance abstractions that simplify the development of complex asynchronous operations, making it an ideal choice for ensuring a reliable and efficient connection to the xStation5 platform. |
| 5 | + |
| 6 | +## Key Concepts |
| 7 | + |
| 8 | +### 1. Asynchronous Programming with Coroutines |
| 9 | +The library makes heavy use of C++20 coroutines and Boost.Asio to handle asynchronous operations. Each API call is suspended until the operation completes, allowing the program to remain responsive and efficient. |
| 10 | + |
| 11 | +While C++20 provides the coroutine syntax (``co_await``, ``co_return``, ``co_yield``), it doesn’t define a complete framework for asynchronous execution or I/O. Libraries like Boost.Asio provide the necessary abstractions and asynchronous I/O handling that C++20 coroutines on their own do not. |
| 12 | + |
| 13 | +### 2. Secure WebSocket Communication |
| 14 | +The xapi uses secure WebSockets (WebSockets over SSL) for communication, ensuring that the data transmitted between the client and server is encrypted. This provides a secure channel for sensitive information, such as account credentials and balance data. |
| 15 | + |
| 16 | +### 3. Separate WebSocket Connections |
| 17 | +The xapi establishes separate WebSocket connections for **xapi::Socket** and **xapi::Stream**. This separation aims to minimize congestion on a single connection especially if one connection is handling high-frequency data (like streaming). |
| 18 | + |
| 19 | + |
| 20 | +# Getting Started |
| 21 | +Let`s break down some important steps to start using xStation in your project |
| 22 | + |
| 23 | +## Awailable operations |
| 24 | +### 1. Socket Operations |
| 25 | +The **xapi::Socket** object is used to Request-Reply commands. Full list of commands is in [xApi Retrieving Trading Data](http://developers.xstore.pro/documentation/2.5.0#retrieving-trading-data) |
| 26 | + |
| 27 | +### 2. Stream Operations |
| 28 | +The **xapi::Stream** object is used to manage real-time streaming data, such as balance updates, tick prises and so on. Full list of streaming operations is in [xApi Available Streaming Commands](http://developers.xstore.pro/documentation/2.5.0#available-streaming-commands) |
| 29 | + |
| 30 | +Please note, that to use streaming operations, you first should get streaming id from **xapi::Socket** login() command. |
| 31 | + |
| 32 | +## Cmake configuration |
| 33 | +Xapi supports ``find_package``, simplifying the process of linking the library to your project. A typical CMake configuration might look like this: |
| 34 | + |
| 35 | +```cmake |
| 36 | + cmake_minimum_required(VERSION 3.10) |
| 37 | + project(ExampleApp) |
| 38 | +
|
| 39 | + set(CMAKE_CXX_STANDARD 20) |
| 40 | + set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 41 | +
|
| 42 | + find_package(Xapi REQUIRED) |
| 43 | +
|
| 44 | + add_executable(ExampleApp main.cpp) |
| 45 | +
|
| 46 | + target_link_libraries(ExampleApp |
| 47 | + PRIVATE |
| 48 | + Boost::system |
| 49 | + Boost::json |
| 50 | + Xapi::Xapi |
| 51 | + ) |
| 52 | +``` |
| 53 | + |
| 54 | + |
| 55 | +## Simple example |
| 56 | +The simplest example is [RetrieveStreamSessionId](RetrieveStreamSessionId.cpp), which demonstrates how to connect to an xStation server using Xapi. The program initializes a session, logs in, and retrieves a stream session ID. |
| 57 | + |
| 58 | +Additional examples can be found in the .cpp files within the examples folder. |
| 59 | + |
| 60 | +## Compile examples |
| 61 | +You can compile all examples by following these steps: |
| 62 | + |
| 63 | +1. Fix your credentials in the example you want to use. In ``run`` function: |
| 64 | + |
| 65 | + ```cpp |
| 66 | + const std::string accountId = "<your accountId>"; |
| 67 | + const std::string password = "<your password>"; |
| 68 | + |
| 69 | + // If you are using real account, replace with "real" |
| 70 | + const std::string accountType = "demo"; |
| 71 | + ``` |
| 72 | + |
| 73 | +1. Create a `build` directory and navigate into it: |
| 74 | + |
| 75 | + ```bash |
| 76 | + mkdir build |
| 77 | + cd build |
| 78 | + ``` |
| 79 | + |
| 80 | +2. Run CMake to configure and build the project: |
| 81 | + |
| 82 | + ```bash |
| 83 | + cmake .. |
| 84 | + cmake --build . |
| 85 | + ``` |
| 86 | + |
| 87 | +3. Binaries will be stored in ``bin`` directory. Run example app that you want (f.e. RetrieveStreamSessionId) |
| 88 | + ```bash |
| 89 | + ./bin/RetrieveStreamSessionId |
| 90 | + ``` |
0 commit comments