API

Warning
The API and risk server is currently undergoing maintenance for the release of a new version. Meanwhile feel free to try out API v0.1, but expect occasional downtime.
API

X-Margin Mark to Market API

X-Margin provides free live market data that allows traders to mark to market any BTC option, future, or forward within a given range. X-Margin has interpolated live market data from Deribit’s public API, to create a 3D Volatility Surface that lines up with the current mark prices as much as possible, and also uses futures prices and synthetics of options contracts to create a forward curve.

Therefore a client can price any option or forward within that range. This is one example of an OTC mark to market feed, and we can customize any asset class, any fitting methodology and data source (see below for a 3D volatility surface example).

  • API v0.1 Documentation

    X-margin currently offers two websocket subscriptions for user acceptance testing

    • Implied volatility and price based on our risk engine
    • Forward curve
  • Endpoint: ws://api.xmargin.io (port 5000)
  • Naming

    Futures are named CURRENCY-DDMMYY, e.g.

    • BTC-06OCT2019
    • BTC-27DEC19

    Options are named CURRENCY-DDMMYY-STRIKE-TYPE

    • BTC-06SEP19-12000-C
    • BTC-27SEP19-12000-P

    Perpetuals are named CURRENCY-PERPETUAL

    • BTC-PERPETUAL
  • Request format

    Subscriptions have the following request format:

    {

    “action” : “subscription type”,

    “instruments” : [

    {“instrument_name” : “INST 1”},

    …,

    { “instrument_name” : “INST N” },

    ]

    }

     

    Subscriptions to the iv feed:

    request = {

    “action” : “vol”,

    “instruments” : [

    {“instrument_name” : “BTC-06SEP-12000-C”},

    {“instrument_name” : “BTC-27DEC-12000-C”}

    ]

    }

     

    Subscriptions to the forward curve feed:

    request = {

    “action” : “fwd”,

    “instruments” : [

    {“instrument_name” : “BTC-PERPETUAL”},

    {“instrument_name” : “BTC-06OCT19””},

    {“instrument_name” : “BTC-06DEC19””}

    ]

    }

  • Response format

    The response format for forward curve subscriptions given by example:

    {

    “data”: [

    {

    “forward_price”: 9444.0,

    “instrument_name”: “BTC-PERPETUAL”

    },

    {

    “forward_price”: 9482.0,

    “instrument_name”: “BTC-06OCT19”

    },

    {

    “forward_price”: 9582.0,

    “instrument_name”: “BTC-27DEC19”

    }

    ],

    “type”: “forward”

    }

     

    The response format for implied volatility subscriptions given by example:

    {

    “data”: [

    {

    “atmf_imp_vol”: 0.8667,

    “imp_price”: 0.0262

    “imp_price_usd”: 248.0316,

    “imp_vol”: 0.8383,

    “instrument_name”: “BTC-06SEP19-10000-C”

    },

    {

    “atmf_imp_vol”: 0.8482,

    “imp_price”: 0.12633,

    “imp_price_usd”: 1197.17,

    “imp_vol”: 0.8366,

    “instrument_name”: “BTC-27SEP19-10000-P”

    }

    ],

    “type”: “vol”

    }

    where atmf_imp_vol refers to the ATM forward volatility corresponding to the expiry of the given option.

  • Example

    Implied volatility subscription:

     

    import json

    import asyncio

    import websockets

    import time

    request = {

    “action” : “vol”,

    “instruments” : [

    {“instrument_name” : “BTC-06SEP19-10000-C”},

    {“instrument_name” : “BTC-27SEP19-10000-P”}

    ]

    }

    async def iv_feed():

    async with websockets.connect(‘ws://api.xmargin.io:5000’) as websocket:

    await websocket.send(json.dumps(request))

    while True:

    msg = await websocket.recv()

    print(json.dumps(json.loads(msg), indent=4, sort_keys=True))

     

    asyncio.get_event_loop().run_until_complete(iv_feed())

     

    Forward curve subscription:

    request = {

    “action” : “fwd”,

    “instruments” : [

    {“instrument_name” : “BTC-PERPETUAL”},

    {“instrument_name” : “BTC-06OCT19”},

    {“instrument_name” : “BTC-27DEC19”},

    ]

    }

     

    async def forward_curve():

    async with websockets.connect(‘ws://api.xmargin.io:5000’) as websocket:

    await websocket.send(json.dumps(request))

    while True:

    msg = await websocket.recv()

    print(json.dumps(json.loads(msg), indent=4, sort_keys=True))

     

    asyncio.get_event_loop().run_until_complete(forward_curve())