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
555 stars 192 forks source link

Question #452

Closed AydinyanNarek closed 8 months ago

AydinyanNarek commented 8 months ago

First of all thanks for this powerful API. I am getting familiar with this API and there are some questions. I have created this kind of request Request request(Request::Operation::GET_ACCOUNT_BALANCES, "binance"); The output looks like this

  Event [
    type = RESPONSE,
    messageList = [
      Message [
        type = GET_ACCOUNT_BALANCES,
        recapType = UNKNOWN,
        time = 1970-01-01T00:00:00.000000000Z,
        timeReceived = 2023-11-08T13:52:30.291849435Z,
        elementList = [
          Element [
            nameValueMap = {
              ASSET = BTC,
              QUANTITY_AVAILABLE_FOR_TRADING = 0.00000000,
              QUANTITY_TOTAL = 0
            }
          ],
          Element [
            nameValueMap = {
              ASSET = LTC,
              QUANTITY_AVAILABLE_FOR_TRADING = 0.00000000,
              QUANTITY_TOTAL = 0
            }
          ],
          Element [
            nameValueMap = {
              ASSET = ETH,
              QUANTITY_AVAILABLE_FOR_TRADING = 0.00000000,
              QUANTITY_TOTAL = 0
            }
          ],
          Element [
            nameValueMap = {
              ASSET = NEO,
              QUANTITY_AVAILABLE_FOR_TRADING = 0.00000000,
              QUANTITY_TOTAL = 0
            }
          ],
          Element [
            nameValueMap = {
              ASSET = BNB,
              QUANTITY_AVAILABLE_FOR_TRADING = 0.00002760,
              QUANTITY_TOTAL = 0.0000276
            }
          ],
          Element [
            nameValueMap = {
              ASSET = QTUM,
              QUANTITY_AVAILABLE_FOR_TRADING = 0.00000000,
              QUANTITY_TOTAL = 0
            }
          ],
          Element [
            nameValueMap = {
              ASSET = EOS,
              QUANTITY_AVAILABLE_FOR_TRADING = 0.00000000,
              QUANTITY_TOTAL = 0
            }
          ],
          Element [
            nameValueMap = {
              ASSET = SNT,
              QUANTITY_AVAILABLE_FOR_TRADING = 0.00000000,
              QUANTITY_TOTAL = 0
            }
          ],
          Element [
            nameValueMap = {
              ASSET = BNT,
              QUANTITY_AVAILABLE_FOR_TRADING = 0.00000000,
              QUANTITY_TOTAL = 0
            }
          ],
          Element [
            nameValueMap = {
              ASSET = GAS,
              QUANTITY_AVAILABLE_FOR_TRADING = 0.00000000,
              QUANTITY_TOTAL = 0
            }
          ],
...
        ],
        correlationIdList = [ W0ldOPBY ],
        secondaryCorrelationIdMap = {}
      ]
    ]
  ]

I have bought coins SOL, AVAX , USDT etc... but those coins haven't been listed in the output above.

The questions are

  1. How can I get a balance for specific coins ?
  2. Should I use GENERIC_PUBLIC_REQUEST instead of predefined ones?

Thanks in advance.

PS. Would be great if you will create one more channel in Issues section for questions and/or discussions.

cryptochassis commented 8 months ago

Notice the three dots in the print, there are more that were not printed. You can do event.getMessageList()[0].getElementList() , loop through that and do element.toString() to see all of them.

AydinyanNarek commented 8 months ago

Thanks, it works. One more question Why are we getting the first Message only and getting ElementList from it? Shouldn't we iterate on MessageList, call getElementList() for each message, and iterate on elements?

  class MyEventHandler : public EventHandler
  {
  public:
    bool processEvent(const Event &event, Session *session) override
    {
      response = true;
      auto messageList = event.getMessageList();
      for(const auto& message : messageList) {
        auto elemList = message.getElementList();
        for(const auto& elem : elemList) {
          std::cout << "Received an event:\n" + elem.toStringPretty(2, 2) << std::endl;
        }
      }
      return true;
    }
  };
cryptochassis commented 8 months ago

Thanks, it works. One more question Why are we getting the first Message only and getting ElementList from it? Shouldn't we iterate on MessageList, call getElementList() for each message, and iterate on elements?

  class MyEventHandler : public EventHandler
  {
  public:
    bool processEvent(const Event &event, Session *session) override
    {
      response = true;
      auto messageList = event.getMessageList();
      for(const auto& message : messageList) {
        auto elemList = message.getElementList();
        for(const auto& elem : elemList) {
          std::cout << "Received an event:\n" + elem.toStringPretty(2, 2) << std::endl;
        }
      }
      return true;
    }
  };

Yes, you are right.

AydinyanNarek commented 8 months ago

Thanks for your help. Closing the issue