Skip to content

Commit

Permalink
Add portfolio API code generators, wrapper methods, and request/respo…
Browse files Browse the repository at this point in the history
…nse types. (#64)
  • Loading branch information
krazkidd authored Jul 21, 2024
1 parent 4fcd014 commit 725fb45
Show file tree
Hide file tree
Showing 4 changed files with 434 additions and 0 deletions.
8 changes: 8 additions & 0 deletions include/api/Api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,15 @@ namespace kdeck

// portfolio
double GetBalance();
std::shared_ptr<FillsResponse> GetFills();
std::shared_ptr<OrdersResponse> GetOrders();
std::shared_ptr<OrderResponse> CreateOrder();
std::shared_ptr<OrderResponse> GetOrder(std::string_view orderId);
std::shared_ptr<CancelOrderResponse> CancelOrder(std::string_view orderId);
std::shared_ptr<AmendOrderResponse> AmendOrder(std::string_view orderId);
std::shared_ptr<OrderResponse> DecreaseOrder(std::string_view orderId);
std::shared_ptr<PortfolioPositionsResponse> GetPositions();
std::shared_ptr<PortfolioSettlementsResponse> GetPortfolioSettlements();

// helpers
bool IsLoggedIn();
Expand Down
56 changes: 56 additions & 0 deletions include/api/_Api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,69 @@ namespace kdeck
}
API_CALL("GET", "{basePath}/portfolio/balance", GetBalance, PATH(String, basePath), AUTHORIZATION(String, authString, "Bearer"))

API_CALL_HEADERS(GetFills)
{
headers.put("Content-Type", "application/json");
headers.put("Accept", "application/json");
}
API_CALL("GET", "{basePath}/portfolio/fills", GetFills, PATH(String, basePath), AUTHORIZATION(String, authString, "Bearer"), BODY_DTO(Object<FillsRequest>, req))

API_CALL_HEADERS(GetOrders)
{
headers.put("Content-Type", "application/json");
headers.put("Accept", "application/json");
}
API_CALL("GET", "{basePath}/portfolio/orders", GetOrders, PATH(String, basePath), AUTHORIZATION(String, authString, "Bearer"), BODY_DTO(Object<OrdersRequest>, req))

API_CALL_HEADERS(CreateOrder)
{
headers.put("Content-Type", "application/json");
headers.put("Accept", "application/json");
}
API_CALL("POST", "{basePath}/portfolio/orders", CreateOrder, PATH(String, basePath), AUTHORIZATION(String, authString, "Bearer"), BODY_DTO(Object<CreateOrderRequest>, req))

API_CALL_HEADERS(GetOrder)
{
headers.put("Content-Type", "application/json");
headers.put("Accept", "application/json");
}
API_CALL("GET", "{basePath}/portfolio/orders/{order_id}", GetOrder, PATH(String, basePath), AUTHORIZATION(String, authString, "Bearer"), PATH(String, order_id))

API_CALL_HEADERS(CancelOrder)
{
headers.put("Content-Type", "application/json");
headers.put("Accept", "application/json");
}
API_CALL("DELETE", "{basePath}/portfolio/orders/{order_id}", CancelOrder, PATH(String, basePath), AUTHORIZATION(String, authString, "Bearer"), PATH(String, order_id))

API_CALL_HEADERS(AmendOrder)
{
headers.put("Content-Type", "application/json");
headers.put("Accept", "application/json");
}
API_CALL("POST", "{basePath}/portfolio/orders/{order_id}/amend", AmendOrder, PATH(String, basePath), AUTHORIZATION(String, authString, "Bearer"), PATH(String, order_id), BODY_DTO(Object<AmendOrderRequest>, req))

API_CALL_HEADERS(DecreaseOrder)
{
headers.put("Content-Type", "application/json");
headers.put("Accept", "application/json");
}
API_CALL("POST", "{basePath}/portfolio/orders/{order_id}/decrease", DecreaseOrder, PATH(String, basePath), AUTHORIZATION(String, authString, "Bearer"), PATH(String, order_id), BODY_DTO(Object<DecreaseOrderRequest>, req))

API_CALL_HEADERS(GetPositions)
{
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>, portfolioPositionsRequest))

API_CALL_HEADERS(GetPortfolioSettlements)
{
headers.put("Content-Type", "application/json");
headers.put("Accept", "application/json");
}
API_CALL("GET", "{basePath}/portfolio/settlements", GetPortfolioSettlements, PATH(String, basePath), AUTHORIZATION(String, authString, "Bearer"), BODY_DTO(Object<PortfolioSettlementsRequest>, req))

};

#include OATPP_CODEGEN_END(ApiClient)
Expand Down
227 changes: 227 additions & 0 deletions include/api/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,194 @@ namespace kdeck

};

class FillsRequest
: public oatpp::DTO
{

DTO_INIT(FillsRequest, DTO /* extends */)

DTO_FIELD(String, ticker);
DTO_FIELD(String, order_id);
DTO_FIELD(Int64, min_ts);
DTO_FIELD(Int64, max_ts);
DTO_FIELD(Int32, limit);
DTO_FIELD(String, cursor);

};

class Fill
: public oatpp::DTO
{

DTO_INIT(Fill, DTO /* extends */)

DTO_FIELD(String, action);
DTO_FIELD(Int32, count);
DTO_FIELD(DateTime_Iso8601, created_time);
DTO_FIELD(Boolean, is_taker);
DTO_FIELD(Int64, no_price);
DTO_FIELD(String, order_id);
DTO_FIELD(String, side);
DTO_FIELD(String, ticker);
DTO_FIELD(Int64, yes_price);

};

