Open stream for the account
Error while loading OpenAPI operation — Invalid OpenAPI document
Parameters Upgrade andCoonection are the standard options for working with web sockets. Together, these options allow the client and server to establish a Web Sockets connection.
In our case, the value Connection: Upgradein the request and response headers is a signal to change the protocol from standard HTTP to the web socket protocol and Upgrade: websocket.
Features of working with open stream
Streaming connection: impormant to make ping request each 30 sec.
While opening open stream you should specify the query parameter as stream-auth (header Authorization in stream will be ignored).
If header
Authorizationis specified andserver_code,but query parameterstream-authis not specified, the authorization will not be succeed:
When the header and the query parameter are specified both, when authorization will succeed:
When opening stream query parameter is specified but header is not specified, when authorization will also succeed:
If authorization is not specified at all, you will get error = 401:
WebSocket request format is a JSON structure with the following fields:
id
big integer
unique identification of message the will be used in an asynchronous responce to the request
type
string
a request type, defined in below section
body
JSON structure
contains a set of fields/parameters for the request execution
example 1. with empty body:
example 2. Subscription to ticks:
Webscoket response structure
id
big integer [optional]
a unique identification of the message that was specified in the request
doesn’t used in subscriptions messages
type
string
a responce type, defined in below section
body
JSON structure
contains a set of fields/values returning after a request execution or in subscription messages
Example 1:
Example 2. Subscription to ticks:
In case of an error during a request execution the body of the responce include only two fields:
code- an integer code of the error from the MetaTrader Server if the code > 0 otherwise a system error code;message- a string with error description.
Also the response will have an object “error” with the following fields:
code- an integer code of the error from the MetaTrader Server if the code > 0 otherwise a system error codemessage- a string with error description
Example:
request: {"id": 11, "type":"CloseOrder", "body": {"ticket":969016, "volume": 0.01, "deviation": 100}}
response: {"id": 11, "type": "CloseOrder", "body": {"code":10036, "message":"Position doesn't exist"}, "error": {"code": 10036, "message": "unknown MT5 error"}}
The following errors can be generated by the system:
-1
when the requested type is not supported
-2
when the system throttles recieved message due to number of requests more then expected number of requests in a second
-3
when the system removes a message from the message queue due to big number unprocessed messages in the message queue
-9
timeout when the system did not get a responce from MT5 in expected timefrime specifically for acynchronus request for open/close/midification positions
-10017
Trade (for client) is disabled
-10018
Market closed (open/modificaion/close trade is not allowed)
Errors from MetaTrader
MT_RET_ERROR
2
Common error.
MT_RET_ERR_PARAMS
3
Invalid parameters.
MT_RET_ERR_DATA
4
Invalid information.
MT_RET_ERR_DISK
5
Hard disk error.
MT_RET_ERR_MEM
6
Memory error.
MT_RET_ERR_NETWORK
7
Network error.
MT_RET_ERR_PERMISSIONS
8
Not enough permissions to perform the operation.
MT_RET_ERR_TIMEOUT
9
Timeout expired.
MT_RET_ERR_CONNECTION
10
No connection.
MT_RET_ERR_NOSERVICE
11
Service is not available.
MT_RET_ERR_FREQUENT
12
Too frequent requests.
MT_RET_ERR_NOTFOUND
13
Not found.
MT_RET_ERR_PARTIAL
14
Partial error.
MT_RET_ERR_SHUTDOWN
15
Server shutdown in progress.
MT_RET_ERR_CANCEL
16
The operation has been canceled.
MT_RET_ERR_DUPLICATE
17
Duplicate information.
Last updated