Вверх ↑
Ответов: 649
Рейтинг: 138
#1: 2023-09-04 15:26:34 ЛС | профиль | цитата
Подключение к websocket серверу с помощью cscript и jscript -а

Пример: подписка на bookticker по паре BTCUSDT с биржи bybit

Add(MainForm,16417920,70,196)
{
Width=948
Point(onClose)
link(onCreate,14115103:doString,[])
link(onClose,8827366:doConsoleTerminate,[(116,223)(116,251)(263,251)(263,223)])
}
Add(Memo,6453024,413,217)
{
Width=932
Height=261
Align=5
ScrollBars=3
}
Add(WinExec,8827366,287,196)
{
FileName="cscript"
Mode=0
Point(doConsoleExec)
Point(onErrorExec)
Point(onConsoleResult)
Point(doConsoleTerminate)
link(onErrorExec,85276:doWork1,[(340,216)])
link(onConsoleResult,85276:doWork2,[])
}
Add(BlockFind,8178086,357,217)
{
StartBlock="{"
EndBlock="}"
link(onSearch,6453024:doAdd,[])
}
Add(FormatStr,14115103,126,210)
{
Mask="var StdIn = WSH.StdIn, StdOut = WSH.StdOut, StdErr = WSH.StdErr; \r\nvar document = new ActiveXObject('htmlfile');\r\ndocument.write('<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />');\r\nvar window = document.Script, JSON = window.JSON, WebSocket = window.WebSocket;\r\nvar url = '%1';\r\nvar ws = new WebSocket(url);\r\nws.onopen = function(event){ws.send('%2');}\r\nws.onmessage = function(event){StdOut.WriteLine(event.data);}\r\nws.onerror = function(event){StdErr.WriteLine('Web socket error !');}\r\nws.onclose = function(event){StdOut.WriteLine('Web socket closed');WSH.Quit();}\r\nwhile(-1){WSH.Sleep(100);}"
link(onFString,927093:doConvert,[])
link(Str1,16770708:Text,[])
link(Str2,2968059:Text,[])
}
Add(TempFileStream,8761983,224,210)
{
Extention=".js"
link(onCreate,8827366:doConsoleExec,[])
}
Add(StreamConvertor,927093,175,210)
{
Mode=7
link(onResult,8761983:doCreate,[])
}
Add(VisualStrings,16770708,126,133)
{
@Hint=#24:WebSocket public channel|
Lines=#37:wss://stream.bybit.com/spot/public/v3|
Width=207
AddHint(272,-2,144,13,@Hint)
}
Add(VisualStrings,2968059,133,161)
{
@Hint=#19:Subscribe to Topics|
Lines=#48:{"op":"subscribe","args":["bookticker.BTCUSDT"]}|
Width=270
AddHint(302,-1,109,13,@Hint)
}
Add(HubEx,85276,336,217)
{
link(onEvent,8178086:doSearch,[])
}

Проверено на
- Windows 10 (x64)
- Hiasm v4.05 build 186 (delphi) rev - 2404
карма: 14

0