AZOTHX trading engine: how trades are executed
A full description of the AZOTHX trading engine: where prices come from, how orders are executed, and how fees, positions, margin, liquidation and funding are calculated. All formulas are open — you can recalculate any figure yourself.
1. What the trading engine is
The trading engine is the AZOTHX exchange where trades are executed. It follows the rules of Bybit USDT perpetual contracts and executes trades at live Bybit quotes.
- One set of rules for everyone — the engine does not know who is trading and has no settings tailored to a specific trader. Price, fees and formulas are identical for every account.
- The prices are not ours — quotes come directly from the public Bybit API. The engine cannot change the price, widen the spread or delay execution.
- It works without you — the engine watches the market continuously, even when the terminal is closed.
- Everything is recorded — every trade, fee, funding payment and account event is saved and visible to you in your account area.
2. Where prices come from
The engine uses three prices for each Bybit contract — the same ones you see on the exchange.
| Price | What it is | What it is used for |
|---|---|---|
| Best bid / ask | The best buyer and seller price in the Bybit order book | Execution of market and limit orders |
| Last | The price of the most recent trade on Bybit | Triggering of conditional orders, trailing stop, TP/SL (by default) |
| Mark | Bybit’s fair price, smoothed by the index of spot exchanges | Unrealized PnL, equity, liquidation, TP/SL and conditional orders when this price is chosen |
- Live stream — for coins that are open in the terminal or have positions and orders, prices arrive over the Bybit WebSocket and are no older than 50 ms.
- Other coins — quotes for lists and summaries are refreshed by one request to the Bybit API once a second. They do not affect execution: as soon as a coin has a position or an order, it switches to the live stream.
- If Bybit is unavailable — the engine uses the last received prices for 15 seconds and then halts execution: without fresh quotes, no trade, liquidation or rule check is performed.
As on Bybit, liquidation goes by the mark price, so a brief spike of the last price does not liquidate a position by itself. But, as on the exchange, wicks do hit orders: limit orders fill against the order book, while conditional orders, the trailing stop and TP/SL trigger on the last price by default.
3. How orders are executed
Market order
A buy is executed at the best Bybit ask and a sell at the best bid, with the whole size at a single price. The engine does not “walk” the order book: even a large market order gets the best price, with no additional slippage.
Limit order
- Crosses the market — a buy at or above the ask or a sell at or below the bid fills at once at the best price, as a taker order.
- Rests in the book — otherwise the order waits and fills in full at its own price as a maker order: a buy once the ask comes down to its price or lower, a sell once the bid rises to it or higher.
Conditional order
It waits until the last or mark price (your choice) crosses the trigger price. After triggering, a market order is executed at the best price, and a limit order at its own price with the taker fee.
Rounding and limits
- Size — rounded down to the Bybit contract lot step, price — rounded down to the price step. A size below the minimum lot is not accepted.
- Maximum — a market order is subject to the Bybit contract's maximum size, and the value of a single position may not exceed $10,000,000.
- Reduce-only — the order only reduces a position and never opens a new one.
- An order that cannot be executed (insufficient margin, nothing to close) is rejected with a reason and does not affect other orders.
4. Fees
Fees are the same as on Bybit for USDT perpetual contracts and are deducted from the balance at the moment of execution.
| Execution type | Rate | When |
|---|---|---|
| Taker | 0.055% | Market orders, limit orders filled immediately, triggering of TP/SL, trailing and conditional orders, closing by rules |
| Maker | 0.02% | A limit order that rested in the order book and was filled when the market reached its price |
Fee = size × execution price × rateExample: buying 0.1 BTC at market at a price of $60,000 — value $6,000, fee 6,000 × 0.055% = $3.30.
There is a fee both when opening and when closing a position. Both are visible in every row of the “Trades” tab.
5. Position and PnL
There is one position per coin — long or short (one-way mode, as on Bybit). New trades are combined with it.
- Adding in the same direction — the position grows and the entry price becomes the weighted average.
- A trade in the opposite direction — first closes the position (fully or partially) and realizes the profit or loss. If the size is larger than the position, the remainder opens a new position in the other direction.
New entry price = (size₁ × entry₁ + size₂ × entry₂) / (size₁ + size₂)
Long PnL = (price − entry) × size
Short PnL = (entry − price) × size
ROE = PnL / initial margin- Unrealized PnL — at the mark price, while the position is open.
- Realized PnL — at the execution price of the closing trade; together with fees it changes the balance.
Equity = balance + unrealized PnL of all open positions6. Margin and leverage
Margin is isolated: each position risks only its own margin, and the rest of the balance is not affected.
Initial margin (IM) = entry price × size / leverage
Position margin = IM + closing fee at the bankruptcy price- Leverage — chosen separately for each coin, 10x by default. The maximum is the lesser of 100x and the contract limit on Bybit; for large positions the limit is lower, following Bybit's risk limit tiers.
- Closing fee — reserved in advance, so even a liquidation cannot take more than the position's margin.
How much free funds you need
For a market order = value / leverage + value × 0.055%
For a limit order in the order book = value / leverage + value × 0.055% × 2
Available = balance − position margin − margin of orders in the order bookA limit order reserves the fee for both opening and closing, so that it definitely has enough margin when it is filled.
Changing leverage with an open position
The position margin is recalculated: lowering leverage requires free funds, raising it releases them. You cannot raise leverage so that the position immediately ends up beyond its liquidation price.
7. Liquidation
Liquidation replicates Bybit's mechanics. Maintenance margin (MM) is taken from Bybit's risk limit tiers for the coin: the MMR rate and the deduction depend on the position value.
MM = position value × MMR − deduction
Bankruptcy price: long = entry − IM / size; short = entry + IM / size
Liquidation price: long = entry − (IM − MM) / size; short = entry + (IM − MM) / size- When it fires — the mark price reached the liquidation price. Checked on every price move, before TP/SL and any other rule.
- What happens — the position is closed at the bankruptcy price and you lose the position margin: IM and the reserved closing fee. Not a cent beyond it — the rest of the balance is not affected.
- Where to see it — the liquidation price is shown in the positions table and as an orange line on the chart.
| Example: long 1 BTC at $60,000, leverage 10x, MMR 0.5% | Value |
|---|---|
| Position value | $60,000 |
| Initial margin (IM) | 60,000 / 10 = $6,000 |
| Maintenance margin (MM) | 60,000 × 0.5% = $300 |
| Liquidation price | 60,000 − (6,000 − 300) / 1 = $54,300 |
| Bankruptcy price | 60,000 − 6,000 / 1 = $54,000 |
| Closing fee | 1 × 54,000 × 0.055% = $29.70 |
| Position margin — maximum loss | $6,029.70 |
The MMR rate in the example is illustrative: the calculation always uses the current Bybit tier for the coin and position size.
8. Funding
Funding is charged at the real Bybit rates and at the same moments as on the exchange (usually every 8 hours, more often for some contracts).
Funding = size × mark price at the time of payment × rate- Direction — with a positive rate, longs pay shorts; with a negative rate, shorts pay longs.
- Price — the Bybit mark price at the minute of payment.
- Each payment once — even if the server was restarted, missed payments are caught up and none is ever charged twice.
- Where to see it — the “Funding” tab: time, coin, size, mark price, rate and amount of each payment.
The rate of any payment can be checked against Bybit's funding history for the same coin and time.
9. TP/SL and trailing stop
- Take profit and stop loss — trigger when the last price (default, as on Bybit) or the mark price reaches the level. The whole position is closed at market: a long at the bid, a short at the ask.
- Level validation — a long's take profit must be above the entry price (or the market) and its stop below; for a short, the reverse.
- Trailing stop — follows the last price. If an activation price is set, it turns on when the market reaches it. After that, the engine remembers the best price and closes the position at market on a pullback of the specified distance.
Trailing stop: long = best price − distance; short = best price + distanceWhen a position is closed, its reduce-only orders are cancelled automatically, as on the exchange.
10. How the engine watches positions and orders
The engine watches accounts continuously — whether or not the terminal is open.
- In memory — for every position and order the engine keeps its levels: the liquidation price, TP/SL, the trailing stop, the trigger and fill prices of orders.
- On every price move — the coin's quotes are checked against these levels within 100 ms.
- When a level is reached — the account is processed in one transaction under a lock: funding and liquidation first, then TP/SL and the trailing stop, then orders. Either all changes apply or none.
- Funding — is booked right after each settlement on Bybit.
- Safety net — once a minute every account with positions or orders is checked in full, even if no level was reached.
11. How to verify any figure yourself
The engine hides nothing: everything that makes up an account's result is visible in your account area and the terminal.
- Trades — each execution has a time, price, size, fee, taker or maker flag and realized PnL. Compare the price with the Bybit bid and ask at the same second.
- Funding — each payment has a mark price and a rate: compare with Bybit's funding history.
- Positions — entry price, margin, liquidation and bankruptcy prices: recalculate them using the formulas in this guide.
If a figure does not match the calculation, write to support with the account number and a platform error will be corrected.
12. How the engine differs from an exchange
The engine copies Bybit's rules but is not an exchange with its own order book. The differences, stated honestly:
- No order book impact — your order does not move the Bybit price, and a market order of any size is executed at the best price. On an exchange, a large order would walk through several order book levels.
- Limit orders without a queue — a limit order is filled in full as soon as the best bid or ask reaches its price; on an exchange it could wait in the queue or be filled partially.
- Speed — every price move is checked within 100 ms; on the exchange, orders execute at the very moment of the trade.
- Liquidation without auto-deleveraging — a position is always closed at the bankruptcy price; the insurance fund and ADL are not applied.
These differences are identical for everyone and do not depend on whether you are in profit or loss.
13. Questions about the trading engine
Can AZOTHX move the price against me?
No. Prices come from the public Bybit API, and the engine has no settings that change the price, spread or execution speed for an individual account.
Is there slippage?
Only the natural kind: a market order is executed at the best Bybit bid or ask at the moment of execution. The engine adds no additional slippage.
Why does the execution price differ from the last price on the chart?
A buy is executed at the ask and a sell at the bid, while the chart shows the price of the last trade. The difference between them is the Bybit spread.
Why was my position liquidated even though the last price did not reach the liquidation price?
Liquidation, as on Bybit, looks at the mark price, not the last price. The mark price is shown in the top bar of the terminal.
What happens if Bybit stops responding?
The engine halts execution and rule checks until quotes return. Trades at stale prices are not executed.