Reya
  • Start Here
    • Why Reya?
  • REYA PRODUCTS
    • Reya DEX
      • Navigating Reya DEX
        • Dashboard: getting started
          • Creating your margin account
          • Moving funds
          • Checking your account
        • The Trading Screen
          • Trade form
          • Market Data Panel
        • LP Pool
      • Trading on Reya DEX
        • Perpetual Futures
        • Margin
        • Auto-exchange and Liquidations
        • Specifications
        • Conditional Orders
        • FlashSwap
        • Collateral liquidations
        • Settlement and cross-collateralization
      • Docs: Reya DEX REST API
      • Docs: Reya DEX WebSocket
    • Reya Network
      • The structure of Reya Network
      • The Liquidity Layer
        • Reya’s pool for perpetual futures
        • Offering liquidity in the passive pool
        • Deepdive into passive perps
        • Network Owned Liquidity
      • Derivatives Clearing
        • Automatic leveraging of PnL across instruments
        • Cross-collateralization
          • Haircuts
          • Auto-exchange conditions
          • Auto-exchange mechanism
        • Cross-margining
          • The margin system
        • The liquidation engine
          • Ranked liquidations
          • Dutch auction
          • Backstop LPs
          • Insurance Funds
          • Page 1
        • Spot markets
        • Reya Governance
      • What's the roadmap
      • Who's Behind Reya Network
    • rUSD / srUSD
      • rUSD
      • srUSD
      • srUSD How to and FAQs
  • COMMUNITY
    • Join the Reya Community
    • Incentives Overview
      • Experience (XP)
        • Technical details
      • Boosts
      • Ranks and Seasons
    • x.com
  • Technical Docs
    • Reya Python SDK
    • Contract Functions
      • Core
      • Passive Perp Instrument
      • Passive Pool
      • Oracle Adapter
    • Contract Addresses
    • Smart Contract Withdrawals
    • Audits
  • REYA RESOURCES
    • Blog
    • Beginner's Guide to Better Trading with Reya
    • Block Explorer
    • Glossary (coming soon)
    • FAQ (coming soon)
Powered by GitBook
On this page
  • Base URL
  • Table of Contents
  • Common WebSocket Message Fields
  • Connecting to WebSocket
  • Ping/Pong Heartbeat
  • Message Types: Server -> Client
  • Message Types: Client -> Server
  • Wallet Data
  • Wallet Position Updates
  • Wallet Orders Updates
  • Wallet Account Balances
  • Wallet Conditional Orders
  • Market Data
  • All Markets Data
  • Specific Market Data
  • Market Orders
  1. REYA PRODUCTS
  2. Reya DEX

Docs: Reya DEX WebSocket

This document provides comprehensive information about the websocket trading API endpoints in the Reya DEX.

Base URL

Mainnet: wss://websocket.reya.xyz/
Testnet: wss://ws.reya-cronos.gelato.digital

Table of Contents

  • Common WebSocket Message Fields

  • Connecting to WebSocket

  • Ping/Pong Heartbeat

  • Message Types: Client -> Server

  • Message Types: Server -> Client

  • Wallet Data

    • Wallet Position Updates

    • Wallet Orders Updates

    • Wallet Account Balances

    • Wallet Conditional Orders

  • Market Data

    • All Markets Data

    • Specific Market Data

    • Market Orders

Common WebSocket Message Fields

Field
Description

type

Message type (e.g., "subscribed", "channel_data")

connection_id

Unique identifier for the WebSocket connection

message_id

Sequential message ID for the connection

channel

The channel the message pertains to

id

Optional channel ID (often empty string)

contents

The channel data contents

version

API version (for channel_data messages)

Connecting to WebSocket

const ws = new WebSocket('wss://websocket.reya.xyz/');

ws.onopen = function() {
  console.log('Connected to WebSocket server');
};

Ping/Pong Heartbeat

