Skip to content

Commit

Permalink
Implement market API wrapper methods.
Browse files Browse the repository at this point in the history
This is a partial implementation.
  • Loading branch information
krazkidd committed Jul 16, 2024
1 parent 88fe97f commit b2563e8
Show file tree
Hide file tree
Showing 2 changed files with 187 additions and 5 deletions.
14 changes: 9 additions & 5 deletions include/api/Api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ namespace kdeck

// market
std::shared_ptr<EventsResponse> GetEvents();

Check warning on line 35 in include/api/Api.hpp

View workflow job for this annotation

GitHub Actions / cpp-linter

include/api/Api.hpp:35:41 [modernize-use-trailing-return-type]

use a trailing return type for this function
std::shared_ptr<EventResponse> GetEvent();
std::shared_ptr<EventResponse> GetEvent(std::string_view eventTicker);

Check warning on line 36 in include/api/Api.hpp

View workflow job for this annotation

GitHub Actions / cpp-linter

include/api/Api.hpp:36:40 [modernize-use-trailing-return-type]

use a trailing return type for this function
std::shared_ptr<MarketsResponse> GetMarkets();

Check warning on line 37 in include/api/Api.hpp

View workflow job for this annotation

GitHub Actions / cpp-linter

include/api/Api.hpp:37:42 [modernize-use-trailing-return-type]

use a trailing return type for this function
std::shared_ptr<TradesResponse> GetTrades();

Check warning on line 38 in include/api/Api.hpp

View workflow job for this annotation

GitHub Actions / cpp-linter

include/api/Api.hpp:38:41 [modernize-use-trailing-return-type]

use a trailing return type for this function
std::shared_ptr<MarketResponse> GetMarket();
std::shared_ptr<MarketOrderbookResponse> GetMarketOrderbook();
std::shared_ptr<SeriesResponse> GetSeries();
std::shared_ptr<MarketCandlesticksResponse> GetMarketCandlesticks();
std::shared_ptr<MarketResponse> GetMarket(std::string_view marketTicker);

Check warning on line 39 in include/api/Api.hpp

View workflow job for this annotation

GitHub Actions / cpp-linter

include/api/Api.hpp:39:41 [modernize-use-trailing-return-type]

use a trailing return type for this function
std::shared_ptr<MarketOrderbookResponse> GetMarketOrderbook(std::string_view marketTicker);

Check warning on line 40 in include/api/Api.hpp

View workflow job for this annotation

GitHub Actions / cpp-linter

include/api/Api.hpp:40:50 [modernize-use-trailing-return-type]

use a trailing return type for this function
std::shared_ptr<SeriesResponse> GetSeries(std::string_view seriesTicker);

Check warning on line 41 in include/api/Api.hpp

View workflow job for this annotation

GitHub Actions / cpp-linter

include/api/Api.hpp:41:41 [modernize-use-trailing-return-type]

use a trailing return type for this function
std::shared_ptr<MarketCandlesticksResponse> GetMarketCandlesticks(std::string_view seriesTicker, std::string_view marketTicker);

// portfolio
double GetBalance();
Expand All @@ -64,6 +64,10 @@ namespace kdeck
std::shared_ptr<ExchangeScheduleResponse> schedule;
std::shared_ptr<ExchangeStatusResponse> status;

// market
std::shared_ptr<EventsResponse> events;
std::shared_ptr<MarketsResponse> markets;

// portfolio
std::shared_ptr<PortfolioBalanceResponse> balance;
std::shared_ptr<PortfolioPositionsResponse> positions;
Expand Down
178 changes: 178 additions & 0 deletions src/api/Api.market.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
#include <stdexcept>

Check notice on line 1 in src/api/Api.market.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

Run clang-format on src/api/Api.market.cpp

File src/api/Api.market.cpp does not conform to LLVM style guidelines. (lines 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 17, 18, 19, 21, 23, 25, 26, 27, 28, 29, 30, 31, 32, 34, 35, 37, 38, 39, 41, 43, 45, 46, 47, 48, 49, 50, 51, 52, 53, 55, 56, 58, 59, 60, 62, 64, 66, 67, 68, 69, 70, 71, 72, 73, 75, 76, 78, 79, 80, 82, 84, 86, 87, 88, 89, 90, 91, 92, 93, 94, 96, 97, 99, 100, 101, 103, 105, 106, 107, 108, 109, 110, 111, 112, 113, 115, 116, 118, 119, 120, 122, 124, 126, 127, 128, 129, 130, 131, 132, 133, 134, 136, 137, 139, 140, 141, 143, 145, 146, 147, 148, 149, 150, 151, 152, 153, 155, 156, 158, 159, 160, 162, 164, 166, 167, 168, 169, 170, 171, 172, 173, 174, 176, 178)

#include "api/Api.hpp"

Check failure on line 3 in src/api/Api.market.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

src/api/Api.market.cpp:3:10 [clang-diagnostic-error]

'api/Api.hpp' file not found

namespace kdeck
{
class ErrorResponse;

class EventsResponse;
class EventResponse;
class MarketsResponse;
class TradesResponse;
class MarketOrderbookResponse;
class SeriesResponse;
class MarketCandlesticksResponse;

std::shared_ptr<EventsResponse> Api::GetEvents()
{
OATPP_LOGD("Api", "GetEvents");

auto req = EventsRequest::createShared();

ApiResult<EventsResponse> res = HandleResponse<EventsResponse>(_api->GetEvents(basePath, req));

if (std::holds_alternative<std::shared_ptr<EventsResponse>>(res))
{
events = std::get<std::shared_ptr<EventsResponse>>(res);
}
else
{
throw std::runtime_error(std::get<std::shared_ptr<ErrorResponse>>(res)->error->message->c_str());
}

return events;
}

std::shared_ptr<EventResponse> Api::GetEvent(std::string_view eventTicker)
{
OATPP_LOGD("Api", "GetEvent");

auto req = EventRequest::createShared();

ApiResult<EventResponse> res = HandleResponse<EventResponse>(_api->GetEvent(basePath, std::string{eventTicker}, req));

if (std::holds_alternative<std::shared_ptr<EventResponse>>(res))
{
//TODO populate events
return std::get<std::shared_ptr<EventResponse>>(res);
}
else
{
throw std::runtime_error(std::get<std::shared_ptr<ErrorResponse>>(res)->error->message->c_str());
}

//TODO return events[eventTicker];
}

std::shared_ptr<MarketsResponse> Api::GetMarkets()
{
OATPP_LOGD("Api", "GetMarkets");

auto req = MarketsRequest::createShared();

ApiResult<MarketsResponse> res = HandleResponse<MarketsResponse>(_api->GetMarkets(basePath, login->token, req));

if (std::holds_alternative<std::shared_ptr<MarketsResponse>>(res))
{
markets = std::get<std::shared_ptr<MarketsResponse>>(res);
}
else
{
throw std::runtime_error(std::get<std::shared_ptr<ErrorResponse>>(res)->error->message->c_str());
}

return markets;
}

std::shared_ptr<TradesResponse> Api::GetTrades()
{
OATPP_LOGD("Api", "GetTrades");

auto req = TradesRequest::createShared();

ApiResult<TradesResponse> res = HandleResponse<TradesResponse>(_api->GetTrades(basePath, req));

if (std::holds_alternative<std::shared_ptr<TradesResponse>>(res))
{
//TODO populate trades
return std::get<std::shared_ptr<TradesResponse>>(res);
}
else
{
throw std::runtime_error(std::get<std::shared_ptr<ErrorResponse>>(res)->error->message->c_str());
}

//TODO return trades;
}

std::shared_ptr<MarketResponse> Api::GetMarket(std::string_view marketTicker)
{
OATPP_LOGD("Api", "GetMarket");

ApiResult<MarketResponse> res = HandleResponse<MarketResponse>(_api->GetMarket(basePath, std::string{marketTicker}));

if (std::holds_alternative<std::shared_ptr<MarketResponse>>(res))
{
//TODO populate markets
return std::get<std::shared_ptr<MarketResponse>>(res);
}
else
{
throw std::runtime_error(std::get<std::shared_ptr<ErrorResponse>>(res)->error->message->c_str());
}

//TODO return markets[marketTicker];
}

std::shared_ptr<MarketOrderbookResponse> Api::GetMarketOrderbook(std::string_view marketTicker)
{
OATPP_LOGD("Api", "GetMarketOrderbook");

auto req = MarketOrderbookRequest::createShared();

ApiResult<MarketOrderbookResponse> res = HandleResponse<MarketOrderbookResponse>(_api->GetMarketOrderbook(basePath, login->token, std::string{marketTicker}, req));

if (std::holds_alternative<std::shared_ptr<MarketOrderbookResponse>>(res))
{
//TODO populate orderbooks
return std::get<std::shared_ptr<MarketOrderbookResponse>>(res);
}
else
{
throw std::runtime_error(std::get<std::shared_ptr<ErrorResponse>>(res)->error->message->c_str());
}

//TODO return orderbooks[marketTicker];
}

std::shared_ptr<SeriesResponse> Api::GetSeries(std::string_view seriesTicker)
{
OATPP_LOGD("Api", "GetSeries");

ApiResult<SeriesResponse> res = HandleResponse<SeriesResponse>(_api->GetSeries(basePath, std::string{seriesTicker}));

if (std::holds_alternative<std::shared_ptr<SeriesResponse>>(res))
{
//TODO populate series
return std::get<std::shared_ptr<SeriesResponse>>(res);
}
else
{
throw std::runtime_error(std::get<std::shared_ptr<ErrorResponse>>(res)->error->message->c_str());
}

//TODO return series[seriesTicker];
}

std::shared_ptr<MarketCandlesticksResponse> Api::GetMarketCandlesticks(std::string_view seriesTicker, std::string_view marketTicker)
{
OATPP_LOGD("Api", "GetMarketCandlesticks");

auto req = MarketCandlesticksRequest::createShared();

ApiResult<MarketCandlesticksResponse> res = HandleResponse<MarketCandlesticksResponse>(_api->GetMarketCandlesticks(basePath, login->token, std::string{seriesTicker}, std::string{marketTicker}, req));

if (std::holds_alternative<std::shared_ptr<MarketCandlesticksResponse>>(res))
{
//TODO populate candlesticks
return std::get<std::shared_ptr<MarketCandlesticksResponse>>(res);
}
else
{
throw std::runtime_error(std::get<std::shared_ptr<ErrorResponse>>(res)->error->message->c_str());
}

//return candlesticks[seriesTicker][marketTicker];
}
}

0 comments on commit b2563e8

Please sign in to comment.