syntax = "proto3";

package trading;

service TradingEngine {
  rpc PlaceOrder (PlaceOrderRequest) returns (TradingResponse);
  rpc CryptoPlaceOrder (PlaceOrderRequest) returns (TradingResponse);
  rpc NfoPlaceOrder (PlaceOrderRequest) returns (TradingResponse);
  
  rpc ModifyOrder (ModifyOrderRequest) returns (TradingResponse);
  rpc CancelOrder (CancelOrderRequest) returns (TradingResponse);
  rpc ExitPosition (ExitPositionRequest) returns (TradingResponse);
  
  rpc GetTradingSummary (SummaryRequest) returns (SummaryResponse);
  rpc CombinedMarginOrder (CombinedMarginOrderRequest) returns (TradingResponse);
}

// ----------------------------------------
// Standard Payload Wrappers
// ----------------------------------------
message TradingResponse {
  bool status = 1;
  string msg = 2;
  string ot = 3;
  string data = 4;
}

// ----------------------------------------
// Place Order
// ----------------------------------------
message PlaceOrderRequest {
  int32 uid = 1;
  string apptoken = 2;
  string trading_status = 3;
  
  int32 cid = 4;
  int32 sid = 5;
  double qty = 6;
  string action = 7;
  double entry_price = 8;
  double exit_price = 9;
  double lot_size = 10;
  int64 orderid = 11;
  double target = 12;
  double stoploss = 13;
  string variety = 14;
  string product = 15;
  string order_type = 16;
  double profit = 17;
  double investment = 18;
}

// ----------------------------------------
// Modify Order
// ----------------------------------------
message ModifyOrderRequest {
  int32 uid = 1;
  string apptoken = 2;
  string trading_status = 3;
  
  int64 id = 4;
  double target = 5;
  double stoploss = 6;
  string order_type = 7;
  string type = 8;
  double qty = 9;
}

// ----------------------------------------
// Cancel Order
// ----------------------------------------
message CancelOrderRequest {
  int32 uid = 1;
  string apptoken = 2;
  int64 id = 3;
}

// ----------------------------------------
// Exit Position
// ----------------------------------------
message ExitPositionRequest {
  int32 uid = 1;
  string apptoken = 2;
  int32 cid = 3;
  string sids_json = 4;
}

// ----------------------------------------
// Trading Summary
// ----------------------------------------
message SummaryRequest {
  int32 uid = 1;
  int32 cid = 2;
  string segment = 3;
}

message SummaryResponse {
  bool status = 1;
  string msg = 2;
  string ot = 3;
  string data_json = 4; 
}

// ----------------------------------------
// Combined Margin Order
// ----------------------------------------
message CombinedMarginOrderRequest {
  int32 uid = 1;
  int32 cid = 2;
  int32 sid = 3;
  double quantity = 4;
  double price = 5;
  double trigger_price = 6;
  string order_type = 7;
  string transaction_type = 8;
  string apptoken = 9;
}