The WebSocket connection uses a ping/pong mechanism to maintain the connection and ensure both client and server are responsive.

  • The server will periodically send ping frames to the client.

  • The client should respond with a pong frame as soon as possible after receiving a ping.

  • If the server does not receive a pong response within a certain timeout period, it may assume the connection is lost and close it.

These are the heartbeating parameters used in the Reya DEX WebSocket server:

  • HEARTBEAT_INTERVAL_MS: 10 seconds

  • HEARTBEAT_TIMEOUT_MS: 5 seconds

Message Types: Server -> Client

The following code snippet shows how to handle all possible message types from the server to the client:

ws.onmessage = function(event) {
  const data = JSON.parse(event.data);
  
  switch(data.type) {
    case 'connected':
      console.log('Connection established');
      break;
    case 'subscribed':
      console.log(`Subscribed to ${data.channel}`);
      break;
    case 'unsubscribed':
      console.log(`Unsubscribed from ${data.channel}`);
      break;  
    case 'channel_data':
      console.log(`Received data update for ${data.channel}`, data.contents);
      break;
    case 'pong':
      console.log('Pong received');
      break;  
    case 'error':
      console.error(`Error: ${data.message}`);
      break;
  }
};

Message Types: Client -> Server

The following code snippets show all possible message types from the client to the server:

Sending a Ping

setInterval(() => {
  ws.send(JSON.stringify({ type: 'ping' }));
}, 30000); // Send ping every 30 seconds

Sending a Subscription*

ws.send(JSON.stringify({
  type: 'subscribe',
  channel: '/api/trading/wallet/0x6c51275fd01d5dbd2da194e92f920f8598306df2/positions'
}));

Sending an Unsubscription

ws.send(JSON.stringify({
  type: 'unsubscribe',
  channel: '/api/trading/wallet/0x6c51275fd01d5dbd2da194e92f920f8598306df2/positions'
}));

Wallet Data

Wallet Position Updates

Channel: /api/trading/wallet/:address/positions

Description: Real-time updates for a wallet's positions

Subscription Request:

ws.send(JSON.stringify({
  type: 'subscribe',
  channel: '/api/trading/wallet/0x6c51275fd01d5dbd2da194e92f920f8598306df2/positions'
}));

Example Response:

{
  "type": "channel_data",
  "channel": "/api/trading/wallet/0x6c51275fd01d5dbd2da194e92f920f8598306df2/positions",
  "contents": 
  [{
      "market_id": "1",
      "account_id": "95681",
      "base": "0",
      "realized_pnl": "-304974292384640029085",
      "last_price": "2.527588661417322834645e+21",
      "last_price_timestamp": "1747821004",
      "funding_value": "412142260930556829205",
      "base_multiplier": "1000000000000000000",
      "adl_unwind_price": "0",
      "transaction_hash": "0x45cf36005fe934669935a992d9b3f0a990e82844b13cb5edebae376705b2a5e5",
      "block_timestamp": "1747840695",
      "block_number": "67720583",
      "unique_id": 6772058300008
  }]
}

Response Fields:

Field
Description

market_id

ID of the market the position is in

account_id

ID of the account that holds the position

base

Base value of the position

realized_pnl

Realized profit and loss

last_price

Last known price

last_price_timestamp

Timestamp of the last price

funding_value

Value from funding rate payments

base_multiplier

Multiplier applied to the base value

adl_unwind_price

ADL unwind price for the position

transaction_hash

Transaction hash on the blockchain

block_timestamp

Timestamp of the block

block_number

Block number

unique_id

Unique identifier for the position

Wallet Orders Updates

Channel: /api/trading/wallet/:address/orders

Description: Real-time updates for a wallet's orders

Subscription Request:

ws.send(JSON.stringify({
  type: 'subscribe',
  channel: '/api/trading/wallet/0x6c51275fd01d5dbd2da194e92f920f8598306df2/orders'
}));

Example Response:

