JKorf / OKX.Net

A C# .netstandard client library for the OKX REST and Websocket Spot and Futures API focusing on clear usage and models
https://jkorf.github.io/OKX.Net/
MIT License
26 stars 14 forks source link

_socketClient.UnifiedApi.Trading.SubscribeToOrderUpdatesAsync cause high cpu, with no trading and data subscription. #38

Open anthonyyfu opened 2 months ago

anthonyyfu commented 2 months ago

I called this method (SubscribeToOrderUpdatesAsync()), and there's no trading, and of course no orderupdate callback received. wail for 20 minutes, the cpu usage will by very high. I'm using .net framework 4.7. and have tried on 3 different pc/server. all the same result. high cpu. In this code, I firstly selected 20 symbols, and they called SubscribeToOrderUpdatesAsync() for each of them.

                var instrumentSecetedList = instrumentList.Where(record =>
                {
                    return record.Symbol.StartsWith("BTC-")
                           || record.Symbol.StartsWith("ETH-")
                           || record.Symbol.StartsWith("SOL-")
                           || record.Symbol.StartsWith("BCH-")
                           || record.Symbol.StartsWith("EOS-")
                           || record.Symbol.StartsWith("LTC-")
                           || record.Symbol.StartsWith("TRX-")
                           || record.Symbol.StartsWith("UNI-")
                           || record.Symbol.StartsWith("XLM-")
                           ;
                });

                Console.WriteLine(string.Join("\t", instrumentList.Select(a => a.Symbol)));

                foreach (var instrument in instrumentSecetedList)
                {

                    var result = _socketClient.UnifiedApi.Trading.SubscribeToOrderUpdatesAsync(OKXInstrumentType.Swap, instrument.Symbol, null, dataEvent => ExchangeTradingOrderUpdate(dataEvent.Data),
                        _clientCts.Token).Result;
                    Console.WriteLine($"{instrument} TradingApicSubscribed");

                    if (!result.Success)
                    {
                        Logger.Warn("futuresCoinUserDataUpdateResp failed! Message:(" + result.Error?.Message + ")");
                        throw new TxException("Client has not been initialized");
                    }
                }
anthonyyfu commented 2 months ago

I'm using 32bit (x86), because I have to use a old component which have to be called in 32bit. hope it's not the reason of high cpu. 4 core/8 hyperthread, and use up to 30% of cpu whitout doing anything. Thank you for help!