You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on May 13, 2024. It is now read-only.
Copy file name to clipboardExpand all lines: docs/core-concepts/api-calls-anatomy/index.md
+15-15Lines changed: 15 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
---
2
2
title: API calls' anatomy
3
-
hide_title: true
3
+
hide_title: false
4
4
draft: false
5
5
sidebar_label: API calls' anatomy
6
6
sidebar_position: 1
@@ -27,26 +27,26 @@ Some of these API calls automatically subscribe (e.g. [ticks](https://api.deriv.
27
27
28
28
For example, you can call [Tick History](https://api.deriv.com/api-explorer#ticks_history) to receive tick history data. But when you add the `subscribe` option to this call, you will receive the tick history data you requested in the first response, and you will continue to receive a new response every time there is a new tick published by the server for the given symbol.
29
29
30
-
In the message stream from `subscribe` there is a field called `subscription`, this is the `Stream ID`. with this ID you can identify the message stream in your logic and stop the stream with `Forget` and `Forget All` API calls.
30
+
In the message stream from `subscribe`, there is a field called `subscription`. This is the `Stream ID`. With this ID, you can identify the message stream in your logic and stop the stream with `Forget` and `Forget All` API calls.
31
31
32
32
The data provided by API calls with the `subscribe` functionality can be used as a data source for other API calls and features.
33
33
34
34
### Send
35
35
36
-
If you call the API with the `send` functionality, then the server will only send back the requested data one time. In order to get updated data you have to send the API call again. Usually, this method is used when you get other API call responses or UI events such as `Click`, `Scroll` and more.
36
+
If you call the API with the `send` functionality, then the server will only send back the requested data one time. In order to get updated data, you have to send the API call again. Usually, this method is used when you get other API call responses or UI events such as `Click`, `Scroll`, and more.
37
37
38
38
### Forget
39
39
40
-
If you want to stop the message Stream created by `subscribe`, you will have to call the `Forget` API call with the correct `Stream ID`. Otherwise, you can use the `Forget All` API call to stop streams by their `Method name`.
40
+
If you want to stop the message stream created by `subscribe`, you will have to call the `Forget` API call with the correct `Stream ID`. Otherwise, you can use the `Forget All` API call to stop streams by their `Method name`.
41
41
42
42
:::caution
43
-
For more information on the `Forget` API call, you can have a look at [Forget](https://api.deriv.com/api-explorer#forget) and [Forget All](https://api.deriv.com/api-explorer#forget_all) in the API explorer.
43
+
For more information on the `Forget` API call, have a look at [Forget](https://api.deriv.com/api-explorer#forget) and [Forget All](https://api.deriv.com/api-explorer#forget_all) in the API explorer.
44
44
:::
45
45
46
46
47
47
## Request data
48
48
49
-
In order to make it easier for you to handle the `request` and `response` flow of your WebSocket connection, every deriv WebSocket API calls has a general structure. you can use it for caching, validation, request and response synchronization are some of the things you can use it for.
49
+
To make it easier for you to handle the request and response flow of your WebSocket connection, each Deriv WebSocket API call follows a standardised structure. You can use it for caching, validation, request, and response synchronisation.
50
50
51
51
#### API call method name
52
52
@@ -58,11 +58,11 @@ API Call Method Name is always required. this field determines the data you'll g
58
58
59
59
### Required fields
60
60
61
-
Every request data has several required fields which you must provide them and they may contain optional fields as well, let's explore this with an example on`Residence List`:
61
+
Each request data has mandatory fields that you must provide, and it may also include optional fields. Let's explore this with an example from`Residence List`.
62
62
63
-
`Residence List`Call returns a list of countries and 2-letter country codes, suitable for populating the account opening form.
63
+
A `Residence List`call returns a list of countries and 2-letter country codes, suitable for populating the account opening form.
64
64
65
-
Request data for this call is like so:
65
+
The request data for this call is as below:
66
66
67
67
```ts
68
68
{
@@ -72,19 +72,19 @@ Request data for this call is like so:
72
72
}
73
73
```
74
74
75
-
The `residence_list` field is the `method name` for the call and is required. There may be other required fields which are related to this type of the request you want to send. if you want to know more about `Residence List` and other API calls please check them out in the[API Explorer](https://api.deriv.com/api-explorer#residence_list).
75
+
The `residence_list` field is the `method name` for the call and is required. There may be other required fields related to this type of the request you want to send. To know more about `Residence List` and other API calls, please check them out in [API Explorer](https://api.deriv.com/api-explorer#residence_list).
76
76
77
77
### Optional fields
78
78
79
-
Every Call has several `Optional` fields as well, `passthrough` and `req_id` are always part of the request data but you can choose to opt-out and not use them.
79
+
Every call has several `Optional` fields as well. `Passthrough` and `req_id` are always part of the request data but you can choose to optout and not use them.
80
80
81
-
#### `passthrough` field
81
+
#### The `passthrough` field
82
82
83
-
Whatever you pass to this field will be returned back to you inside a `response` object, this can be helpful when you need to simulate a stateful flow for your `requests` and `responses`.
83
+
Whatever you pass to this field will be returned back to you inside a `response` object. This can be helpful when you need to simulate a stateful flow for your `requests` and `responses`.
84
84
85
-
#### `req_id` field
85
+
#### The `req_id` field
86
86
87
-
You may need to `tag` your requests and pass them through our `WebSocket` calls. you can do it by passing a `number` to this field. it can be helpful when you need to map `requests` to `responses`.
87
+
You may need to `tag` your requests and pass them through our `WebSocket` calls. You can do so by passing a `number` to this field. it can be helpful when you need to map `requests` to `responses`.
88
88
89
89
:::caution
90
90
To learn about additional optional fields specific to each API call, please refer to our [API Explorer](https://api.deriv.com/api-explorer).
Copy file name to clipboardExpand all lines: docs/core-concepts/websocket/index.md
+9-9Lines changed: 9 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -77,7 +77,7 @@ socket.onerror = function (error) {
77
77
};
78
78
```
79
79
80
-
## Why do we need websocket and when should we avoid it?
80
+
## Why do we need WebSockets and when should we avoid them?
81
81
82
82
WebSocket are an essential client-server communication tool and one needs to be fully aware of its utility and avoid scenarios to benefit from its utmost potential. It’s explained extensively in the next section.
83
83
@@ -95,25 +95,25 @@ WebSocket shouldn’t be taken onboard when old data fetching is the need of the
95
95
96
96
## WebSocket vs HTTP
97
97
98
-
As both HTTP and WebSocket are employed for application communication, people often get confused and find it difficult to pick one out of these two. Have a look at the below-mentioned text and gain better clarity on HTTP and WebSocket.
98
+
As both HTTP and WebSocket protocols are employed for application communication, people often get confused and find it difficult to pick one.
99
99
100
-
As told previously, WebSocket is a framed and bidirectional protocol. On the contrary, to this, HTTP is a unidirectional protocol functioning above the TCP protocol.
100
+
As told previously, WebSocket is a framed and bidirectional protocol. On the other hand, HTTP is a unidirectional protocol functioning above the TCP protocol.
101
101
102
-
As WebSocket protocol is capable to support continual data transmission, it’s majorly used in real-time application development. HTTP is stateless and is used for the development of [RESTful](https://de.wikipedia.org/wiki/Representational_State_Transfer) and [SOAP](https://de.wikipedia.org/wiki/SOAP) applications. Soap can still use HTTP for implementation, but REST is widely spread and used.
102
+
As the WebSocket protocol is capable of supporting continual data transmission, it’s majorly used in real-time application development. HTTP is stateless and is used for the development of [RESTful](https://de.wikipedia.org/wiki/Representational_State_Transfer) and [SOAP](https://de.wikipedia.org/wiki/SOAP) applications. SOAP can still use HTTP for implementation, but REST is widely spread and used.
103
103
104
-
In WebSocket, communication occurs at both ends, which makes it a faster protocol. In HTTP, the connection is built at one end, making it a bit sluggish than WebSocket.
104
+
In WebSocket, communication occurs at both ends, which makes it a faster protocol. In HTTP, the connection is built at one end, making it a bit more sluggish than WebSocket.
105
105
106
106
WebSocket uses a unified TCP connection and needs one party to terminate the connection. Until it happens, the connection remains active. HTTP needs to build a distinct connection for separate requests. Once the request is completed, the connection breaks automatically.
107
107
108
108
## How are WebSocket connections established?
109
109
110
-
The process starts with a WebSocket handshake that involves using a new scheme ws or wss. To understand quickly, you may consider them equivalent to HTTP and secure HTTP (HTTPS) respectively.
110
+
The process starts with a WebSocket handshake that involves using a new scheme (ws or wss). To help you understand, consider them equivalent to HTTP and secure HTTP (HTTPS) respectively.
111
111
112
-
Using this scheme, servers and clients are expected to follow the standard WebSocket connection protocol. The WebSocket connection establishment begins with HTTP request upgrading that features a couple of headers such as Connection: Upgrade, Upgrade: WebSocket, Sec-WebSocket- Key, and so on.
112
+
Using this scheme, servers and clients are expected to follow the standard WebSocket connection protocol. The WebSocket connection establishment begins with a HTTP request upgrading that features a couple of headers such as Connection: Upgrade, Upgrade: WebSocket, Sec-WebSocket- Key, and so on.
113
113
114
114
Here is how this connection is established:
115
115
116
-
1.**The Request :** Connection Upgrade header denotes the WebSocket handshake while the Sec-WebSocket-Key features Base64-encoded random value. This value is arbitrarily generated during every WebSocket handshake. Besides the above, the key header is also a part of this request.
116
+
1.**The Request :**The Connection Upgrade header denotes the WebSocket handshake while the Sec-WebSocket-Key features Base64-encoded random value. This value is arbitrarily generated during every WebSocket handshake. Besides the above, the key header is also a part of this request.
117
117
118
118
The above-listed headers, when combined, form an HTTP GET request. It will have similar data in it:
119
119
@@ -128,7 +128,7 @@ Sec-WebSocket-Version: 13
128
128
Sec-WebSocket-Key: b6gjhT32u488lpuRwKaOWs==
129
129
```
130
130
131
-
To clarify, Sec-WebSocket-Version, one can explain the WebSocket protocol version ready to use for the client.
131
+
To clarify Sec-WebSocket-Version, one can explain the WebSocket protocol version ready to use for the client.
132
132
133
133
2.**The Response:** The response header, Sec-WebSocket-Accept, features the rest of value submitted in the Sec-WebSocket-Key request header. This is connected with a particular protocol specification and is used widely to keep misleading information at bay. In other words, it enhances the API security and stops ill-configured servers from creating blunders in the application development.
Copy file name to clipboardExpand all lines: docs/languages/javascript/project-setup/index.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -30,13 +30,13 @@ Next, create the required files as you see below:
30
30
touch index.html index.css index.js
31
31
```
32
32
33
-
Now, you can open the folder with your prefered code editor or IDE.
34
-
35
33
:::tip
36
34
We suggest using [Visual Studio Code](https://code.visualstudio.com/) with [Live Server Extension](https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer) enabled. This will help you a lot with implementations.
37
35
:::
38
36
39
-
Your final code should be:
37
+
Now open the `index.html` file or use the [Live Server Extension](https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer)
38
+
39
+
Now, change the content of the files using the following approach:
40
40
41
41
```js title="index.js"
42
42
console.log("we will create our websocket connection here");
Copy file name to clipboardExpand all lines: docs/languages/javascript/websocket-connection/index.md
+3-4Lines changed: 3 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,10 +17,9 @@ If you're not familiar with WebSockets, please check out [our documentation](/do
17
17
:::
18
18
19
19
### Set up a WebSocket connection
20
+
<!-- To create a websocket connection, we want to use the Deriv websocket URL with an `app_id`. You can create your own app_id within your [dashboard](/dashboard) or keep the default `1089` app_id for testing. Keep in mind that eventually, you should make your own app_id. Especially if you would like to monetize your application. -->
20
21
21
-
To create a websocket connection, we want to use the Deriv websocket URL with an `app_id`. You can create your own app_id within your [dashboard](/dashboard) or keep the default `1089` app_id for testing. Keep in mind that eventually, you should make your own app_id. Especially if you would like to monetize your application.
22
-
23
-
To setup the connection, add the following code in your JavaScript file:
22
+
Next, we'll create a WebSocket connection to Deriv WebSocket Server as seen below:
24
23
25
24
```js title="index.js"
26
25
constapp_id=1089; // Replace with your app_id or leave as 1089 for testing.
@@ -72,7 +71,7 @@ Now, open the `index.html` file in our browser and check your developer console.
72
71
73
72
### Send and receive data
74
73
75
-
Our WebSocket server provides a [ping/pong](/api-explorer#ping) functionality. Let's use it in our demo project to send and receive data. Change the event listeners for `open` and `message` as below:
74
+
Our WebSocket server provides [ping/pong](/api-explorer#ping) functionality. Let's use it in our demo project to send and receive data. Change the event listeners for `open` and `message` as below:
76
75
77
76
:::caution
78
77
The `send` function on the WebSocket connection, only receives `string`, `ArrayBuffer`, `Blob`, `TypedArray` and `DataView`. You can read more about them on [MDN](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/send). This means, if we want to send an `object`, we have to stringify it with `JSON.stringify` first.
0 commit comments