# Price Formulation

To ensure transparent and accurate pricing for trading games, Betfury utilizes a composite index price that is calculated every 500 milliseconds. This index is derived from real-time price feeds from the most liquid spot and derivative cryptocurrency exchanges globally. By aggregating data from multiple sources, the Betfury index remains resilient to market manipulation, technical disruptions, and other irregular trading behavior that may arise on individual exchanges.

This approach enables Betfury to provide fair and reliable pricing to its users, fostering a trustworthy and secure trading environment.

##### The calculation steps are as follows:

- Subscribe to as many levels of depth as available using each exchange's streaming APIs.
- Remove any price feeds for which there have been no market data updates for the last 30 seconds
- Remove any price feeds with crossed buy and sell prices or whose top-of-book mid-price is more than 10% away from the median top-of-book mid-price across all price feeds.
- Wait until there are at least 6 valid price feeds. If there are not enough price feeds, the BetFury index price will not be updated.
- Combine all resting limit orders from each price feed into a single composite order book. It is okay and expected that the price of some buy orders will exceed the price of some sell orders from other exchanges. Individual order sizes are capped to $1 million to limit the influence of a single large order.
- Using the composite order book, a function is defined to represent the marginal price to buy or sell a given amount. For example, the marginal buying function is:

P_buy(s) = max{ґp_i | sum_{i in 1..N}{s_i} <= s}

where p_i | i in 1..N and s_i | i in 1..N are the buy prices and sizes sorted in increasing distance from the top-of-book. This function gives the maximum price one would pay to buy an amount s. - The marginal buy and sell price functions are then used to define a marginal mid-price function given a size:

P_mid(s) = (P_buy(s) + P_sell(s)) / 2 - The final index price is then calculated as the weighted average of the marginal mid-prices at each size. The weights are chosen to be the probability density of the exponential distribution, which is monotonically decreasing, resulting in a higher emphasis on prices closer to the top-of-book. The weights are given by:

w_i = L * exp(-L * v_i)

Where v_i are the sizes at which the mid-prices are calculated and are defined as the union of the cumulative buy and sell sizes from the composite order book. L is a scaling factor defined as 1 / V, where V is the maximum size at which a mid-price is calculated and is defined as the minimum of the sum of buying and selling sizes in the composite order book.

The output of this calculation is a single index price that is used for both long and short bets in the BetFury trading game. Unlike with most other trading platforms, BetFury does not charge a bid-offer spread. Trading with a single price makes it possible to speculate on short-term price moves for which a bid-offer spread would be prohibitively expensive.

### Liquidation and Stop-Loss Price

Regardless of liquidity on underlying markets, we guarantee that take-profit and stop-loss orders will be executed at the price predetermined upon entry. The liquidation amount is limited to the initial bet amount, and stop-loss orders are limited by user settings.

Initial prices for liquidation and stop-loss can be calculated using:

P_trigger = P_close * (1 + trade_sign*risk_buffer)

where P_close is the liquidation or stop-loss price of P_open*(1 - 1/bet_multiplier). risk_buffer is a set of parameters based on current market conditions. Its current value can be found here.

### Market Impact Effect

P_close(T) = P(t) + ((1 - base_rate) / (1 + 1/abs((P(T)/P(t) - 1)*rate_multiplier)^rate_exponent + bet_amount*bet_multiplier/(10^6*abs(P(T)/P(t) - 1)*position_multiplier)))*(P(T) - P(t))

The parameters of the formula are set based on current market conditions, and their current values can be found here.