Task: implementation of the fastest possible calculation and opening of an order on the ByBit exchange
Data preparation
Parsing all tokens on the ByBit exchange (spot / futures, separately), the list is updated every 5 minutes by cron.
Connecting via socket to each coin and collecting real-time ticks (order book changes) and trades.
Sending all this to Victoria Metrics, data up to 5 minutes – stored in RAM
Separately for spot, separately for futures we collect the current order book independently by ticks
Data calculation for the trade
Calculating the price change dynamics by VOLUME.
For this, we calculate the average price for asks (for opening a long) in equivalent volumes:
1,000$, 5,000$ (step in the form of an array to be set in the settings)
Comparing with the average value of trades over the last 60 and 300 seconds
Comparing with the average value of asks (for the same volume) from the order book history.
As a result, we get an array [price_difference_60s]
1000$ - 5.86%
5000$ - 6.12%
We check if at a volume of 1000$ the delta in price is less than 10% (PRICE_CHANGE_DELTA_60S = 10), then we continue the logic/purchase.
Calculating slippage data to determine size.
Using the specified constant (MAX_SLIPPAGE_PERCENT = 5) we add asks line by line until we reach the required limit of >5%
Multiplying volume by price in the order book to calculate the available volume in the order book considering the maximum slippage.
Using the variable from the config (MAX_POSITION_SIZE_IN_USD = 10000) for the final size calculation. For example, in the order book, the available volume at the ask is 8500$ with slippage <5%, so this is our position size of 8500$, if the available volume >10000$, then our position size will be 10,000$ (taken from MAX_POSITION_SIZE_IN_USD)
Opening a trade
Sending limit orders via websocket and through the REST API at the ask price +5% (taken from MAX_SLIPPAGE_PERCENT) and the IOC (immediate or cancel) parameter.
Along with the order, a stop loss/take profit is set at 33% of the size for growth +10%, +20%, +30%
The stop loss is set at -10% from the first ask in the order book.
Passing order orderLinkId and "smpType": "CancelTaker" for the correct operation of the script when running in parallel on multiple servers.
It is important to think through the reconnection, retries, logs, and alerts system
Warm_up_mode, send a “fake” order to the exchange every 30 seconds to maintain activity.
System for generating JA3 fingerprints
The task is not simple, requires full involvement, so if you have a couple of hours a day - it is not suitable. A person with full immersion in the issue is needed.