{
  "type": "channel_data",
  "channel": "/api/trading/wallet/0x6c51275fd01d5dbd2da194e92f920f8598306df2/orders",
  "contents":
  [{
    "id": "0xe7a2415f615c32fdb309738f7786e40cb5c2ff31bd5229d527cbb87a9953e1bf-8",
    "market_id": "2",
    "account_id": "95681",
    "executed_base": "20600000000000000",
    "fee": "801813",
    "price": "1.11208696e+23",
    "is_match_order": true,
    "liquidation_type": "-1",
    "position_base": "20600000000000000",
    "position_realized_pnl": "-18749657582419440095",
    "position_last_price": "1.11208696e+23",
    "position_last_price_timestamp": "1747943611",
    "position_funding_value": "5.753090050869636920185e+21",
    "position_base_multiplier": "1000000000000000000",
    "position_adl_unwind_price": "0",
    "counterparty_account_id": "2",
    "counterparty_base": "-77900000000000000",
    "counterparty_realized_pnl": "4.8843950429623853993507e+22",
    "counterparty_last_price": "1.11564219456087119420629e+23",
    "counterparty_last_price_timestamp": "1747943611",
    "counterparty_funding_value": "5.753090050869636920185e+21",
    "counterparty_base_multiplier": "1000000000000000000",
    "counterparty_adl_unwind_price": "0",
    "transaction_hash": "0xe7a2415f615c32fdb309738f7786e40cb5c2ff31bd5229d527cbb87a9953e1bf",
    "block_timestamp": "1747943611",
    "block_number": "67791450",
    "unique_id": 6779145000008,
    "created_at": "2025-05-22T19:53:31.545Z"
  }]
}

Response Fields:

Field
Description

id

Unique identifier for the order

market_id

ID of the market the order is in

account_id

ID of the account that placed the order

executed_base

Base amount executed

fee

Fee paid for the order

price

Order price

is_match_order

Whether the order is a match order

liquidation_type

Type of liquidation, if applicable

position_base

Position base amount

position_realized_pnl

Realized profit and loss for the position

position_last_price

Last price for the position

position_last_price_timestamp

Timestamp of the last price

position_funding_value

Funding value for the position

position_base_multiplier

Base multiplier for the position

position_adl_unwind_price

ADL unwind price for the position

counterparty_account_id

ID of the counterparty account

counterparty_base

Base value for the counterparty

counterparty_realized_pnl

Realized profit and loss for the counterparty

counterparty_last_price

Last price for the counterparty

counterparty_last_price_timestamp

Timestamp of the last price for the counterparty

counterparty_funding_value

Funding value for the counterparty

counterparty_base_multiplier

Base multiplier for the counterparty

counterparty_adl_unwind_price

ADL unwind price for the counterparty

transaction_hash

Transaction hash on the blockchain

block_timestamp

Timestamp of the block

block_number

Block number

unique_id

Unique identifier for the order

created_at

Timestamp when the order was created

Wallet Account Balances

Channel: /api/trading/wallet/:address/accounts/balances

Description: Real-time updates for a wallet's account balances

Subscription Request:

ws.send(JSON.stringify({
  type: 'subscribe',
  channel: '/api/trading/wallet/0x6c51275fd01d5dbd2da194e92f920f8598306df2/accounts/balances'
}));

Example Response:

{
  "type": "channel_data",
  "channel": "/api/trading/wallet/0x6c51275fd01d5dbd2da194e92f920f8598306df2/accounts/balances",
  "contents": 
  [
      {
        "account_id": 95681,
        "collateral": "0x162b78e827a8db8173d13735c08c8d40cb5ccdab",
        "balance": "9.56851448557047183318262400312e+29"
      },
      {
        "account_id": 95681,
        "collateral": "0xa9f32a851b1800742e47725da54a09a7ef2556a3",
        "balance": "559738853"
      }
  ]

}

Response Fields:

Field
Description

account_id

ID of the account

collateral

Address of the collateral asset

balance

Current balance amount

Wallet Conditional Orders

Channel: /api/trading/wallet/:address/conditionalOrders

Description: Real-time updates for a wallet's conditional orders

Subscription Request:

ws.send(JSON.stringify({
  type: 'subscribe',
  channel: '/api/trading/wallet/0x6c51275fd01d5dbd2da194e92f920f8598306df2/conditionalOrders'
}));

