Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Betfair Streaming API
#1
Hi,

I have searched everywhere trying to find a solution to this problem.

I am a regular user of Betfair and use their polling API with idHTTP components which has worked fin for years and now I'm getting endless SSL errors, so I want to change to the Betfair Stream API using TCP.

I have a valid Login and the correct API Key which is required for Betfair API Access.

Here is my code:

Code:
procedure TfrmStream.Button1Click(Sender: TObject);
var
  SSLHandler: TIdSSLIOHandlerSocketOpenSSL;
  headers, response, connectionmessage: string;
begin
  if not TCPClient.Connected then
    begin
      try
        Memo1.Lines.Clear;
        SSLHandler := TIdSSLIOHandlerSocketOpenSSL.Create(TCPClient);
        SSLHandler.SSLOptions.Mode := sslmClient;
        SSLHandler.SSLOptions.VerifyMode := [];
        SSLHandler.SSLOptions.VerifyDepth := 0 ;
        SSLHandler.SSLOptions.SSLVersions :=  [sslvTLSv1, sslvTLSv1_1, sslvTLSv1_2];
        TCPClient.IOHandler := SSLHandler;
        TCPClient.Host := 'stream-api-integration.betfair.com';
        TCPClient.Port := 443;
        TCPClient.ConnectTimeout := 5000;
        TCPClient.Connect;
        response := TCPClient.IOHandler.ReadLn;
        Memo1.Lines.Add(response);
      except
        on E: Exception do
          Memo1.Lines.Add(' ====== ERROR ======' + sLineBreak +
            ' > ' + E.Message + sLineBreak);
      end;
    end
  else
    begin
      TCPClient.Disconnect;
    end;
end;

I get no response at all where I should be getting

Code:
{"op":"connection","connectionId":"105-260623224442-1720442"}

If I place the same url in a browser I do get the response, so why doesn't my code get a response?

I've been battling this for over week so any help would be appreciated.
Reply
#2
(06-27-2023, 01:08 AM)cnielsen4211 Wrote: I am a regular user of Betfair and use their polling API with idHTTP components which has worked fin for years and now I'm getting endless SSL errors

I just replied to your other post about that.

(06-27-2023, 01:08 AM)cnielsen4211 Wrote: I get no response at all

That is because you are not initiating an SSL/TLS handshake after connecting to the server's SSL/TLS port. You need to set the SSLHandler.PassThrough property to False to invoke the handshake. You can do that either before calling Connect(), or after Connect() returns and before you call ReadLn().

(06-27-2023, 01:08 AM)cnielsen4211 Wrote: If I place the same url in a browser I do get the response, so why doesn't my code get a response?

Because the server is waiting for you to send it a TLS handshake to secure the connection before it will then send its greeting back to you.

Reply
#3
Oh,

You see Betfair have two api's the HTTP Poling API which I have been using and to which you have already replied, there is also a TCP Streaming API which if I was looking to try and use if I couldn't find a solution to the first process.

Thank you for your help
Reply
#4
(06-28-2023, 01:57 AM)cnielsen4211 Wrote: You see Betfair have two api's the HTTP Poling API which I have been using and to which you have already replied

That API uses HTTPS, which is HTTP over SSL/TLS. The SSLIOHandler.PassThrough controls the SSL/TLS handshake, and the TIdHTTP component sets the SSLIOHandler.PassThrough property for you on a per-connection basic as needed for each HTTP request.

(06-28-2023, 01:57 AM)cnielsen4211 Wrote: there is also a TCP Streaming API which if I was looking to try and use

That API uses plain TCP over SSL/TLS. The TIdTCPClient component DOES NOT set the SSLIOHandler.PassThrough property for you, so you have to set it yourself when needed.

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)