Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: iceberg & ttl orders support #60

Merged
merged 6 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/kitepp/kite/order.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ inline string kite::placeOrder(const placeOrderParams& params) {
utils::addParam(bodyParams, params.squareOff, "squareoff");
utils::addParam(bodyParams, params.stopLoss, "stoploss");
utils::addParam(bodyParams, params.trailingStopLoss, "trailing_stoploss");
utils::addParam(bodyParams, params.icebergLegs, "iceberg_legs");
utils::addParam(bodyParams, params.icebergQuantity, "iceberg_quantity");
utils::addParam(bodyParams, params.validityTtl, "validity_ttl");
utils::addParam(bodyParams, params.tag, "tag");

return callApi<string, utils::json::JsonObject, true>("order.place",
Expand Down
11 changes: 10 additions & 1 deletion include/kitepp/responses/order.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ struct placeOrderParams {
GENERATE_FLUENT_METHOD(placeOrderParams, int, quantity, Quantity);
GENERATE_FLUENT_METHOD(
placeOrderParams, int, disclosedQuantity, DisclosedQuantity);
GENERATE_FLUENT_METHOD(placeOrderParams, int, validityTtl, ValidityTtl);
GENERATE_FLUENT_METHOD(placeOrderParams, int, icebergLegs, IcebergLegs);
GENERATE_FLUENT_METHOD(
placeOrderParams, int, icebergQuantity, IcebergQuantity);
GENERATE_FLUENT_METHOD(placeOrderParams, double, price, Price);
GENERATE_FLUENT_METHOD(
placeOrderParams, double, triggerPrice, TriggerPrice);
Expand All @@ -64,7 +68,10 @@ struct placeOrderParams {

int quantity;
std::optional<int> disclosedQuantity;
std::optional<int> price;
std::optional<int> validityTtl;
std::optional<int> icebergLegs;
std::optional<int> icebergQuantity;
std::optional<double> price;
std::optional<double> triggerPrice;
std::optional<double> squareOff;
std::optional<double> stopLoss;
Expand Down Expand Up @@ -135,6 +142,7 @@ struct order {
product = utils::json::get<string>(val, "product");
quantity = utils::json::get<int>(val, "quantity");
disclosedQuantity = utils::json::get<int>(val, "disclosed_quantity");
validityTtl = utils::json::get<int>(val, "validity_ttl");
price = utils::json::get<double>(val, "price");
triggerPrice = utils::json::get<double>(val, "trigger_price");
averagePrice = utils::json::get<double>(val, "average_price");
Expand All @@ -149,6 +157,7 @@ struct order {
int filledQuantity = -1;
int pendingQuantity = -1;
int cancelledQuantity = -1;
int validityTtl = -1;
double price = -1.0;
double triggerPrice = -1.0;
double averagePrice = -1.0;
Expand Down
2 changes: 2 additions & 0 deletions include/kitepp/userconstants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const string VARIETY_REGULAR = "regular";
const string VARIETY_BO = "bo";
const string VARIETY_CO = "co";
const string VARIETY_AMO = "amo";
const string VERIETY_ICEBERG = "iceberg";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be a typo

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I think the commit (dd7e06b) is showing up so the branch might need to be rebased.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed the typo.

That commit is showing up because I had created this branch from previous PR branch (because I needed those changes here). It doesn't matter because I intend to squash the commits.


// Transaction type
const string TRANSACTION_TYPE_BUY = "BUY";
Expand All @@ -63,6 +64,7 @@ const string TRANSACTION_TYPE_SELL = "SELL";
// Validity
const string VALIDITY_DAY = "DAY";
const string VALIDITY_IOC = "IOC";
const string VALIDITY_TTL = "TTL";

// Exchanges
const string EXCHANGE_NSE = "NSE";
Expand Down
33 changes: 33 additions & 0 deletions tests/unit/kite/order.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,39 @@ TEST(kiteTest, ordersTest) {
EXPECT_EQ(order1.filledQuantity, 0);
EXPECT_EQ(order1.pendingQuantity, 1);
EXPECT_EQ(order1.cancelledQuantity, 1);
EXPECT_EQ(order1.validityTtl, 0);

const kc::order order4 = Orders[3];
EXPECT_EQ(order4.accountID, "");
EXPECT_EQ(order4.placedBy, "XXXXXX");
EXPECT_EQ(order4.orderID, "220524001859672");
EXPECT_EQ(order4.exchangeOrderID, "");
EXPECT_EQ(order4.parentOrderID, "");
EXPECT_EQ(order4.status, "REJECTED");
EXPECT_EQ(order4.statusMessage,
"Insufficient funds. Required margin is 95417.84 but available margin "
"is 74251.80. Check the orderbook for open orders.");
EXPECT_EQ(order4.orderTimestamp, "2022-05-24 12:26:52");
EXPECT_EQ(order4.exchangeUpdateTimestamp, "");
EXPECT_EQ(order4.exchangeTimestamp, "");
EXPECT_EQ(order4.rejectedBy, "");
EXPECT_EQ(order4.variety, "iceberg");
EXPECT_EQ(order4.exchange, "NSE");
EXPECT_EQ(order4.tradingsymbol, "SBIN");
EXPECT_EQ(order4.instrumentToken, 779521);
EXPECT_EQ(order4.orderType, "LIMIT");
EXPECT_EQ(order4.transactionType, "BUY");
EXPECT_EQ(order4.validity, "TTL");
EXPECT_EQ(order4.product, "CNC");
EXPECT_EQ(order4.quantity, 200);
EXPECT_EQ(order4.disclosedQuantity, 0);
EXPECT_DOUBLE_EQ(order4.price, 463);
EXPECT_DOUBLE_EQ(order4.triggerPrice, 0);
EXPECT_DOUBLE_EQ(order4.averagePrice, 0);
EXPECT_EQ(order4.filledQuantity, 0);
EXPECT_EQ(order4.pendingQuantity, 0);
EXPECT_EQ(order4.cancelledQuantity, 0);
EXPECT_EQ(order4.validityTtl, 2);
}

TEST(kiteTest, orderHistoryTest) {
Expand Down