Balance Channel

Channel Update Frequency : On update

The websocket will reply with the shown success response format for subscribed assets with changed balances.

If a subscription has been made to balance:all, the data array in the message from this balance channel will contain a JSON list, otherwise the data array will contain a single JSON corresponding to one spot asset per asset channel subscription.

Curl

Request format

{
  "op": "subscribe",
  "args": ["balance:all"],
  "tag": 101
}

OR

{
  "op": "subscribe", 
  "args": ["balance:USDT", "balance:OX", ........], 
  "tag": 101
}

Success response format

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

Balance channel format

{
  "table": "balance",
  "accountId": "<Your account ID>",
  "timestamp": "1599693365059",
  "tradeType": "STANDARD",
  "data":[
      {
          "total": "10000",
          "reserved": "1000",
          "instrumentId": "USDT",
          "available": "9000",
          "locked": "0"
          "quantityLastUpdated": "1599694369431",
       },
       {
          "total": "100000",
          "reserved": "0",
          "instrumentId": "OX",
          "available": "100000",
          "locked": "0"
          "quantityLastUpdated": "1599694343242",
        }
  ]
}
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
          }
}
balance = \
{
  "op": "subscribe",
  "args": ["balance:all"],
  "tag": 101
}
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(balance))
            elif 'event' in data and data['event'] == 'balance':
                 continue
asyncio.get_event_loop().run_until_complete(subscribe())

Request Parameters

Parameters
Type
Required
Description

op

STRING

Yes

subscribe

args

LIST

Yes

balance:all or a list of individual assets balance:<assetId>

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

balance

accountId

STRING

Account identifier

timestamp

STRING

Current millisecond timestamp

tradeType

STRING

LINEAR, STANDARD, PORTFOLIO

data

LIST of dictionaries

total

STRING

Total spot asset balance

reserved

STRING

Reserved asset balance for working spot and repo orders

instrumentId

STRING

Base asset ID e.g. BTC

available

STRING

Remaining available asset balance (total - reserved)

locked

STRING

Temporarily locked asset balance

quantityLastUpdated

STRING

Millisecond timestamp

Last updated