diff --git a/include/api/Api.hpp b/include/api/Api.hpp index 280f14f..3b5b941 100644 --- a/include/api/Api.hpp +++ b/include/api/Api.hpp @@ -33,13 +33,13 @@ namespace kdeck // market std::shared_ptr GetEvents(); - std::shared_ptr GetEvent(); + std::shared_ptr GetEvent(std::string_view eventTicker); std::shared_ptr GetMarkets(); std::shared_ptr GetTrades(); - std::shared_ptr GetMarket(); - std::shared_ptr GetMarketOrderbook(); - std::shared_ptr GetSeries(); - std::shared_ptr GetMarketCandlesticks(); + std::shared_ptr GetMarket(std::string_view marketTicker); + std::shared_ptr GetMarketOrderbook(std::string_view marketTicker); + std::shared_ptr GetSeries(std::string_view seriesTicker); + std::shared_ptr GetMarketCandlesticks(std::string_view seriesTicker, std::string_view marketTicker); // portfolio double GetBalance(); @@ -64,6 +64,10 @@ namespace kdeck std::shared_ptr schedule; std::shared_ptr status; + // market + std::shared_ptr events; + std::shared_ptr markets; + // portfolio std::shared_ptr balance; std::shared_ptr positions; diff --git a/src/api/Api.market.cpp b/src/api/Api.market.cpp new file mode 100644 index 0000000..e6220e1 --- /dev/null +++ b/src/api/Api.market.cpp @@ -0,0 +1,178 @@ +#include + +#include "api/Api.hpp" + +namespace kdeck +{ + class ErrorResponse; + + class EventsResponse; + class EventResponse; + class MarketsResponse; + class TradesResponse; + class MarketOrderbookResponse; + class SeriesResponse; + class MarketCandlesticksResponse; + + std::shared_ptr Api::GetEvents() + { + OATPP_LOGD("Api", "GetEvents"); + + auto req = EventsRequest::createShared(); + + ApiResult res = HandleResponse(_api->GetEvents(basePath, req)); + + if (std::holds_alternative>(res)) + { + events = std::get>(res); + } + else + { + throw std::runtime_error(std::get>(res)->error->message->c_str()); + } + + return events; + } + + std::shared_ptr Api::GetEvent(std::string_view eventTicker) + { + OATPP_LOGD("Api", "GetEvent"); + + auto req = EventRequest::createShared(); + + ApiResult res = HandleResponse(_api->GetEvent(basePath, std::string{eventTicker}, req)); + + if (std::holds_alternative>(res)) + { + //TODO populate events + return std::get>(res); + } + else + { + throw std::runtime_error(std::get>(res)->error->message->c_str()); + } + + //TODO return events[eventTicker]; + } + + std::shared_ptr Api::GetMarkets() + { + OATPP_LOGD("Api", "GetMarkets"); + + auto req = MarketsRequest::createShared(); + + ApiResult res = HandleResponse(_api->GetMarkets(basePath, login->token, req)); + + if (std::holds_alternative>(res)) + { + markets = std::get>(res); + } + else + { + throw std::runtime_error(std::get>(res)->error->message->c_str()); + } + + return markets; + } + + std::shared_ptr Api::GetTrades() + { + OATPP_LOGD("Api", "GetTrades"); + + auto req = TradesRequest::createShared(); + + ApiResult res = HandleResponse(_api->GetTrades(basePath, req)); + + if (std::holds_alternative>(res)) + { + //TODO populate trades + return std::get>(res); + } + else + { + throw std::runtime_error(std::get>(res)->error->message->c_str()); + } + + //TODO return trades; + } + + std::shared_ptr Api::GetMarket(std::string_view marketTicker) + { + OATPP_LOGD("Api", "GetMarket"); + + ApiResult res = HandleResponse(_api->GetMarket(basePath, std::string{marketTicker})); + + if (std::holds_alternative>(res)) + { + //TODO populate markets + return std::get>(res); + } + else + { + throw std::runtime_error(std::get>(res)->error->message->c_str()); + } + + //TODO return markets[marketTicker]; + } + + std::shared_ptr Api::GetMarketOrderbook(std::string_view marketTicker) + { + OATPP_LOGD("Api", "GetMarketOrderbook"); + + auto req = MarketOrderbookRequest::createShared(); + + ApiResult res = HandleResponse(_api->GetMarketOrderbook(basePath, login->token, std::string{marketTicker}, req)); + + if (std::holds_alternative>(res)) + { + //TODO populate orderbooks + return std::get>(res); + } + else + { + throw std::runtime_error(std::get>(res)->error->message->c_str()); + } + + //TODO return orderbooks[marketTicker]; + } + + std::shared_ptr Api::GetSeries(std::string_view seriesTicker) + { + OATPP_LOGD("Api", "GetSeries"); + + ApiResult res = HandleResponse(_api->GetSeries(basePath, std::string{seriesTicker})); + + if (std::holds_alternative>(res)) + { + //TODO populate series + return std::get>(res); + } + else + { + throw std::runtime_error(std::get>(res)->error->message->c_str()); + } + + //TODO return series[seriesTicker]; + } + + std::shared_ptr Api::GetMarketCandlesticks(std::string_view seriesTicker, std::string_view marketTicker) + { + OATPP_LOGD("Api", "GetMarketCandlesticks"); + + auto req = MarketCandlesticksRequest::createShared(); + + ApiResult res = HandleResponse(_api->GetMarketCandlesticks(basePath, login->token, std::string{seriesTicker}, std::string{marketTicker}, req)); + + if (std::holds_alternative>(res)) + { + //TODO populate candlesticks + return std::get>(res); + } + else + { + throw std::runtime_error(std::get>(res)->error->message->c_str()); + } + + //return candlesticks[seriesTicker][marketTicker]; + } +}