Sunday, January 13, 2019

How does the perpetual XBTUSD contract works? An intuitive guide

This is a basic explanation of how the XBTUSD perpetual contract works; it's meant to illustrate the intuition behind it and some of the details you might have to ask. It's not exhaustive, it only useful intuitions.

Bitmex accepts Bitcoin only, and settle contracts in BTC, so you only own, gain or loses Bitcoin, but you trade or gamble in other cryptocurrencies.

The XTBUSD Perpetual contract

You have an amount of BTC. You want this amount to grow in the same way as the price of BTC-USD (when you buy the contract) or in the opposite direction (when you sell the contract).

Each contract is worth 1USD, so When you buy 1 contract @3610.0 it means you have to pay 1 USD worth of bitcoin at the price you specified. When you sell the contract instead you receive 1USD woth of BTC at the price you sold at. The same is true if you sell before buying.

Note that you are buying contracts and not USD or BTC; so how does it guarantee that the price of the contract will follow the price of BTC-USD? With the Funding Rate

Funding Rate

https://www.bitmex.com/app/perpetualContractsGuide#Funding The price of the contract might differ from the price of BTC-USD. The price of BTC-USD is distilled into an index (.BXBT)[https://www.bitmex.com/app/index/.BXBT] which is the average of BTC-USD from other exchanegs. This is the 'price of BTC' and is usually slightly different from the 'price of the contract'. When the price of the contract is less than price of BTC, users with a long position get paid the funding rate so you have an incentive to buy the contracts, this push up the price of the contract thus realigning the price of the contract with the price of BTC-USD. At the same time users with short position will pay the same amunt of funding rate, so they have an incentive to reduce their position (by buying contracts), and this also tend to push up the price of the contract to match the price of BTC.

When the price of the contract is more than the price of BTC, the opposite happens: users with long position pays users with short position, this gives an incentive to sell the contract, pushind down its price to be closer to the price of BTC.

The amount of funding rate you receive or pay is proportional to the difference between the price of the contract and the price of BTC. The funding rate is given every 8 hours, and it's computed as an average over the last 8 hours (TWAP) of the difference between price of XBTUSD and .BXBT. The actual computation is more complex and out of the scope of this article, until someone find an intuitive way to describe it. You'll find examples here.

When if the funding rate charged?

The funding rate is charged at 4:00UTC, 12:00UTC and 20:00UTC every day. The funding rate is also published with an 8-hour grace period before it is charged https://blog.bitmex.com/xbtusd-funding-mean-reversion-strategy/. What does it means?

Let's take an example from 13/01/2019 at about 16:40UTC, the detail page https://www.bitmex.com/app/contract/XBTUSD says:

name value
Funding Rate -0.0230%
Next Funding Jan 13, 2019, 8:00:00 PM
Predicted Rate 0.0003%

At Jan 13, 2019, 20:00:00, the funding rate will be -0.0230%, meaning shorts will pay long 0.023% of their open position. This happens only among those users which have an open position at Jan 13, 2019, 20:00:00 . This funding rate has been computed as an average over time of the difference between the price of the XBTUSD contract and .BXBT, during the period (Jan 13, 2019, 12:00:00 - Jan 13, 2019, 16:00:00). (All times are UTC) Also the Predicted Rate is 0.0003%, which is computed during the period (Jan 13, 2019, 12:00:00 - Jan 13, 2019, 20:00:00) and will be paid at Jan 14, 2019, 04:00:00. This is 'predicted' because the period of computation has not finished yet, so this rate might still change.

The current price of the contract and .BXBT will not affect the next funding rate you get, but the one after that.

Note also that the funding rate is not per day, but per 8 hours period. To know which % you pay per day you have to sum 3 consecutive funding rates.

This means you can think of strategies to speculate on the funding rate and not on the price of BTC-USD itself; for example looking at (https://midascapital.eu/2018/08/03/the-xbtusd-perpetual-swap-contract/)[https://midascapital.eu/2018/08/03/the-xbtusd-perpetual-swap-contract/].

API Trades Explanation

How does an API trade messages look like? When a trade happens on the exchange you will receive a JSON message like this throught the websocket or REST API:

'{"timestamp":"2018-12-14T17:04:27.127Z","symbol":"XBTUSD","side":"Sell","size":5,"price":3170.5,"tickDirection":"MinusTick","trdMatchID":"15cdac8e-ccdc-5d4b-1300-a0899574239d","grossValue":157705,"homeNotional":0.00157705,"foreignNotional":5}'

Let's break it down:

{ "timestamp":"2018-12-14T17:04:27.127Z", // When the trade happened according to bitmex server timestamp "symbol":"XBTUSD", // which contract is this "side":"Sell", // The taker side; 'Sell' means someone sent and order to buy and didn't get mathced immediately; at this timestamp someone decided to match the offer and sell to them. "size":5, // How many contracts; just for convenience you can think of these as USD "price":3170.5, // pride of the contract "tickDirection":"MinusTick", // This trade happened at a price lower than the previous one "trdMatchID":"15cdac8e-ccdc-5d4b-1300-a0899574239d", // ID of this trade. It should always be unique. "grossValue":157705, // How many sathoshi were exchanged == 5/3170.5*100000000 "homeNotional":0.00157705, // How many BTC was this trade worth "foreignNotional":5 // How many USD was this trade worth } 

If any of these field seems irrelevant or trivial, please note that they are much less trivial for the ETHUSD contract.

I will happily add or change details if they helps simplifying the explanation.

EDIT: see also the intuitivo guide to ETHUSD.



No comments:

Post a Comment