Last updated
Was this helpful?
Last updated
Was this helpful?
The WebSocket API provides real-time streaming of easily-consumable data regarding all important aspects on the Demex L1 chain. This API is recommended for building most applications.
These public WebSocket endpoints can be used to stream data from Demex.
Mainnet: wss://ws-api.carbon.network/ws
Testnet: wss://test-ws-api.carbon.network/ws
It is important to note that the above public endpoints do not have any guarantees on uptime and may not always be accessible, even when the blockchain may operating normally.
To ensure maximum reliability, it is advisable to with WebSockets enabled.
While interacting with the WebSocket API is straightforward, detailed documentation for each individual endpoint is still underway.
In the meantime, you may already begin using it in production via the following quickstart guide.
To subscribe to a specific subscription, you should use the subscribe
method while specifying the channel
you wish to stream.
request_id: This serves as an identifier to distinguish between different subscription requests. The subscription response will include this identifier.
method: This refers to the name of the method, which is either subscribe
or unsubscribe
.
params: This refers to the request parameters, which is consists of the channels
object. It is an array of the required channels for subscription, postfixed by the respective subscription parameters and delimited by a colon (:
). You can find the list of supported channels and the required parameters .
The successful response will echo the subscribed channel and the request ID.
block_height: This is the block height of the data
channel: This is the subscription's channel
update_type: This field specifies the type of the accompanying data and may be one of: full_state | delta
.
If the value of this field is full_state
, it indicates that the accompanying data represents a full view of the data you intend to stream. This update type is always sent immediately after a new channel subscription, and serves as a foundation for future updates - clients should maintain the given data and modify it based on future updates.
If the value of this field is delta
, it means that the accompanying data only contains deltas (modifications) that should be applied on the full state that the client is maintaining.
Subscription Feed
block_height: This is the block height of the data
channel: This is the subscription's channel
update_type: This field specifies the type of the accompanying data and may be one of: full_state | delta
.
If the value of this field is full_state
, it indicates that the accompanying data represents a full view of the data you intend to stream. This update type is always sent immediately after a new channel subscription, and serves as a foundation for future updates - clients should maintain the given data and modify it based on future updates.
If the value of this field is delta
, it means that the accompanying data only contains deltas (modifications) that should be applied on the full state that the client is maintaining.
Example
Let's stream orders for the account swth12j2frlmwc26xv9dqj08tnqxpjy7yklsxa8p4da
in the swth_eth
market.
result: This field contains the data. You can find the data structure of stream updates from subscriptions .
result: This field contains the data. You can find the data structure of stream updates from subscriptions .