class FillsResponse
: public oatpp::DTO
{

DTO_INIT(FillsResponse, DTO /* extends */)

DTO_FIELD(String, cursor);
DTO_FIELD(Object<Fill>, fills);

};

class OrdersRequest
: public oatpp::DTO
{

DTO_INIT(OrdersRequest, DTO /* extends */)

DTO_FIELD(String, ticker);
DTO_FIELD(String, event_ticker);
DTO_FIELD(Int64, min_ts);
DTO_FIELD(Int64, max_ts);
DTO_FIELD(String, status);
DTO_FIELD(String, cursor);
DTO_FIELD(Int32, limit);

};

class Order
: public oatpp::DTO
{

DTO_INIT(Order, DTO /* extends */)

DTO_FIELD(String, action);
DTO_FIELD(Int32, amend_count);
DTO_FIELD(Int32, amend_taker_fill_count);
DTO_FIELD(String, client_order_id);
DTO_FIELD(Int32, close_cancel_count);
DTO_FIELD(DateTime_Iso8601, created_time);
DTO_FIELD(Int32, decrease_count);
DTO_FIELD(DateTime_Iso8601, expiration_time);
DTO_FIELD(Int32, fcc_cancel_count);
DTO_FIELD(DateTime_Iso8601, last_update_time);
DTO_FIELD(Int64, maker_fees);
DTO_FIELD(Int64, maker_fill_cost);
DTO_FIELD(Int32, maker_fill_count);
DTO_FIELD(Int64, no_price);
DTO_FIELD(String, order_id);
DTO_FIELD(Int32, place_count);
DTO_FIELD(Int32, queue_position);
DTO_FIELD(Int32, remaining_count);
DTO_FIELD(String, side);
DTO_FIELD(String, status);
DTO_FIELD(Int64, taker_fees);
DTO_FIELD(Int64, taker_fill_cost);
DTO_FIELD(Int32, taker_fill_count);
DTO_FIELD(Int32, taker_self_trade_cancel_count);
DTO_FIELD(String, ticker);
DTO_FIELD(String, type);
DTO_FIELD(String, user_id);
DTO_FIELD(Int64, yes_price);

};

class OrdersResponse
: public oatpp::DTO
{

DTO_INIT(OrdersResponse, DTO /* extends */)

DTO_FIELD(String, cursor);
DTO_FIELD(List<Object<Order>>, orders);

};

class CreateOrderRequest
: public oatpp::DTO
{

DTO_INIT(CreateOrderRequest, DTO /* extends */)

DTO_FIELD(String, action);
DTO_FIELD(Int64, buy_max_cost);
DTO_FIELD(String, client_order_id);
DTO_FIELD(Int32, count);
DTO_FIELD(Int64, expiration_ts);
DTO_FIELD(Int64, no_price);
DTO_FIELD(Int32, sell_position_floor);
DTO_FIELD(String, side);
DTO_FIELD(String, ticker);
DTO_FIELD(String, type);
DTO_FIELD(Int64, yes_price);

};

class OrderResponse
: public oatpp::DTO
{

DTO_INIT(OrderResponse, DTO /* extends */)

DTO_FIELD(Object<Order>, order);

};

class CancelOrderResponse
: public oatpp::DTO
{

DTO_INIT(CancelOrderResponse, DTO /* extends */)

DTO_FIELD(Object<Order>, order);
DTO_FIELD(Int32, reduced_by);

};

class AmendOrderRequest
: public oatpp::DTO
{

DTO_INIT(AmendOrderRequest, DTO /* extends */)

DTO_FIELD(String, action);
DTO_FIELD(String, client_order_id);
DTO_FIELD(Int32, count);
DTO_FIELD(Int64, no_price);
DTO_FIELD(String, side);
DTO_FIELD(String, ticker);
DTO_FIELD(String, updated_client_order_id);
DTO_FIELD(Int64, yes_price);

};

class AmendOrderResponse
: public oatpp::DTO
{

DTO_INIT(AmendOrderResponse, DTO /* extends */)

DTO_FIELD(Object<Order>, old_order);
DTO_FIELD(Object<Order>, order);

};

class DecreaseOrderRequest
: public oatpp::DTO
{

DTO_INIT(DecreaseOrderRequest, DTO /* extends */)

DTO_FIELD(Int32, reduce_by);
DTO_FIELD(Int32, reduce_to);

};

struct PortfolioPositionsRequest
: public oatpp::DTO
{
Expand Down Expand Up @@ -584,6 +772,45 @@ namespace kdeck

};

class PortfolioSettlementsRequest
: public oatpp::DTO
{

DTO_INIT(PortfolioSettlementsRequest, DTO /* extends */)

DTO_FIELD(Int64, limit);
DTO_FIELD(String, cursor);

};

class Settlement
: public oatpp::DTO
{

DTO_INIT(Settlement, DTO /* extends */)

DTO_FIELD(String, market_result);
DTO_FIELD(Int64, no_count);
DTO_FIELD(Int64, no_total_cost);
DTO_FIELD(Int64, revenue);
DTO_FIELD(DateTime_Iso8601, settled_time);
DTO_FIELD(String, ticker);
DTO_FIELD(Int64, yes_count);
DTO_FIELD(Int64, yes_total_cost);

};

class PortfolioSettlementsResponse
: public oatpp::DTO
{

DTO_INIT(PortfolioSettlementsResponse, DTO /* extends */)

DTO_FIELD(String, cursor);
DTO_FIELD(Object<Settlement>, settlements);

};

#include OATPP_CODEGEN_END(DTO)

}
Expand Down
Loading

0 comments on commit 725fb45

Please sign in to comment.