crypto-chassis / ccapi

A header-only C++ library for interacting with crypto exchanges. Bindings for Python, Java, C#, Go, and Javascript are provided.
https://discord.gg/b5EKcp9s8T
MIT License
568 stars 195 forks source link

A way to get a complete list of symbols on any exchange #421

Closed omidnabi closed 11 months ago

omidnabi commented 1 year ago

This might not fall under a feature request and there might already be a simple solution, but after playing around with your API for a little bit, I noticed there are way too many configuration items and some I'm not sure how to obtain. The main one being a complete list of all the symbols available on an exchange. How do I obtain this information? I'd like to subscribe to all the coins periodically.

cryptochassis commented 1 year ago

Try Request request(Request::Operation::GET_INSTRUMENTS, "coinbase", "");

omidnabi commented 1 year ago

Try Request request(Request::Operation::GET_INSTRUMENTS, "coinbase", "");

I'm new to this library and I couldn't find anything in the examples that uses Request::Operation::GET_INSTRUMETNS, is the request supposed to return a list of symbols? if so how do I get that list? I saw the toString() function which returns this:

Request [exchange = binance-us, marginType = , instrument = , serviceName = market_data, correlationId = 6D6a2kBR, secondaryCorrelationId = , paramList = [ ], credential = {}, operation = GET_INSTRUMENTS, timeSent = 1970-01-01T00:00:00.000000000Z]

omidnabi commented 1 year ago

Actually let me reword my question, what's the best way to subscribe to all the coins to receive price updates? Currently the way I implemented it is to have a session for each coin which I'm guessing is wrong because even though it works for a few seconds but then somewhere in the thread it crashes. The examples are nice but I wish there was a better documentation so I could understand the proper usage better.

nelyajizi commented 1 year ago

when you send the request, the handler given in your session will receive the event corresponding to your request, the examples in the repo shows how to implement a custom handler and process received events. As of my knowledge, there is no predefined request returning the list of symbols available within each exchange, but you could performed it by yourself using ccapi::Request::Operation::GENERIC_PUBLIC_REQUEST and then forming the request url following the desired exchange, and then handle the response with your handler:

ccapi::Request request(ccapi::Request::Operation::GENERIC_PUBLIC_REQUEST,CCAPI_EXCHANGE_NAME_KUCOIN, "", correlation_id); request.appendParam({ {"HTTP_METHOD", SB_GET}, {"HTTP_PATH", SB_MKT_INFO_KUCOIN}, {"HTTP_QUERY_STRING","symbol=" + symbol}, });

cryptochassis commented 12 months ago

Actually let me reword my question, what's the best way to subscribe to all the coins to receive price updates? Currently the way I implemented it is to have a session for each coin which I'm guessing is wrong because even though it works for a few seconds but then somewhere in the thread it crashes. The examples are nice but I wish there was a better documentation so I could understand the proper usage better.

You can use just one session for all coins like this: https://github.com/crypto-chassis/ccapi#multiple-exchanges-andor-instruments.