The bot evaluates the last 1000 trades for both base/rel and rel/base pairs (up to 2000 total).
VWAP Calculation:
For each pair, the VWAP is computed by taking the sum of the product of each trade's price and volume (sum(price * volume)) and dividing it by the total volume (sum(volume)).
When calculating the VWAP for the reverse pair (rel/base), the bot considers its own base asset as the reference, and it gets the price for the base asset.
Combines/sums the separate VWAPs for base/rel and rel/base trades into a total VWAP.
Price Comparison:
Compares total VWAP to the bot's calculated price (price from price service * spread).
If VWAP > calculated price, uses VWAP for order price.
Liquidity Adjustment:
By setting the price of one pair to the VWAP price, the bot adjusts market maker orders above the market rate for one direction to encourage trades in the opposite direction, addressing temporary liquidity imbalances until equilibrium is restored.
Future improvements could include:
Adjusting the VWAP by balancing the difference through buying from a CEX.
Including these CEX purchases in VWAP calculations.
Defining a threshold (e.g., 60%/40%) for triggering a CEX buy to balance the pair.
Trade Analysis:
VWAP Calculation:
sum(price * volume)
) and dividing it by the total volume (sum(volume)
).Price Comparison:
Liquidity Adjustment:
Future improvements could include: