Jump to content

WebSocket connection to XTB - (Moved)


Recommended Posts

Hello,

I would like to get real time data and communicate with the server of XTB.
My script below does not work. I do not know how to send JSON commands to the server with socket connection.
The server connection is described here:

http://developers.xstore.pro/documentation/#communication-with-the-xstation-api

They write:

Furthermore, WebSockets can be used to connect to the API using the following addresses:

  • wss://ws.xtb.com/demo

My code is below, but nothing comes back:, $hRequest is reamain empty
(I want to send a Ping to the server, and check if it asnwers, as first step)

_______________________________________________________________________________________________

$hOpen = _WinHttpOpen()
$hConnect = _WinHttpConnect($hOpen, "ws.xtb.com")
$hRequest  = _WinHttpSimpleSSLRequest($hConnect  , "POST"  , "/demo" , Default  , '{"command":"ping"}' )

_WinHttpSendRequest($hRequest)
$bResults = _WinHttpReceiveResponse($hRequest)

 _WinHttpCloseHandle($hRequest)
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)

_____________________________________________________________________________________________

This reports error at _WinHttpSendRequest($hRequest), I guess, because hRequest is empty.

What is the solution ?

 

(By the way, how can I insert here in this Forum my code so, that it will be showed with colors, like in AutoIT edit field ?)

THX !

 

 

Spoiler

 

Link to comment
Share on other sites

9 minutes ago, Cinemizer said:

(By the way, how can I insert here in this Forum my code so, that it will be showed with colors, like in AutoIT edit field ?)

how-to-post-code-on-the-forum ;)

Edited by Musashi

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

Hello,

I would like to get real time data and communicate with the server of XTB.
My script below does not work. I do not know how to send JSON commands to the server with socket connection.
The server connection is described here:

http://developers.xstore.pro/documentation/#communication-with-the-xstation-api

They write:

Furthermore, WebSockets can be used to connect to the API using the following addresses:

  • wss://ws.xtb.com/demo

My code is below, but nothing comes back:, $hRequest is reamain empty
(I want to send a Ping to the server, and check if it asnwers, as first step)

$hOpen = _WinHttpOpen()
$hConnect = _WinHttpConnect($hOpen, "ws.xtb.com")
$hRequest  = _WinHttpSimpleSSLRequest($hConnect  , "POST"  , "/demo" , Default  , '{"command":"ping"}' )

_WinHttpSendRequest($hRequest)
$bResults = _WinHttpReceiveResponse($hRequest)

 _WinHttpCloseHandle($hRequest)
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)

 

This reports error at _WinHttpSendRequest($hRequest), I guess, because hRequest is empty.

What is the solution ?

THX !

Link to comment
Share on other sites

  • Moderators

Moved to the appropriate forum, as the AutoIt Example Scripts forum very clearly states:

Quote

Share your cool AutoIt scripts, UDFs and applications with others.


Do not post general support questions here, instead use the AutoIt Help and Support forums.

Moderation Team

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

THX, it seems to be in the right direction.

However the XTB server does not answer.
I call the WebSocket example, you sent me with this parameters:

Local $sServerName = "ws.xtb.com"
Local $sPath = "demo"

Local $sMessage = '{"command":"ping"}'

I guess, the server should answer something, but he do not.

I get this answer:

Succesfully upgraded to websocket protocol
Sent message to the server: {"command":"ping"}
WebSocketReceive error
Application failed with error: 0x00002EFE
>Exit code: 4294967295    Time: 11.08

According the documentation of XTB the websocket communication goes over ws.xtb.com/demo

Where ist the failure ?

THX !

Link to comment
Share on other sites

Can it cause, that the server does not answer, because the WebSocket example, you sent me is written for ws message, but the server of XTB is communication over wss ?

According the documentation of XTB the websocket communication goes over wss://ws.xtb.com/demo

If it is so, could you please tell me, how to change the example script, to be able to send and receive secure wss messages ?

THX!

Edited by Cinemizer
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...