Docs: Reya DEX WebSocket
This document provides comprehensive information about the websocket trading API endpoints in the Reya DEX.
Base URL
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
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
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 aping
.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:
Message Types: Client -> Server
The following code snippets show all possible message types from the client to the server:
Sending a Ping
Sending a Subscription*
Sending an Unsubscription
Wallet Data
Wallet Position Updates
Channel: /api/trading/wallet/:address/positions
Description: Real-time updates for a wallet's positions
Subscription Request:
Example Response:
Response Fields:
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:
Example Response:
Response Fields:
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:
Example Response:
Response Fields:
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:
Example Response:
Response Fields:
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:
Example Response:
Response Fields:
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:
Example Response:
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:
Example Response:
Response Fields:
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
Last updated