Position Channel

Channel Update Frequency : real-time, on position update

The websocket will reply with the shown success response format for each position channel which has been successfully subscribed to.

If a subscription has been made to position:all, the data array in the message from this position channel will contain a JSON list. Each JSON will contain position details for a different instrument. Otherwise the data array will contain a single JSON corresponding to one instrument.

Curl

Request format

{
  "op": "subscribe", 
  "args": ["position:all"], 
  "tag": 102
}

OR

{
  "op": "subscribe",
  "args": ["position:BTC-USD-SWAP-LIN", "position:BCH-USD-SWAP-LIN", ........], 
  "tag": 102
}

Success response format

{
  "success": True, 
  "tag": "102", 
  "event": "subscribe", 
  "channel": "<args value>", 
  "timestamp": "1607985371401"
}

Position channel format

{
  "table": "position",
  "accountId": "<Your account ID>",
  "timestamp": "1607985371481",
  "data":[ {
              "instrumentId": "ETH-USD-SWAP-LIN",
              "quantity" : "0.1",
              "lastUpdated": "1616053755423",
              "contractValCurrency": "ETH",
              "entryPrice": "1900.0",
              "positionPnl": "-566.80",
              "estLiquidationPrice": "0",
              "margin": "0",
              "leverage": "0"
            },
            {
              "instrumentId": "ETH-USD-SWAP-LIN",
              "quantity" : "50.54",
              "lastUpdated": "1617099855968",
              "contractValCurrency": "ETH",
              "entryPrice": "2000.0",
              "positionPnl": "1220.9494164000000",
              "estLiquidationPrice": "1317.2",
              "margin": "0",
              "leverage": "0"
            },
            ...
          ]
}
Python

Request format

import websockets
import asyncio
import time
import hmac
import base64
import hashlib
import json

api_key = ''
api_secret = ''
ts = str(int(time.time() * 1000))
sig_payload = (ts+'GET/auth/self/verify').encode('utf-8')
signature = base64.b64encode(hmac.new(api_secret.encode('utf-8'), sig_payload, hashlib.sha256).digest()).decode('utf-8')

auth = \
{
  "op": "login",
  "tag": 1,
  "data": {
           "apiKey": api_key,
           "timestamp": ts,
           "signature": signature
          }
}
position = \
{
  "op": "subscribe", 
  "args": ["position:all"], 
  "tag": 102
}

url= 'wss://api.ox.fun/v2/websocket'
async def subscribe():
    async with websockets.connect(url) as ws:
        while True:
            if not ws.open:
                print("websocket disconnected")
                ws = await websockets.connect(url)
            response = await ws.recv()
            data = json.loads(response)
            print(data)
            if 'nonce' in data:
                    await ws.send(json.dumps(auth))
            elif 'event' in data and data['event'] == 'login':
                if data['success'] == True:
                    await ws.send(json.dumps(position))
            elif 'event' in data and data['event'] == 'position':
                 continue
asyncio.get_event_loop().run_until_complete(subscribe())

Request Parameters

Parameters
Type
Required
Description

op

STRING

Yes

subscribe

args

LIST

Yes

position:all or a list of individual instruments position:<instrumentId>

tag

INTEGER or STRING

No

If given it will be echoed in the reply and the max size of tag is 32

Channel Update Fields

Fields
Type
Description

table

STRING

position

accountId

STRING

Account identifier

timestamp

STRING

Current millisecond timestamp

data

LIST of dictionaries

instrumentId

STRING

e.g. ETH-USD-SWAP-LIN

quantity

STRING

Position size (+/-)

lastUpdated

STRING

Millisecond timestamp

contractValCurrency

STRING

Base asset ID e.g. ETH

entryPrice

STRING

Average entry price of total position (Cost / Size)

positionPnl

STRING

Postion profit and lost in OX

estLiquidationPrice

STRING

Estimated liquidation price, return 0 if it is negative(<0)

margin

STRING

Currently always reports 0

leverage

STRING

Currently always reports 0

Order Channel

Last updated