diff --git a/include/api/Api.hpp b/include/api/Api.hpp index feb7662..3fc0c73 100644 --- a/include/api/Api.hpp +++ b/include/api/Api.hpp @@ -50,7 +50,7 @@ namespace kdeck std::shared_ptr CancelOrder(std::string_view orderId); std::shared_ptr AmendOrder(std::string_view orderId); std::shared_ptr DecreaseOrder(std::string_view orderId); - std::shared_ptr GetPositions(); + std::shared_ptr GetPositions(); std::shared_ptr GetPortfolioSettlements(); // helpers @@ -77,8 +77,8 @@ namespace kdeck std::shared_ptr markets; // portfolio - std::shared_ptr balance; - std::shared_ptr positions; + std::shared_ptr balance; + std::shared_ptr positions; std::map> eventsMap; std::map>> marketsMap; diff --git a/include/api/_Api.hpp b/include/api/_Api.hpp index 40cee17..e19f2d5 100644 --- a/include/api/_Api.hpp +++ b/include/api/_Api.hpp @@ -26,7 +26,7 @@ namespace kdeck headers.put("Content-Type", "application/json"); headers.put("Accept", "application/json"); } - API_CALL("POST", "{basePath}/login", Login, PATH(String, basePath), BODY_DTO(Object, loginRequest)) + API_CALL("POST", "{basePath}/login", Login, PATH(String, basePath), BODY_DTO(Object, req)) API_CALL_HEADERS(Logout) { @@ -64,28 +64,28 @@ namespace kdeck headers.put("Content-Type", "application/json"); headers.put("Accept", "application/json"); } - API_CALL("GET", "{basePath}/events", GetEvents, PATH(String, basePath), BODY_DTO(Object, eventsRequest)) + API_CALL("GET", "{basePath}/events", GetEvents, PATH(String, basePath), BODY_DTO(Object, req)) API_CALL_HEADERS(GetEvent) { headers.put("Content-Type", "application/json"); headers.put("Accept", "application/json"); } - API_CALL("GET", "{basePath}/events/{event_ticker}", GetEvent, PATH(String, basePath), PATH(String, event_ticker), BODY_DTO(Object, eventRequest)) + API_CALL("GET", "{basePath}/events/{event_ticker}", GetEvent, PATH(String, basePath), PATH(String, event_ticker), BODY_DTO(Object, req)) API_CALL_HEADERS(GetMarkets) { headers.put("Content-Type", "application/json"); headers.put("Accept", "application/json"); } - API_CALL("GET", "{basePath}/markets", GetMarkets, PATH(String, basePath), AUTHORIZATION(String, authString, "Bearer"), BODY_DTO(Object, marketsRequest)) + API_CALL("GET", "{basePath}/markets", GetMarkets, PATH(String, basePath), AUTHORIZATION(String, authString, "Bearer"), BODY_DTO(Object, req)) API_CALL_HEADERS(GetTrades) { headers.put("Content-Type", "application/json"); headers.put("Accept", "application/json"); } - API_CALL("GET", "{basePath}/markets/trades", GetTrades, PATH(String, basePath), BODY_DTO(Object, tradesRequest)) + API_CALL("GET", "{basePath}/markets/trades", GetTrades, PATH(String, basePath), BODY_DTO(Object, req)) API_CALL_HEADERS(GetMarket) { @@ -98,7 +98,7 @@ namespace kdeck headers.put("Content-Type", "application/json"); headers.put("Accept", "application/json"); } - API_CALL("GET", "{basePath}/markets/{ticker}/orderbook", GetMarketOrderbook, PATH(String, basePath), AUTHORIZATION(String, authString, "Bearer"), QUERY(String, ticker), BODY_DTO(Object, marketOrderbookRequest)) + API_CALL("GET", "{basePath}/markets/{ticker}/orderbook", GetMarketOrderbook, PATH(String, basePath), AUTHORIZATION(String, authString, "Bearer"), QUERY(String, ticker), BODY_DTO(Object, req)) API_CALL_HEADERS(GetSeries) { @@ -111,7 +111,7 @@ namespace kdeck headers.put("Content-Type", "application/json"); headers.put("Accept", "application/json"); } - API_CALL("GET", "{basePath}/series/{series_ticker}/markets/{ticker}/candlesticks", GetMarketCandlesticks, PATH(String, basePath), AUTHORIZATION(String, authString, "Bearer"), PATH(String, series_ticker), PATH(String, ticker), BODY_DTO(Object, marketCandlesticksRequest)) + API_CALL("GET", "{basePath}/series/{series_ticker}/markets/{ticker}/candlesticks", GetMarketCandlesticks, PATH(String, basePath), AUTHORIZATION(String, authString, "Bearer"), PATH(String, series_ticker), PATH(String, ticker), BODY_DTO(Object, req)) // portfolio //////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////// @@ -176,7 +176,7 @@ namespace kdeck headers.put("Content-Type", "application/json"); headers.put("Accept", "application/json"); } - API_CALL("GET", "{basePath}/portfolio/positions", GetPositions, PATH(String, basePath), AUTHORIZATION(String, authString, "Bearer"), BODY_DTO(Object, portfolioPositionsRequest)) + API_CALL("GET", "{basePath}/portfolio/positions", GetPositions, PATH(String, basePath), AUTHORIZATION(String, authString, "Bearer"), BODY_DTO(Object, req)) API_CALL_HEADERS(GetPortfolioSettlements) { diff --git a/include/api/types.hpp b/include/api/types.hpp index fcc688c..a19a1ec 100644 --- a/include/api/types.hpp +++ b/include/api/types.hpp @@ -515,10 +515,11 @@ namespace kdeck // portfolio //////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////// - class PortfolioBalanceResponse + class BalanceResponse : public oatpp::DTO { - DTO_INIT(PortfolioBalanceResponse, DTO /* extends */) + + DTO_INIT(BalanceResponse, DTO /* extends */) DTO_FIELD(Int64, balance); //TODO how to make optional? @@ -714,16 +715,16 @@ namespace kdeck }; - struct PortfolioPositionsRequest + struct PositionsRequest : public oatpp::DTO { - DTO_INIT(PortfolioPositionsRequest, DTO /* extends */) + DTO_INIT(PositionsRequest, DTO /* extends */) DTO_FIELD(String, cursor); - DTO_FIELD(Int32, limit) = 100; - DTO_FIELD(String, count_filter) = "position,total_traded,resting_order_count"; - DTO_FIELD(String, settlement_status) = "unsettled"; + DTO_FIELD(Int32, limit); + DTO_FIELD(String, count_filter); + DTO_FIELD(String, settlement_status); DTO_FIELD(String, ticker); DTO_FIELD(String, event_ticker); @@ -760,11 +761,11 @@ namespace kdeck }; - struct PortfolioPositionsResponse + struct PositionsResponse : public oatpp::DTO { - DTO_INIT(PortfolioPositionsResponse, DTO /* extends */) + DTO_INIT(PositionsResponse, DTO /* extends */) DTO_FIELD(String, cursor); DTO_FIELD(List>, event_positions); diff --git a/src/api/Api.auth.cpp b/src/api/Api.auth.cpp index 345d31a..308a718 100644 --- a/src/api/Api.auth.cpp +++ b/src/api/Api.auth.cpp @@ -3,13 +3,10 @@ #include #include "api/Api.hpp" +#include "api/types.hpp" namespace kdeck { - class VoidResponse; - class ErrorResponse; - - class LoginResponse; void Api::Login(std::string_view email, std::string_view password) { diff --git a/src/api/Api.exchange.cpp b/src/api/Api.exchange.cpp index 89f4646..87ccb66 100644 --- a/src/api/Api.exchange.cpp +++ b/src/api/Api.exchange.cpp @@ -1,14 +1,10 @@ #include #include "api/Api.hpp" +#include "api/types.hpp" namespace kdeck { - class ErrorResponse; - - class ExchangeAnnouncementsResponse; - class ExchangeScheduleResponse; - class ExchangeStatusResponse; std::shared_ptr Api::GetExchangeAnnouncements() { diff --git a/src/api/Api.market.cpp b/src/api/Api.market.cpp index e6220e1..653cfa4 100644 --- a/src/api/Api.market.cpp +++ b/src/api/Api.market.cpp @@ -1,18 +1,10 @@ #include #include "api/Api.hpp" +#include "api/types.hpp" namespace kdeck { - class ErrorResponse; - - class EventsResponse; - class EventResponse; - class MarketsResponse; - class TradesResponse; - class MarketOrderbookResponse; - class SeriesResponse; - class MarketCandlesticksResponse; std::shared_ptr Api::GetEvents() { diff --git a/src/api/Api.portfolio.cpp b/src/api/Api.portfolio.cpp index 0cf7927..fd41b21 100644 --- a/src/api/Api.portfolio.cpp +++ b/src/api/Api.portfolio.cpp @@ -3,23 +3,20 @@ #include #include "api/Api.hpp" +#include "api/types.hpp" namespace kdeck { - class ErrorResponse; - - class PortfolioBalanceResponse; - class PortfolioPositionsResponse; double Api::GetBalance() { OATPP_LOGD("Api", "GetBalance"); - ApiResult res = HandleResponse(_api->GetBalance(basePath, login->token)); + ApiResult res = HandleResponse(_api->GetBalance(basePath, login->token)); - if (std::holds_alternative>(res)) + if (std::holds_alternative>(res)) { - balance = std::get>(res); + balance = std::get>(res); } else { @@ -151,17 +148,17 @@ namespace kdeck //TODO return order; } - std::shared_ptr Api::GetPositions() + std::shared_ptr Api::GetPositions() { OATPP_LOGD("Api", "GetPositions"); - auto req = PortfolioPositionsRequest::createShared(); + auto req = PositionsRequest::createShared(); - ApiResult res = HandleResponse(_api->GetPositions(basePath, login->token, req)); + ApiResult res = HandleResponse(_api->GetPositions(basePath, login->token, req)); - if (std::holds_alternative>(res)) + if (std::holds_alternative>(res)) { - positions = std::get>(res); + positions = std::get>(res); eventsMap.clear(); marketsMap.clear();