Vessel Finance API
  1. Market
Vessel Finance API
  • Introduction
  • General Info
  • HMAC Signature Guide
  • Poseidon Signature Guide
  • Internal Transfer Signature Guide
  • Error Code
  • Vessel REST API
    • Public
      • Market Data
        • 24hr Ticker Statistics
        • Kline / Candlestick Data
        • Order Book
        • Recent Trades List
        • Average Price
        • AMM Pool Last 24h Data
      • Exchange Data
        • Ticker Info
        • Asset Info
        • Trade Fee
        • AMM Pool Info
    • User
      • Asset
        • User Asset
        • Withdraw
        • Withdraw History
        • Deposit History
        • Claim History
        • Internal Transfer (Send)
        • Internal Transfer History
      • Order
        • Place Order
        • Cancel Order
        • Open Orders
        • Completed Orders
        • All Orders
        • Query Order
        • Modify Order
      • AMM
        • Add Liquidity
        • Remove Liquidity
        • Collect Fee
        • AMM Position
        • AMM Action History
      • Account
        • User Profile
        • User Trade List
  • Vessel WebSocket
    • Market
      • Order Book
      • K Line
      • Recent Trades
      • 24hr Ticker Statistics
      • Ticker Setting Upade
    • User
      • Authorize
      • Balance
      • Account
  1. Market

Order Book

{{WSS_SERVER}}/ws
Last modified:2024-10-12 09:17:07
Order Book is used to subscribe to real-time updates for the order book of a specific trading pair on our platform.

Information#

Update Speed: 1000ms
Initial Limit: 1000 data points for both bid and ask sides

Message Structure#

Send Message#

1.
type: Specifies the type of WebSocket message.
Type: String.
Value: "subscribe"
2.
channel: Indicates the type of data to subscribe to (e.g., order book updates).
Type: String.
Value: "orderbook"
3.
id: A unique identifier for the subscription request. Write randomly or use any unique identifier.
Type: String.
Example. "random string 001"
4.
symbol: Specifies the trading pair for which the subscriber wants to receive order book updates.
Type: String.
Example: "WBTCUSDT"

Subscribe Example#

{
    "type": "subscribe",
    "channel": "orderbook",
    "id": "random string",
    "symbol": "WBTCUSDT"
}

Unsubscribe Example#

{
    "type": "unsubscribe",
    "channel": "orderbook",
    "id": "random string",
    "symbol": "WBTCUSDT"
}

Initial Message#

1.
type: Specifies the type of WebSocket message.
Type: String
Value: "init"
2.
channel: Indicates the type of data being updated (e.g., order book updates).
Type: String
Value: "orderbook"
3.
symbol: Specifies the trading pair for which the order book is being updated.
Type: String
Example: "WBTCUSDT"
4.
timestamp: Specifies the timestamp of the order book is subscribed.
Type: String (UNIX timestamp in milliseconds & UTC)
Example: 1704433004692
5.
data: Contains the actual order book update information.
bids: Array of bid orders (buy orders) in the order book. Each bid is an object with price, volume, and orderCount fields.
Type: Array of Objects
asks: Array of ask orders (sell orders) in the order book. Each ask is an object with price, volume, and orderCount fields.
Type: Array of Objects
timestamp: The current timestamp when the update message is sent.
Type: Integer (UNIX timestamp in milliseconds & UTC)

Response Message Example#

Update Message#

1.
type: Specifies the type of WebSocket message.
Type: String
Value: "update"
2.
channel: Indicates the type of data being updated (e.g., order book updates).
Type: String
Value: "orderbook"
3.
symbol: Specifies the trading pair for which the order book is being updated.
Type: String
Example: "WBTCUSDT"
4.
data: Contains the actual order book update information.
bids: Array of bid orders (buy orders) in the order book. Each bid is an object with price, volume, and orderCount fields.
Type: Array of Objects
asks: Array of ask orders (sell orders) in the order book. Each ask is an object with price, volume, and orderCount fields.
Type: Array of Objects
lastTimestamp: The timestamp of the last order book.
Type: String (UNIX timestamp in milliseconds & UTC)
timestamp: The timestamp of the current order book.
Type: String (UNIX timestamp in milliseconds & UTC)

Update Message Example#

{
  "type": "update",
  "channel": "orderbook",
  "symbol": "WBTCUSDT",
  "data": {
    "bids": [
      {
        "price": "32680.18",
        "volume": "0.09",
        "orderCount": "1"
      },
      {
        "price": "32571.69",
        "volume": "0.1",
        "orderCount": "1"
      },
      {
        "price": "32142.54",
        "volume": "0.1",
        "orderCount": "1"
      }
    ],
    "asks": [
      {
        "price": "34915.97",
        "volume": "0.1",
        "orderCount": "1"
      }
    ],
    "lastTimestamp": "1700809758368",
    "timestamp": "1700809759368"
  }
}

Maintain a Local Orderbook#

To maintain a local order book correctly, follow these steps:
1.
Subscribe to the WebSocket "orderbook" Channel
Initiate a connection to the WebSocket order book channel for real-time updates.
2.
Initialize with Snapshot
Upon subscribing, you'll receive an initial snapshot message which type is "init". Buffer and store this data to create your local order book.
This snapshot gives you the current state of the order book up to a certain depth limit (1000 data points for both bid and ask sides).
3.
Process Updates
Continuously listen to the stream of updates which type is "uptade".
For each update, check that the lastTimestamp matches the timestamp in previous message from your local order book to ensure updates are in sequence.
If the timestamps do not match, it indicates that some messages have been lost. In such cases, you should reconnect and reinitialize your order book to ensure accuracy.
4.
Apply Updates
The data in each update represents the absolute quantity at a specific price level.
If the quantity is greater than 0 at a price level, update your local order book with this new quantity.
If the quantity is 0, remove the corresponding price level from your local order book.
5.
Handling 1000 Price Levels
Your local order book might not include all price levels due to the initial snapshot's depth limit of 1000 levels.
Vessel's WebSocket only maintains the most recent 1000 levels in the order book. Specifically, when an update message is received, the system retrieves the latest 1000 price levels. If there are price levels in the previous order book that are no longer within the latest 1000 price levels, their quantities will be updated to 0. If there is any discrepancy between the previous order book and the latest one, the system will update the quantities based on the latest price levels.
However, the depth limit of 1000 levels generally provides enough information to understand the market and trade effectively.
By following these steps, you can maintain a local order book that is sufficiently accurate for most trading activities, even though it may not perfectly match the full order book on the exchange.

Request

Header Params
VESSEL-API-KEY
string 
required
Default:
{{API_KEY}}
VESSEL-PASSPHRASE
string 
required
Default:
{{API_PASSPHRASE}}
VESSEL-SIGNATURE
string 
required
Use signRequest script to generate
VESSEL-TIMESTAMP
string 
required
Use signRequest script to set
Previous
Market
Next
K Line
Built with