IQFeed.CSharpApiClient icon indicating copy to clipboard operation
IQFeed.CSharpApiClient copied to clipboard

IClient connection status.

Open Nucs opened this issue 7 years ago • 18 comments

There is no way to know if a client is connected, disconnected or suddenly lost connection. There is a heavy need for:

  • Event for connection state change.
  • Property for current connection state.

Current workaround for knowing if client is connected and is working.

a.1. accessing private field _socketClient of type SocketClient and then _clientSocket of type Socket via reflection to send a poll request.

b.1. Disabling timestamps feed (enabled by default) Level1Client.ReqTimestamps(false); b.2. Sending a timestamp request with 200ms timeout via Level1Client.ReqTimestamp(); b.3. If no response came in or exception was thrown - not connected.

When method 'a' and 'b' are true, socket is connected.

Nucs avatar Sep 11 '18 19:09 Nucs

Did you try using the AdminClient statuses? I think by properly naming your Level1Client you should be able to know if your client still connected using the Admin features. Not sure about it but I`ll check tomorrow.

mathpaquette avatar Sep 11 '18 22:09 mathpaquette

@Nucs did you check with AdminClient?

mathpaquette avatar Sep 13 '18 18:09 mathpaquette

I'm talking about knowing in a business layer if Level1Client has disconnected, lost connection or just idle because the specific stock is silent.

You'll need to be more specific because there is no documentation at all in any parts of the code. ClientsConnected from StatsMessage in AdminClient provides general count of connections. ClientStatsMessage still doesn't refer to Level1Client current state.

Edit: Looking again at AdminClient, there is not documentation available (in the library) regarding how it works or even towards how to interact with it. If you think it might help with knowing the connection state, examples are needed.

Nucs avatar Sep 14 '18 04:09 Nucs

I didnt forget you... Still working to find the time to add this. Before the end of the week for sure!

mathpaquette avatar Sep 19 '18 23:09 mathpaquette

Nucs, Level1 you will receive Timestamp every seconds, if not, something goes wrong.

mathpaquette avatar Sep 20 '18 11:09 mathpaquette

Wanted to circle back to this...what about checking the status of the DerivativeClient? It is also streaming data and needs to handle connection state changes.

hunterfries avatar Oct 23 '18 16:10 hunterfries

Bump here...what do we think about this?

hunterfries avatar Nov 07 '18 22:11 hunterfries

@hunterfries totally agree with you guys that would be nice to have such abiliality in every connected clients. I'll do it once I have spare time, right now focusing on my new contract...

mathpaquette avatar Nov 07 '18 22:11 mathpaquette

No problem. In the meantime, would subscribing to the Level1Client's timestamp callback and then handling a disconnection be the current workaround? Something like:

IQFeedLauncher.Terminate(); IQFeedLauncher.Start(); // start your clients

@Nucs is this how you're handling this?

hunterfries avatar Nov 09 '18 20:11 hunterfries

The same way I wrote on the first post on a separate thread.

Nucs avatar Nov 13 '18 13:11 Nucs

But guys, do you agree that if there's no reconnect mechanism checking the status is a but useless or this is me that not getting the use case?

Suppose I add Connected prop in IClient, you think that's enough?

mathpaquette avatar Nov 15 '18 22:11 mathpaquette

That or an implementation of the workaround above that fired a Disconnected event that we could hook onto. I would just want some input on the implementation.

hunterfries avatar Nov 16 '18 02:11 hunterfries

@hunterfries, yes, I think I prefer the Disconnected event. Ill do that. thanks

mathpaquette avatar Nov 17 '18 21:11 mathpaquette

Hi All,

What is the Product_id in app.config file or user environment variable .From where i can get the product_id key value

10thBeast avatar Nov 22 '18 12:11 10thBeast

@10thBeast long story short, you need to buy a dev license from IQFeed

mathpaquette avatar Nov 23 '18 02:11 mathpaquette

IQFeed themselves use a product key in their test tools.. A little reverse engineering got me it. <add key="IQConnect:product_id" value="IQFEED_DIAGNOSTICS"/> Use it at your own risk, I'm not responsible for anything. you'll have to eventually purchase the dev pack for your own product.

Nucs avatar Nov 23 '18 06:11 Nucs

Guys, there's no easy way to know if a socket is still connected or not. Even the Connected property from Socket class can lie about his current status in the case the connection dropped unexpectedly. We need to have a HeartBeat mechanism but not supported by IQFeed...

Ill check what I can do with the Admin port to monitor the status with IQFeed Servers but there's no easy way to do it.

mathpaquette avatar Dec 16 '18 14:12 mathpaquette

You can always create a separate Level1Client that will use timestamps as heartbeat while a different client is used for data. Would be nice to have such a class provided with the library itself.

Nucs avatar Dec 17 '18 04:12 Nucs