Example Response:

{
  "type": "subscribed",
  "connection_id": "4908b1c8-31d6-4901-91b8-55d523c3e085",
  "message_id": 11,
  "channel": "/api/trading/wallet/0x6c51275fd01d5dbd2da194e92f920f8598306df2/conditionalOrders",
  "contents": 
  [{
      "id": "a77d7040-c079-4d48-b78a-4e9d682fd85d",
      "account_id": "95681",
      "market_id": "2",
      "order_type": "Stop Loss",
      "is_long": false,
      "trigger_price": 110000,
      "order_base": "0",
      "status": "pending",
      "creation_timestamp_ms": 1747943630008,
      "last_update_timestamp_ms": 1747943630008,
      "transaction_hash": null
  }]
}

Response Fields:

Field
Description

id

Unique identifier for the conditional order

account_id

ID of the account that placed the order

market_id

ID of the market the order is for

order_type

Type of conditional order (e.g., "Stop Loss")

is_long

Whether the order is long (true) or short (false)

trigger_price

Price at which the order will be triggered

order_base

Base amount for the order

status

Current status of the order (e.g., "pending")

creation_timestamp_ms

Timestamp when the order was created (milliseconds)

last_update_timestamp_ms

Timestamp when the order was last updated (milliseconds)

transaction_hash

Blockchain transaction hash (if available)

Market Data

All Markets Data

Channel: /api/trading/markets/data

Description: Real-time updates for all markets data

Subscription Request:

ws.send(JSON.stringify({
  type: 'subscribe',
  channel: '/api/trading/markets/data'
}));

Example Response:

{
  "type": "channel_data",
  "channel": "/api/trading/markets/data",
  "contents":  
    [{
        "marketId": "2",
        "updatedAt": 1747950805007,
        "longOI": 4.2148,
        "shortOI": 4.2148,
        "longSkewPercentage": 50,
        "shortSkewPercentage": 50,
        "openInterest": 4.2148,
        "fundingRate": 0.0021282372228978498,
        "last24hVolume": 3446963.8729016,
        "maxAmountBaseLong": 859.7891490203162,
        "maxAmountBaseShort": 859.7891490203162,
        "maxAmountSizeLong": 95302034.4325028,
        "maxAmountSizeShort": 95302034.4325028,
        "priceChange24H": 2432.2611632500048,
        "priceChange24HPercentage": 2.24381789178321,
        "poolPrice": 110842.7949782424,
        "oraclePrice": 110842.7949782424,
        "pricesUpdatedAt": 1747950804690
    }]
}

Response Fields:

Field
Description

marketId

Unique identifier for the market

updatedAt

Timestamp when the data was last updated (milliseconds)

longOI

Long open interest

shortOI

Short open interest

longSkewPercentage

Percentage of open interest that is long

shortSkewPercentage

Percentage of open interest that is short

openInterest

Total open interest

fundingRate

Current funding rate

last24hVolume

24-hour trading volume

maxAmountBaseLong

Maximum base amount for long positions

maxAmountBaseShort

Maximum base amount for short positions

maxAmountSizeLong

Maximum size for long positions

maxAmountSizeShort

Maximum size for short positions

priceChange24H

Absolute price change in the last 24 hours

priceChange24HPercentage

Percentage price change in the last 24 hours

poolPrice

Current pool price

oraclePrice

Current oracle price

pricesUpdatedAt

Timestamp when prices were last updated (milliseconds)

Specific Market Data

Channel: /api/trading/market/:marketId/data

Description: Real-time updates for a specific market's data

Subscription Request:

ws.send(JSON.stringify({
  type: 'subscribe',
  channel: '/api/trading/market/2/data'
}));

Example Response:

