A simple Websocket Server/Client template that converts Tick Data into OHLCV Renko via Websockets!
In-depth overview
Everything starts with a GET request, which the user enters the renko parameters into the url:
localhost:9000/client/{symbol}/{brickSize}
The WebSocketClient will open a connection to simulator server, while the symbol and brickSize are stored in SessionService.
Every message came from simulator will be transfered to reactive RenkoChartService, send to 3 producers (normal-in-memory
, wicks-in-memory
, nongap-in-memory
) a dynamic topic with the following pattern:
new renko: {symbol}_{mode}
forming renko: {symbol}_{mode}_forming
ex: us30_normal, eurgbp_wicks, us500_nongap
NOTE: The forming renko topics are not actually sent because a suitable frontend hasn't been created yet.
Maybe in the future using Server-Sent-Events (SSE).
The WebsocketServer will receive a connection following the pattern:
ws://localhost:9000/renko/{symbol}/{mode}
The symbol must be the same as that given in the GET request, otherwise the consumer will read an empty non-existent topic.
We have 2 "types" of consumers:
- 3 Static consumers: Once time inicialized, will never be closed until the application shutdown.
- nº Dynamic consumers: Created as needed, can be closed due inactivity a.k.a empty sessions, every 30min.
The Group ID of each consumer are identify by renko mode [normal
, wicks
, nongap
] which reads the respective channel/topic.
Both consumers will have the topic updated if they have empty sessions and a new connection with the same Group ID (renko mode) is made.
Example:
Consumer nongap-0, topic us30_nongap, total sessions: 1
*session disconnect*
Consumer nongap-0, topic us30_nongap, total sessions: 0
*new connection to us500_nongap*
Using an existing empty session consumer of group nongap to topic us500_nongap
*change the topic*
Consumer nongap-0, topic us500_nongap, total sessions: 1
The application can be run in:
Dev mode
In root path:
1º Start simulator.
./mvnw -f simulator compile quarkus:dev
2º Start creator.
./mvnw -f creator compile quarkus:dev
Thanks to Quarkus Dev Services, a Kafka broker is started automatically from a container.
Packaged running locally (or Docker)
In root path:
1º package simulator and creator.
./mvnw -f simulator package
./mvnw -f creator package
NOTE: Before packaging creator, you'll need to change 2 properties in application.properties to:
%prod.kafka.bootstrap.servers=localhost:9092
%prod.creator.client.simulator.url=localhost:8080/ticks.
If running on Docker, no changes are needed.
2º We need start a Kafka broker manually by ourselves, so using Docker, let's iniciate the kafka-compose.yaml:
docker compose -f kafka-compose.yaml up -d
3º Run the packages!
java -jar simulator/target/quarkus-app/quarkus-run.jar
java -jar creator/target/quarkus-app/quarkus-run.jar
Afte 1º just do:
docker compose up -d
Native executable running locally (or Docker)
In root path:
1º package simulator and creator.
./mvnw -f simulator package -Dnative -Dquarkus.native.container-build=true
./mvnw -f creator package -Dnative -Dquarkus.native.container-build=true
NOTE: Before packaging creator, you'll need to change 2 properties in application.properties to:
%prod.kafka.bootstrap.servers=localhost:9092
%prod.creator.client.simulator.url=localhost:8080/ticks.
If running on Docker, no changes are needed.
2º We need start a Kafka broker manually by ourselves, so using Docker, let's iniciate the kafka-compose.yaml:
docker compose -f kafka-compose.yaml up -d
3º Run the packages!
./simulator/target/simulator-0.0.1-runner
./creator/target/creator-0.0.1-runner
Afte 1º just do:
docker compose -f native-compose.yaml up -d
After choose your prefered way, and once time that all things are on:
1º: Connect multiples websocket clients with the proper chart logic to renko server (see python folder):
- ws://127.0.0.1:9000/renko/US30/
{mode}
- ws://127.0.0.1:9000/renko/EURGBP/
{mode}
{mode}
can benormal
,wicks
ornongap
2º: a GET requisition from browser by acessing the following urls: