VOOZH about

URL: https://www.asyncapi.com/blog/websocket-part2

⇱ Creating AsyncAPI for WebSocket API - Step by Step | AsyncAPI Initiative for event-driven APIs


👁 Image

This step-by-step guide is a continuation of a series of articles about WebSockets. I recommend reading WebSocket, Shrek, and AsyncAPI - An Opinionated Intro first.

If you do not want to read this article, then watch the recording of the live stream about the same:

All roads lead to Rome, but all those roads are different. First, you need to identify where you are and what is the purpose of your journey. What is your goal? What do you want to use AsyncAPI for?

You may invest in using the specification for many different reasons, like for example:

  • documentation
  • testing
  • mocking
  • code generation
  • message validation

Depending on your goal, you might need to take different roads to get there. If your only goal is documentation, you might take a different approach to writing an AsyncAPI file than you would take while thinking about code generation.

Choosing the right road to Rome

Let's say AsyncAPI does not fully cover your use case. You are missing some extra property. You are disappointed that you cannot explicitly provide information that your production servers both support different channels. Server A supports channel AA and AB, while Server B supports channel BA and BB. It is not currently possible with the specification as the assumption is that your application communicates with servers that support the same channels.

There are two roads to Rome:

Road docs-only: You need AsyncAPI for docs generation only and have no intention of sharing the source document with anyone. It means you do not need to bother much about inventing some specification extension. You can just add missing information to the description of a given object.

Road automation: You need AsyncAPI for docs and code generation, which means that all details in your AsyncAPI document must be machine-readable. You can't just put unsupported information in the description.

Kraken API use case

I'm going to guide you through the process of creating an AsyncAPI document. I'll use the example of Kraken API mentioned in my previous article.

The challenge I had here was that I'm trying to document an API basing on public docs with no access to a subject matter expert. I also have zero understanding of the cryptocurrency industry and still do not fully understand the vocabulary.

Message to Kraken API developers and technical writers
In case you want to continue the work I started on the AsyncAPI document for Kraken API, feel free to do that. I'm happy to help, just let me know. Reach me out in our AsyncAPI Slack workspace.

More interesting here are the technical challenges though, caused by the fact that Kraken's API:

  • has two production servers for non-secure and secure message exchange
  • some messages are supported only by the public and some only by a private server
  • has just one entry point for communication. You do not get specific messages from one of many endpoints. You get specific messages after first sending a subscription message. Meaning you have a request message and you get a reply message, so something that is not yet possible to describe with AsyncAPI in a machine-readable way

Writing a single AsyncAPI document

Because of all these different challenges, I took the docs-only road described in section Choosing the right road to Rome. No worries though, I give tips for the automation road too.

Basic information about the API

First, provide some basic information that every good AsyncAPI file should have:

  • What AsyncAPI version do you use?
  • What is the name of your API?
  • What version of the API you describe?
  • Do not underestimate the description. Optional != not needed. AsyncAPI supports markdown in descriptions. Provide long generic documentation for your API. Benefit from markdown features to structure it, so it is easier to read

In case you think using just one property to add overarching documentation for your API is very limiting, I agree with you 😃 Join discussion here. I believe spec should have better support for docs, and we should first explore it with specification extensions. To be honest, I always thought documentation deserves its specification, but I don't want to bother you with my wicked visions now.

1asyncapi:2.0.02info:3title:KrakenWebsocketsAPI4version:'1.8'5description:|
6 WebSockets API offers real-time market data updates. WebSockets is a bidirectional protocol offering fastest real-time data, helping you build real-time applications. The public message types presented below do not require authentication. Private-data messages can be subscribed on a separate authenticated endpoint. 
78### General Considerations9
10-TLSwithSNI(ServerNameIndication)isrequiredinordertoestablishaKrakenWebSocketsAPIconnection.SeeCloudflare's [WhatisSNI?](https://www.cloudflare.com/learning/ssl/what-is-sni/)guideformoredetails.11-AllmessagessentandreceivedviaWebSocketsareencodedinJSONformat.12-Alldecimalfields(includingtimestamps)arequotedtopreserveprecision.13-TimestampsshouldnotbeconsidereduniqueandnotbeconsideredasaliasesfortransactionIDs.Also,thegranularityoftimestampsisnotrepresentativeoftransactionrates.14-Atleastoneprivatemessageshouldbesubscribedtokeeptheauthenticatedclientconnectionopen.15-PleaseuseRESTAPIendpoint [AssetPairs](https://www.kraken.com/features/api#get-tradable-pairs)tofetchthelistofpairswhichcanbesubscribedviaWebSocketsAPI.Forexample,field'wsname'givesthesupportedpairsnamewhichcanbeusedtosubscribe.16-Cloudflareimposesaconnection/re-connectionratelimit(perIPaddress)ofapproximately150attemptsperrolling10minutes.Ifthisisexceeded,theIPisbannedfor10minutes.17-Recommendedreconnectionbehaviouristo(1)attemptreconnectioninstantlyuptoahandfuloftimesifthewebsocketisdroppedrandomlyduringnormaloperationbut(2)aftermaintenanceorextendeddowntime,attempttoreconnectnomorequicklythanonceevery5seconds.Thereisnoadvantagetoreconnectingmorerapidlyaftermaintenanceduringcancel_onlymode.

Provide server information

Describe how to connect to the API:

  • What is the URL of the server?
  • Is there any authorization in place?
  • What is the protocol requirement, is SSL connection required?

The Kraken API is an excellent example of how different WebSocket implementations can be and that there is never one way to design your architecture. It all depends on your requirements, the use cases that drive your product.

Describing multiple servers

Below you can notice two different servers. These are not, as you might think, production and development servers. Here you have a clear division between publicly available data and private-only data. In other words, users use two different servers, not channels/paths/endpoints, to talk to the API.

1servers:2public:3url:ws.kraken.com4protocol:wss5description:|
6 Public server available without authorization.
7 Once the socket is open you can subscribe to a public channel by sending a subscribe request message.
8private:9url:ws-auth.kraken.com10protocol:wss11description:|
12 Private server that requires authorization.
13 Once the socket is open you can subscribe to private-data channels by sending an authenticated subscribe request message.

You can verify if above is true by connecting to ws.kraken.com and trying to subscribe to one of the event streams that require a token:

{ "event": "subscribe", "subscription": { "name": "ownTrades", "token": "WW91ciBhdXRoZW50aWNhdGlvbiB0b2tlbiBnb2VzIGhlcmUu" } }

In response you get an error:

{"errorMessage":"Private data and trading are unavailable on this endpoint. Try ws-auth.kraken.com","event":"subscriptionStatus","status":"error","subscription":{"name":"ownTrades","token":"WW91ciBhdXRoZW50aWNhdGlvbiB0b2tlbiBnb2VzIGhlcmUu"}}

In the documentation, they also indicate beta servers like beta-ws.kraken.com. It is hard to understand their purpose, so I did not put them in the AsyncAPI document. For me, beta means something new, some upgrades, and I would consider writing a separate AsyncAPI document.

Is it reasonable to describe API that has two different production servers in one AsyncAPI? As usual, it depends. For docs-only road described in section Choosing the right road to Rome, you can "workaround" some AsyncAPI features if they do not support your use case. Check out, for example, what I had to do in section Server security where I was not sure how to describe the specific security of the private server. Short answer: just extend the description.

For automation road described in Choosing the right road to Rome section, you need a machine-readable structure. In case you have messages that can be consumed only by the private server, you need a way to specify that the given message can be published only to the private server. It is exactly the case with Kraken API.

Imagine you want to read the AsyncAPI document in real-time in your server and validate all incoming messages. Take server ws.kraken.com. The only way to emit errors like Private data and trading are unavailable on this endpoint. Try ws-auth.kraken.com is by writing the code that handles validation manually. You can't generate that as the AsyncAPI file does not specify what messages can go to ws.kraken.com and what messages can't.

Why?

At the moment, in AsyncAPI, you don't have a way to "wire" a server with a message, operation, or a channel. There are no default properties that allow you to provide information that message with the name ownTrades can only be sent to ws-auth.kraken.com server.

Solution?

Create two AsyncAPI documents. Treat those two servers as separate services that share messages and schemas. Use $ref feature to cross-reference schemas.

Server security

You can use AsyncAPI also to describe the security of your API. You can describe in a machine-readable way the security mechanism that protects the server. Several security schemes are supported. In Kraken's case, I could not figure out what kind of security scheme they use from their docs. They seem to have a non-standard set up for getting the authorization token, which is why the only option was to put a human-readable-only description there.

1servers:2public:3url:ws.kraken.com4protocol:wss5description:|
6 Public server available without authorization.
7 Once the socket is open, you can subscribe to a public channel by sending a subscribe request message.
8private:9url:ws-auth.kraken.com10protocol:wss11description:|
12 Private server that requires authorization.
13 Once the socket is open, you can subscribe to private-data channels by sending an authenticated subscribe request message.
1415TheAPIclientmustrequestanauthentication"token"viathefollowingRESTAPIendpoint"GetWebSocketsToken"toconnecttoWebSocketsPrivateendpoints.Formoredetails,readhttps://support.kraken.com/hc/en-us/articles/360034437672-How-to-retrieve-a-WebSocket-authentication-token-Example-code-in-Python-316
17Theresultingtokenmustbeprovidedinthe"token"field of any new private WebSocket feed subscription:18```19 {
20"event":"subscribe",
21"subscription":22 {
23"name":"ownTrades",
24"token":"WW91ciBhdXRoZW50aWNhdGlvbiB0b2tlbiBnb2VzIGhlcmUu"25 }
26 }
27```

Endpoints aka Channels

I saw WebSocket APIs that provide different streams of messages on separate endpoints. It is often the case when you build the WebSocket API for the frontend only and design it for different UI views. In the case of Kraken API we have no endpoints. You connect to the root of the server.

No matter what setup you have, just remember you should use channels to describe it. In the case of connecting to the root, it is as simple as:

1channels:2/:

Multiple different messages on the same channel

You can have one or many different messages coming to your channel. Like in the case of Kraken API, you can even have multiple messages, incoming and outgoing. You can describe it using oneOf on message object as you can see below:

1channels:2/:3publish:4operationId:sendMessage5message:6oneOf:7-$ref:'#/components/messages/ping'8-$ref:'#/components/messages/subscribe'9-$ref:'#/components/messages/unsubscribe'10subscribe:11operationId:processMessage12message:13oneOf:14-$ref:'#/components/messages/pong'15-$ref:'#/components/messages/heartbeat'16-$ref:'#/components/messages/systemStatus'17-$ref:'#/components/messages/subscriptionStatus'

Hold on! Where did these publish and subscribe keywords came from.

When we talk about WebSocket, we usually do not use words like subscribe and publish, as we do not think about producers and consumers. Just check out the protocol RfC. We are used to sending and receiving messages.

Let me present to you an unofficial AsyncAPI vocabulary translator for WebSocket users 😃

WebSocket termAsyncAPI termMeaning from API server perspectiveMeaning from API user perspective
SendPublishThe API server receives the given message.The API user can send a given message to the API server.
ReceiveSubscribeThe API server sends a given message.The API user can receive a given message from the API server.

Messages definition

In event-driven architectures (EDA) it's all about the event, right? The message passed in the system. You need to specify many details about the message, like its payload structure, headers, purpose, and many others.

Above all, always remember to have good examples. Please don't count on the autogenerated ones, as in most cases, they're useless.

1messages:2 systemStatus:3 description: Status sent on connection or system status changes.
4 payload:5 $ref: '#/components/schemas/systemStatus'6 examples:7 - payload:
8 connectionID:86286153908486100009 event: systemStatus
10 status: online
11 version:1.0.0

Describe responses - specification extensions

Describe responses? What responses?

It is EDA. Who cares about responses, right? Fire and forget rules!

The thing is that request and reply pattern is also used in EDA. This is also the case with Kraken API where communication goes through a single channel with multiple different messages. One message triggers another message in response.

The simplest example is the message ping that triggers a pong reply. The current AsyncAPI limitation is that you cannot specify that once the user sends (publish) message ping, the pong message is received in a reply. Look at this thread to participate in an ongoing discussion about request/reply pattern support in AsyncAPI.

For docs-only road from section Choosing the right road to Rome, I would be lazy and just put such info in the description of both messages. Even though this is an error-prone approach, I would just make my life easier. For automation road I would choose to use a specification extension.

What is specification extension?

You can extend every AsyncAPI object in the AsyncAPI document with extra properties. You only need to prefix them with x-. You can also share extensions or reuse extensions from others thanks to extensions catalog.

In the below document, you will notice that for the request/reply pattern, I use AsyncAPI specification extensions called x-response.

1messages:
2 ping:
3summary: Ping serverto determine whether connectionis alive
4 description: Client can ping serverto determine whether connectionis alive, server responds with pong. This is an application level ping as opposed todefault ping in websockets standard which isserver initiated
5 payload:
6 $ref: '#/components/schemas/ping'7 x-response:
8 $ref: '#/components/messages/pong'

Even though the reference to another object is provided inside the extension that is not part of AsyncAPI, our parser will resolve it correctly. It means that under x-response property, I will have access to the entire message object.

Schemas vs JSON Schema

Because the message itself is most important in the entire EDA, you need to describe the message payload properly.

AsyncAPI allows you to provide payload information in different schema formats. The default format is AsyncAPI Schema that is a superset of JSON Schema. You can use others too, like Avro, for example.

From the AsyncAPI document point of view, the most important is that you can reuse schemas. In other words, instead of providing data directly to the payload object, you can $ref them from components.schemas or even an external document. Just DRY, right?

The rest, I would say, has nothing to do with AsyncAPI itself. How you structure schemas depends on you and the schema format that you use. It is why the next sections of my article describe something specific, not for the AsyncAPI itself but rather JSON Schema.

Simplest example of schemas from Kraken API is a payload for ping message:

1schemas:2 ping:3 type: object
4 properties:5 event:6 type: string
7 const: ping
8 reqid:9 $ref: '#/components/schemas/reqid'10 required:11 - event
12 reqid:13 type: integer
14 description: client originated ID reflected in response message.

You can see that ping message is an object that has two properties where only one is required. One property is used across other messages, so is part of many different schemas, so better to keep its definition as a separate schema and reference where needed.

Schemas complexity

Splitting schemas into reusable chunks with $ref usage is not something complex. It gets complex when messages are complex, when you get different message payload depending on system behavior.

Kraken API has a subscriptionStatus message where payload depends on the success of the subscription. In case of successful subscription, you get a message with channelID and channelName properties, but in case of failure, the message doesn't contain these properties but in exchange has errorMessage. In other words, some properties are mutually exclusive.

1 subscriptionStatus:2 type: object
3 oneOf:4 - required:
5 - errorMessage
6 not:7 required:8 - channelID
9 - channelName
10 - required:
11 - channelID
12 - channelName
13 not:14 required:15 - errorMessage
16 properties:17 channelID:18 type: integer
19 description: ChannelID on successful subscription, applicable to public messages only.
20 channelName:21 type: string
22 description: Channel Name on successful subscription. For payloads 'ohlc' and 'book', respective interval or depth will be added as suffix.
23 errorMessage:24 type: string
25 event:26 type: string
27 const: subscriptionStatus
28 reqid:29 $ref: '#/components/schemas/reqid'30 pair:31 $ref: '#/components/schemas/pair'32 status:33 $ref: '#/components/schemas/status'34 subscription:35 type: object
36 properties:37 depth:38 $ref: '#/components/schemas/depth'39 interval:40 $ref: '#/components/schemas/interval'41 maxratecount:42 $ref: '#/components/schemas/maxratecount'43 name:44 $ref: '#/components/schemas/name'45 token:46 $ref: '#/components/schemas/token'47 required:48 - name
49 required:50 - event

It is what I call a complex schema, where good JSON Schema knowledge is needed. The problem with complex schemas is that not many tools support these kinds of schemas. By the time I write this article, our AsyncAPI tools for documentation rendering will fail to render the above schema correctly.

It is why you sometimes need compromises and adjusts schemas, so they get proper tooling support. Below you can see the same schema but structured in a more straightforward way supported by most tools.

1 subscriptionStatus:
2type: object3 oneOf:
4 - $ref: '#/components/schemas/subscriptionStatusError'5 - $ref: '#/components/schemas/subscriptionStatusSuccess'6 subscriptionStatusError:
7 allOf:
8 - properties:
9 errorMessage:
10type: string
11 required:
12 - errorMessage
13 - $ref: '#/components/schemas/subscriptionStatusCommon'14 subscriptionStatusSuccess:
15 allOf:
16 - properties:
17 channelID:
18type: integer19 description: ChannelID on successful subscription, applicable topublic messages only.
20 channelName:
21type: string
22 description: Channel Nameon successful subscription. For payloads 'ohlc'and'book', respective intervalor depth will be added as suffix.
23 required:
24 - channelID
25 - channelName
26 - $ref: '#/components/schemas/subscriptionStatusCommon'27 subscriptionStatusCommon:
28type: object29 required:
30 - event
31 properties:
32 event:
33type: string
34 const: subscriptionStatus
35 reqid:
36 $ref: '#/components/schemas/reqid'37 pair:
38 $ref: '#/components/schemas/pair'39 status:
40 $ref: '#/components/schemas/status'41subscription:
42 required:
43 - name44type: object45 properties:
46 depth:
47 $ref: '#/components/schemas/depth'48interval:
49 $ref: '#/components/schemas/interval'50 maxratecount:
51 $ref: '#/components/schemas/maxratecount'52name:
53 $ref: '#/components/schemas/name'54 token:
55 $ref: '#/components/schemas/token'

I managed to get a structure that will be nicely rendered in the UI. Even code generation will work well. It is a bit more complex than initial structure, although this is rather subjective personal-taste-like opinion.

Let's have a look at the final document

Websocket protocol is very flexible, and therefore you can implement the server in many different ways. The path that Kraken API took is complex but not impossible to describe with the AsyncAPI document. Look at the document's final structure and keep in mind that it is not a complete document for Kraken API and the road that I chose to get to Rome was to focus on documentation rendering only.

For automation road described in section Choosing the right road to Rome, the document should be split into two documents: one for private and one for public servers. Common parts, like common messages and schemas, should be stored in separate files and referred from these two AsyncAPI documents using $ref. Another solution would be to use specification extensions to describe relations between messages and servers.

You can open this document directly in AsyncAPI Studio by clicking this link. Compare it also with the original documentation.