{
  "type": "channel_data",
  "channel": "/api/trading/market/2/data",
  "contents": 
  [{
      "marketId": "2",
      "updatedAt": 1747950805007,
      "longOI": 4.2148,
      "shortOI": 4.2148,
      "longSkewPercentage": 50,
      "shortSkewPercentage": 50,
      "openInterest": 4.2148,
      "fundingRate": 0.0021282372228978498,
      "last24hVolume": 3446963.8729016,
      "maxAmountBaseLong": 859.7891490203162,
      "maxAmountBaseShort": 859.7891490203162,
      "maxAmountSizeLong": 95302034.4325028,
      "maxAmountSizeShort": 95302034.4325028,
      "priceChange24H": 2432.2611632500048,
      "priceChange24HPercentage": 2.24381789178321,
      "poolPrice": 110842.7949782424,
      "oraclePrice": 110842.7949782424,
      "pricesUpdatedAt": 1747950804690
  }]
}

Response Fields: See "All Markets Data" for field descriptions

Market Orders

Channel: /api/trading/market/:marketId/orders

Description: Real-time updates for orders in a specific market

Subscription Request:

ws.send(JSON.stringify({
  type: 'subscribe',
  channel: '/api/trading/market/2/orders'
}));

Example Response:

{
  "type": "channel_data",
  "channel": "/api/trading/market/2/orders",
  "contents": [
    {
      "id": "0x50dbe979d1ce9228cc7f53fe81bb1b991625dc40d1705edc3d65806df79d7a24-7",
      "market_id": "2",
      "account_id": "17695",
      "executed_base": "-281000000000000000",
      "fee": "2806484",
      "price": "1.1097209e+23",
      "is_match_order": true,
      "liquidation_type": "-1",
      "position_base": "2356400000000000000",
      "position_realized_pnl": "6.2530459825487987472136e+22",
      "position_last_price": "1.10865563096944821868902e+23",
      "position_last_price_timestamp": "1747935401",
      "position_funding_value": "5.756991854939699655103e+21",
      "position_base_multiplier": "1000000000000000000",
      "position_adl_unwind_price": "0",
      "counterparty_account_id": "2",
      "counterparty_base": "0",
      "counterparty_realized_pnl": "4.8850987011728587651058e+22",
      "counterparty_last_price": "1.10838063344128113879003e+23",
      "counterparty_last_price_timestamp": "1747949622",
      "counterparty_funding_value": "5.756991854939699655103e+21",
      "counterparty_base_multiplier": "1000000000000000000",
      "counterparty_adl_unwind_price": "0",
      "transaction_hash": "0x50dbe979d1ce9228cc7f53fe81bb1b991625dc40d1705edc3d65806df79d7a24",
      "block_timestamp": "1747949720",
      "block_number": "67795385",
      "unique_id": 6779538500007,
      "created_at": "2025-05-22T21:35:43.558Z"
    }
  ]
}

Response Fields:

Field
Description

id

Unique identifier for the order

market_id

ID of the market the order is in

account_id

ID of the account that placed the order

executed_base

Base amount executed

fee

Fee paid for the order

price

Order price

is_match_order

Whether the order is a match order

liquidation_type

Type of liquidation, if applicable

position_base

Position base amount

position_realized_pnl

Realized profit and loss for the position

position_last_price

Last price for the position

position_last_price_timestamp

Timestamp of the last price

position_funding_value

Funding value for the position

position_base_multiplier

Base multiplier for the position

position_adl_unwind_price

ADL unwind price for the position

counterparty_account_id

ID of the counterparty account

counterparty_base

Base value for the counterparty

counterparty_realized_pnl

Realized profit and loss for the counterparty

counterparty_last_price

Last price for the counterparty

counterparty_last_price_timestamp

Timestamp of the last price for the counterparty

counterparty_funding_value

Funding value for the counterparty

counterparty_base_multiplier

Base multiplier for the counterparty

counterparty_adl_unwind_price

ADL unwind price for the counterparty

transaction_hash

Transaction hash on the blockchain

block_timestamp

Timestamp of the block

block_number

Block number

unique_id

Unique identifier for the order

created_at

Timestamp when the order was created

PreviousDocs: Reya DEX REST APINextReya Network

Last updated 8 days ago