DavidOp
-
Content Count
4 -
Joined
-
Last visited
Posts posted by DavidOp
-
-
Tested and find the final solution:
(lSWC.IOHandler as TIdSSLIOHandlerSocketOpenSSL).PassThrough:=false;
lSWC.Connect('wss://stream.binance.com:9443/ws');
lSWC.writeText('{"method": "SUBSCRIBE","params": ["btcusdt@kline_15m"],"id": 1}');lSWC.writeText('{"method": "SUBSCRIBE","params": ["ethusdt@kline_15m"],"id": 1}');
....
One connection is allowed so you can not run two "connection" command. You have to connect to Binance first and use JSON format to SUBSCRIBE to the crypto/history/candlestick/kindle.
Of course you can use the command (and use this format):
lSWC.Connect('wss://stream.binance.com:9443/ws/btcusdt@kline_15m/ethusdt@kline_15m/.../...'); but it can not be long (maybe 1500 is the max char sum) or it won't work.
The PassThrough section needs to be used before connection command.
PS:
HEADER: X-CMC_PRO_API_KEY= your_api_key -> wrong
HEADER: X-MBX-APIKEY = .... -> right one
-
I use Delphi websocket to get data from Binance.
uses IdIOHandler, IdIOHandlerSocket, IdIOHandlerStack, IdSSL, IdSSLOpenSSL, IdWebSocketSimpleClient;
type
...
procedure lSWC1DataEvent(Sender: TObject; const Text: string);
private
...
public
...
procedure TForm1.lSWC1DataEvent(Sender: TObject; const Text: string);
begin
Form1.smemo1.Lines.Add(text);
end;#use these parameters to avoid SSL3_READ_BYTES:sslv3 alert handshake failure
procedure TForm1.Button1Click(Sender: TObject);
var lSWC:TIdSimpleWebSocketClient;
begin
lSWC := TIdSimpleWebSocketClient.Create(self);
lSWC.onDataEvent := lSWC1DataEvent; //:= self.lSWC1DataEvent; //TSWSCDataEvent
lSWC.AutoCreateHandler := false;
if not lSWC.AutoCreateHandler then
begin
if lSWC.IOHandler=nil then
lSWC.IOHandler := TIdSSLIOHandlerSocketOpenSSL.Create(lSWC);
(lSWC.IOHandler as TIdSSLIOHandlerSocketOpenSSL).SSLOptions.Mode := TIdSSLMode.sslmClient;(lSWC.IOHandler as TIdSSLIOHandlerSocketOpenSSL).SSLOptions.Method := sslvSSLv23;
(lSWC.IOHandler as TIdSSLIOHandlerSocketOpenSSL).SSLOptions.SSLVersions := [TIdSSLVersion.sslvSSLv23];
end;lSWC.Connect('wss://stream.binance.com:9443/ws/btcusdt@kline_15m');
(lSWC.IOHandler as TIdSSLIOHandlerSocketOpenSSL).PassThrough:=false;
end;added this .pas to my Project:
https://github.com/arvanus/Indy/blob/WebSocketImpl/Lib/Core/IdWebSocketSimpleClient.pas
- 1
-
I wrote a program in Delphi 10 which uses REST components to connect to Binance.
In Delphi 10 you can use REST debugger to test the connection and get all the data and components which you can copy to the Form.
In REST debugger:
Request menu:
Method: GET
URL: https://api.binance.com/api/v3/exchangeInfo
(if you generated API KEY you can use that:
Parameters menu:
HEADER: X-CMC_PRO_API_KEY= your_api_key
HEADER: Accept=application/json
)
Click on Send Request and you'll get the data.
On Tabulator Data menu you modify this:
JSON Root Element: symbols
click on "Nested"
click on Apply
You get the all the data from Cryptos you want.
Click on "Copy Components" then create a the Form and paste the components to the Form.
Create a stringgrid to the form.
Click on RESTRequest1 and choose Execute.
Click right mouse button on the form1 and choose Bind Visually.
Link the MemTable to the StringGrid.
And you are done!
You will see the data from Binance!
Delphi Binance API program
in Network, Cloud and Web
Posted
Sometimes needs to be waiting few more seceonds:
lSWC.Connect('wss://stream.binance.com:9443/ws');
sleep(3000);
lSWC.writeText('{"method": "SUBSCRIBE","params": ["btcusdt@kline_15m"],"id": 1}');