1asyncapi:2.0.02
3info:4title:KrakenWebsocketsAPI5version:'1.8.0'6description:|
7 WebSockets API offers real-time market data updates. WebSockets is a bidirectional protocol offering fastest real-time data, helping you build real-time applications. The public message types presented below do not require authentication. Private-data messages can be subscribed on a separate authenticated endpoint. 
89### General Considerations10
11-TLSwithSNI(ServerNameIndication)isrequiredinordertoestablishaKrakenWebSocketsAPIconnection.SeeCloudflare's [WhatisSNI?](https://www.cloudflare.com/learning/ssl/what-is-sni/)guideformoredetails.12-AllmessagessentandreceivedviaWebSocketsareencodedinJSONformat13-Alldecimalfields(includingtimestamps)arequotedtopreserveprecision.14-TimestampsshouldnotbeconsidereduniqueandnotbeconsideredasaliasesfortransactionIDs.Also,thegranularityoftimestampsisnotrepresentativeoftransactionrates.15-Atleastoneprivatemessageshouldbesubscribedtokeeptheauthenticatedclientconnectionopen.16-PleaseuseRESTAPIendpoint [AssetPairs](https://www.kraken.com/features/api#get-tradable-pairs)tofetchthelistofpairswhichcanbesubscribedviaWebSocketsAPI.Forexample,field'wsname'givesthesupportedpairsnamewhichcanbeusedtosubscribe.17-Cloudflareimposesaconnection/re-connectionratelimit(perIPaddress)ofapproximately150attemptsperrolling10minutes.Ifthisisexceeded,theIPisbannedfor10minutes.18-Recommendedreconnectionbehaviouristo(1)attemptreconnectioninstantlyuptoahandfuloftimesifthewebsocketisdroppedrandomlyduringnormaloperationbut(2)aftermaintenanceorextendeddowntime,attempttoreconnectnomorequicklythanonceevery5seconds.Thereisnoadvantagetoreconnectingmorerapidlyaftermaintenanceduringcancel_onlymode.19
20servers:21public:22url:ws.kraken.com23protocol:wss24description:|
25 Public server available without authorization.
26 Once the socket is open you can subscribe to a public channel by sending a subscribe request message.
27private:28url:ws-auth.kraken.com29protocol:wss30description:|
31 Private server that requires authorization.
32 Once the socket is open you can subscribe to private-data channels by sending an authenticated subscribe request message.
3334TheAPIclientmustrequestanauthentication"token"viathefollowingRESTAPIendpoint"GetWebSocketsToken"toconnecttoWebSocketsPrivateendpoints.Formoredetailsreadhttps://support.kraken.com/hc/en-us/articles/360034437672-How-to-retrieve-a-WebSocket-authentication-token-Example-code-in-Python-335
36Theresultingtokenmustbeprovidedinthe"token"field of any new private WebSocket feed subscription:37```38 {
39"event":"subscribe",
40"subscription":41 {
42"name":"ownTrades",
43"token":"WW91ciBhdXRoZW50aWNhdGlvbiB0b2tlbiBnb2VzIGhlcmUu"44 }
45 }
46```47
48channels:49/:50publish:51description:SendmessagestotheAPI52operationId:processReceivedMessage53message:54oneOf:55-$ref:'#/components/messages/ping'56-$ref:'#/components/messages/subscribe'57-$ref:'#/components/messages/unsubscribe'58
59subscribe:60description:MessagesthatyoureceivefromtheAPI61operationId:sendMessage62message:63oneOf:64-$ref:'#/components/messages/pong'65-$ref:'#/components/messages/heartbeat'66-$ref:'#/components/messages/systemStatus'67-$ref:'#/components/messages/subscriptionStatus'68
69components:70messages:71ping:72summary:Pingservertodeterminewhetherconnectionisalive73description:Clientcanpingservertodeterminewhetherconnectionisalive,serverrespondswithpong.Thisisanapplicationlevelpingasopposedtodefaultpinginwebsocketsstandardwhichisserverinitiated74payload:75$ref:'#/components/schemas/ping'76x-response:77$ref:'#/components/messages/pong'78heartbeat:79description:Serverheartbeatsentifnosubscriptiontrafficwithin1second(approximately)80payload:81$ref:'#/components/schemas/heartbeat'82pong:83summary:Pongisaresponsetopingmessage84description:Serverpongresponsetoapingtodeterminewhetherconnectionisalive.Thisisanapplicationlevelpongasopposedtodefaultponginwebsocketsstandardwhichissentbyclientinresponsetoaping85payload:86$ref:'#/components/schemas/pong'87systemStatus:88description:Statussentonconnectionorsystemstatuschanges.89payload:90$ref:'#/components/schemas/systemStatus'91examples:92-payload:93connectionID:862861539084861000094event:systemStatus95status:online96version:1.0.097subscribe:98description:Subscribetoatopiconasingleormultiplecurrencypairs.99payload:100$ref:'#/components/schemas/subscribe'101examples:102-payload:103event:subscribe104pair:105-XBT/USD106-XBT/EUR107subscription:108name:ticker109-payload:110event:subscribe111subscription:112name:ownTrades113token:WW91ciBhdXRoZW50aWNhdGlvbiB0b2tlbiBnb2VzIGhlcmUu114x-response:115$ref:'#/components/messages/subscriptionStatus'116unsubscribe:117description:Unsubscribe,canspecifyachannelIDormultiplecurrencypairs.118payload:119$ref:'#/components/schemas/subscribe'120examples:121-payload:122event:unsubscribe123pair:124-XBT/EUR125-XBT/USD126subscription:127name:ticker128-payload:129event:unsubscribe130subscription:131name:ownTrades132token:WW91ciBhdXRoZW50aWNhdGlvbiB0b2tlbiBnb2VzIGhlcmUu133x-response:134$ref:'#/components/messages/subscriptionStatus'135subscriptionStatus:136description:Subscriptionstatusresponsetosubscribe,unsubscribeorexchangeinitiatedunsubscribe.137payload:138$ref:'#/components/schemas/subscriptionStatus'139examples:140-payload:141channelID:10001142channelName:ohlc-5143event:subscriptionStatus144pair:XBT/EUR145reqid:42146status:unsubscribed147subscription:148interval:5149name:ohlc150-payload:151errorMessage:Subscriptiondepthnotsupported152event:subscriptionStatus153pair:XBT/USD154status:error155subscription:156depth:42157name:book158
159schemas:160ping:161type:object162properties:163event:164type:string165const:ping166reqid:167$ref:'#/components/schemas/reqid'168required:169-event170heartbeat:171type:object172properties:173event:174type:string175const:heartbeat176pong:177type:object178properties:179event:180type:string181const:pong182reqid:183$ref:'#/components/schemas/reqid'184systemStatus:185type:object186properties:187event:188type:string189const:systemStatus190connectionID:191type:integer192description:TheIDoftheconnection193status:194$ref:'#/components/schemas/status'195version:196type:string197status:198type:string199enum:200-online201-maintenance202-cancel_only203-limit_only204-post_only205subscribe:206type:object207properties:208event:209type:string210const:subscribe211reqid:212$ref:'#/components/schemas/reqid'213pair:214$ref:'#/components/schemas/pair'215subscription:216type:object217properties:218depth:219$ref:'#/components/schemas/depth'220interval:221$ref:'#/components/schemas/interval'222name:223$ref:'#/components/schemas/name'224ratecounter:225$ref:'#/components/schemas/ratecounter'226snapshot:227$ref:'#/components/schemas/snapshot'228token:229$ref:'#/components/schemas/token'230required:231-name232required:233-event234unsubscribe:235type:object236properties:237event:238type:string239const:unsubscribe240reqid:241$ref:'#/components/schemas/reqid'242pair:243$ref:'#/components/schemas/pair'244subscription:245type:object246properties:247depth:248$ref:'#/components/schemas/depth'249interval:250$ref:'#/components/schemas/interval'251name:252$ref:'#/components/schemas/name'253token:254$ref:'#/components/schemas/token'255required:256-name257required:258-event259subscriptionStatus:260type:object261oneOf:262-$ref:'#/components/schemas/subscriptionStatusError'263-$ref:'#/components/schemas/subscriptionStatusSuccess'264subscriptionStatusError:265allOf:266-properties:267errorMessage:268type:string269required:270-errorMessage271-$ref:'#/components/schemas/subscriptionStatusCommon'272subscriptionStatusSuccess:273allOf:274-properties:275channelID:276type:integer277description:ChannelIDonsuccessfulsubscription,applicabletopublicmessagesonly.278channelName:279type:string280description:ChannelNameonsuccessfulsubscription.Forpayloads'ohlc'and'book',respectiveintervalordepthwillbeaddedassuffix.281required:282-channelID283-channelName284-$ref:'#/components/schemas/subscriptionStatusCommon'285subscriptionStatusCommon:286type:object287required:288-event289properties:290event:291type:string292const:subscriptionStatus293reqid:294$ref:'#/components/schemas/reqid'295pair:296$ref:'#/components/schemas/pair'297status:298$ref:'#/components/schemas/status'299subscription:300required:301-name302type:object303properties:304depth:305$ref:'#/components/schemas/depth'306interval:307$ref:'#/components/schemas/interval'308maxratecount:309$ref:'#/components/schemas/maxratecount'310name:311$ref:'#/components/schemas/name'312token:313$ref:'#/components/schemas/token'314interval:315type:integer316description:Timeintervalassociatedwithohlcsubscriptioninminutes.317default:1318enum:319-1320-5321-15322-30323-60324-240325-1440326-10080327-21600328name:329type:string330description:Thenameofthechannelyousubscribetoo.331enum:332-book333-ohlc334-openOrders335-ownTrades336-spread337-ticker338-trade339token:340type:string341description:base64-encodedauthenticationtokenforprivate-dataendpoints.342depth:343type:integer344default:10345enum:346-10347-25348-100349-500350-1000351description:Depthassociatedwithbooksubscriptioninnumberoflevelseachside.352maxratecount:353type:integer354description:Maxrate-limitbudget.ComparetotheratecounterfieldintheopenOrdersupdatestocheckwhetheryouareapproachingtheratelimit.355ratecounter:356type:boolean357default:false358description:Whethertosendrate-limitcounterinupdates(supportedonlyforopenOrderssubscriptions)359snapshot:360type:boolean361default:true362description:Whethertosendhistoricalfeeddatasnapshotuponsubscription(supportedonlyforownTradessubscriptions)363reqid:364type:integer365description:clientoriginatedIDreflectedinresponsemessage.366pair:367type:array368description:Arrayofcurrencypairs.369items:370type:string371description:Formatofeachpairis"A/B",whereAandBareISO4217-A3forstandardizedassetsandpopularuniquesymbolifnotstandardized.372pattern:'[A-Z\s]+\/[A-Z\s]+'

Stay tuned for more articles around WebSocket and AsyncAPI. Share your feedback and connect with the AsyncAPI community in our Slack workspace.