Skip to content

Commit 1dde020

Browse files
committed
Replace slicksocket with boost/beast; Change websocket_proxy_client to header-only
1 parent fbeeef4 commit 1dde020

File tree

272 files changed

+1460
-79881
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

272 files changed

+1460
-79881
lines changed

.gitignore

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@
3232
*.app
3333

3434
.vs
35-
Debug
36-
Release
37-
!dependencies/slicksocket/lib/*
38-
!dependencies/slicksocket/lib/Debug/*
39-
!dependencies/slicksocket/lib/Release/*
35+
.vscode
36+
Debug/
37+
Release/
4038
*.vcxproj.user
39+
log/
40+
build/
41+
cmake_build_debug/
42+
cmake_build_release/

.gitmodules

Lines changed: 0 additions & 3 deletions
This file was deleted.

CMakeLists.txt

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
cmake_minimum_required(VERSION 3.15)
2+
3+
file (STRINGS "version" BUILD_VERSION)
4+
5+
project(websocket_proxy
6+
VERSION ${BUILD_VERSION}
7+
LANGUAGES CXX)
8+
9+
file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/include" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
10+
configure_file(src/version.h.in include/version.h)
11+
12+
set(CMAKE_CXX_STANDARD 20)
13+
14+
if (NOT CMAKE_BUILD_TYPE)
15+
set(CMAKE_BUILD_TYPE Release)
16+
endif()
17+
18+
if (CMAKE_BUILD_TYPE MATCHES Debug)
19+
add_definitions(-DDEBUG)
20+
endif()
21+
22+
if (CMAKE_BUILD_TYPE MATCHES Release)
23+
add_definitions(-DNDEBUG)
24+
endif()
25+
26+
find_package(boost_beast REQUIRED CONFIG)
27+
find_package(OpenSSL REQUIRED)
28+
find_package(spdlog REQUIRED CONFIG)
29+
30+
set(OPENSSL_USE_STATIC_LIBS TRUE)
31+
set(OPENSSL_MSVC_STATIC_RT TRUE)
32+
33+
include(cmake/slick_queue.cmake)
34+
35+
set(HEADERS
36+
include/websocket_proxy/type.h
37+
include/websocket_proxy/websocket_proxy_client.h
38+
)
39+
40+
set(SOURCES
41+
src/main.cpp
42+
src/websocket_proxy.cpp
43+
)
44+
45+
add_executable(websocket_proxy ${SOURCES})
46+
target_include_directories(websocket_proxy PUBLIC include ${slick_queue_SOURCE_DIR}/include ${spdlog_SOURCE_DIR} ${CMAKE_BINARY_DIR})
47+
target_link_libraries(websocket_proxy PRIVATE spdlog::spdlog_header_only Boost::asio Boost::beast OpenSSL::SSL OpenSSL::Crypto)
48+
49+
if (MSVC)
50+
add_definitions(-D_WIN32_WINNT=0x0A00)
51+
set(CMAKE_SUPPRESS_REGENERATION true) # supress zero_check
52+
target_compile_definitions(websocket_proxy PUBLIC _UNICODE) # set CharacterSet to unicode
53+
target_compile_options(websocket_proxy PRIVATE "/bigobj")
54+
set_target_properties(websocket_proxy PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
55+
endif()

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2021 Kun Zhao
3+
Copyright (c) 2021-2024 Kun Zhao
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1-
# ZorroWebsocketProxy
2-
ZorroWebsocketProxy is a C++ WebSocket prroxy framework initally created for Zorro-Trader. It can be used for any application to share one WebSockets connection for multiple application instances.
1+
# WebsocketProxy: Share a Single WebSocket Connection for Multiple Clients (C++)
2+
WebSocketProxy provides a C++ WebSocket proxy framework that empowers you to share a single WebSocket connection among multiple clients, maximizing resource utilization and streamlining real-time data access.
33

4-
## Overview
5-
ZorroWebsocketProxy includes two components: a standalone proxy server excutable and a proxy client static library. The proxy server and client communicate with each other through shared memory ring buffers.
4+
## Built for Efficiency: Serving Multiple Clients with One Connection
5+
Designed initially for the [Alpaca.Market](https://alpaca.markets/), which offers data via both REST and WebSockets. However, Alpaca limits the number of concurrent WebSocket connections per account. WebSocketProxy solves this by enabling multiple strategies under the same account to receive real-tine market data updates through a single, shared WebSocket connection.
66

7-
The proxy server is spawned when the first client trying to open a Websocket. The server makes sure that there is only one server running. If for any reason a second server is launched, it will shut itself down. The proxy server will keeps runing until the last client instances are closed.
7+
## Components and Communication
8+
WebSocketProxy consists of two components:
9+
1. Standalone proxy server executable: This executable acts as the central communication hub. It manages the connection to the WebSocket server and handles data forwarding between clients. It's launched upon the first client attempting a WebSocket connection, ensuring only one server instance runs simultaneously. Any subsequent server launch attempts automatically terminate, preventing resource conflicts. The server continues execution until all connected clients are closed.
10+
2. Header-only Proxy Client: This lightweight client library integrates into your individual applications. It manages communication with the proxy server and provides a familiar interface for sending and receiving data.
811

12+
## Benefits of WebSocketProxy
13+
* Efficient Resource Utilization: Share a single WebSocket connection, reducing overhead and improving resource management.
14+
* Real-Time Data Streamlining: Multiple trading strategies within an account gain access to crucial market updates concurrently.
15+
* Simplified Integration: The header-only client library enables effortless integration with your existing client applications.
16+
* Shared Memory Optimization: Communication between server and clients leverages shared memory ring buffers, ensuring high-performance data exchange.

cmake/CPM.cmake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
set(CPM_DOWNLOAD_LOCATION ${CMAKE_BINARY_DIR}/CPM.cmake)
2+
3+
file(DOWNLOAD
4+
https://github.com/cpm-cmake/CPM.cmake/releases/latest/download/cpm.cmake
5+
${CPM_DOWNLOAD_LOCATION})
6+
7+
include(${CPM_DOWNLOAD_LOCATION})

cmake/slick_queue.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
set(slick_queue_SOURCE_DIR "${CMAKE_BINARY_DIR}/_deps/slick_queue")
2+
file(DOWNLOAD
3+
https://raw.githubusercontent.com/SlickTech/slick_queue/main/include/slick_queue.h
4+
${slick_queue_SOURCE_DIR}/include/slick_queue.h)

dependencies/slick_queue

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)