syntax = "proto3";

package dbag.energy.m7t.management.request.v7;

import "google/protobuf/timestamp.proto";
import "dbag/energy/m7t/common/v7/order_common.proto";
import "dbag/energy/m7t/validation/v7/validation.proto";

option java_multiple_files = true;
option java_package = "com.deutscheboerse.energy.m7.api.management.request.v7";

/*
 * The Order Entry message enables a trader to send up to 100 orders at once to the backend for execution.
 * The orders are contained in a so called basket. It is possible to define the execution restriction on a basket level.
 */
message OrderEntry {
  // Execution instruction for the whole list of orders.
  optional dbag.energy.m7t.common.v7.ExecutionInstruction execution_instruction = 1;

  // List of all orders contained in the basket.
  repeated OrderEntryPayload order_list = 2 [
    (energy.m7t.validation.v7.min_occurrence) = 1,
    (energy.m7t.validation.v7.max_occurrence) = 100
  ];
}

/*
 * Represents order structure for Order Entry.
 */
message OrderEntryPayload {
  // Defines if the order is entered on its own account, or as an agent.
  // For valid values, refer to "allowedClearingAcctTypes" in "SystemInfoResp".
  optional string clearing_account_type = 1 [
    (energy.m7t.validation.v7.mandatory) = true,
    (energy.m7t.validation.v7.min_length) = 1,
    (energy.m7t.validation.v7.max_length) = 2
  ];

  // Account for which the order is entered.
  // The order is rejected if the trader tries to enter an account to which they are not assigned.
  optional string account_id = 2 [
    (energy.m7t.validation.v7.mandatory) = true,
    (energy.m7t.validation.v7.min_length) = 1,
    (energy.m7t.validation.v7.max_length) = 32
  ];

  // Delivery area of the order.
  // Mandatory for exchanges with multiple delivery area setup.
  optional string delivery_area = 3 [
    (energy.m7t.validation.v7.min_length) = 16,
    (energy.m7t.validation.v7.max_length) = 16
  ];

  oneof contract_identification {
    // It is mandatory to provide contract identification.
    option (energy.m7t.validation.v7.mandatory_oneof) = true;

    // Underlying contract of the order.
    // Must be set for all pre-defined contracts.
    int64 contract_id = 4 [
      (energy.m7t.validation.v7.min_value) = 0
    ];

    // Contract identification by product details.
    // Used for user-defined contracts (e.g., block contracts).
    ContractIdentificationByProduct contract_identification_by_product = 5;
  }

  // Side of the market the order is entered on.
  optional dbag.energy.m7t.common.v7.OrderSide side = 6 [
    (energy.m7t.validation.v7.mandatory) = true
  ];

  // Type of the order. "REGULAR" is the default value.
  optional dbag.energy.m7t.common.v7.OrderType type = 7;

  // Limit price of the order.
  optional int64 price = 8 [
    (energy.m7t.validation.v7.mandatory) = true
  ];

  // Quantity exposed to the market.
  optional int32 quantity = 9 [
    (energy.m7t.validation.v7.mandatory) = true,
    (energy.m7t.validation.v7.min_value) = 0
  ];

  // Details for stop limit orders.
  optional dbag.energy.m7t.common.v7.StopOrderDetails stop_order_details = 10 [
    (energy.m7t.validation.v7.mandatory_if) = {
      field_name: "type",
      field_value: "ORDER_TYPE_STOP"
    }
  ];

  // Details for Iceberg orders.
  optional dbag.energy.m7t.common.v7.IcebergOrderDetails iceberg_order_details = 11 [
    (energy.m7t.validation.v7.mandatory_if) = {
      field_name: "type",
      field_value: "ORDER_TYPE_ICEBERG"
    }
  ];

  // State of the order. "ACTIVE" is the default value.
  optional dbag.energy.m7t.common.v7.OrderState state = 12;

  // Execution restriction of the order. "NOT_RESTRICTED" is the default value.
  optional dbag.energy.m7t.common.v7.OrderExecutionRestriction execution_restriction = 13;

  // Details for pre-arranged orders.
  optional dbag.energy.m7t.common.v7.PreArrangedOrderDetails pre_arranged_order_details = 14;

  // Details for validity restriction of the order.
  optional dbag.energy.m7t.common.v7.ValidityRestrictionDetails validity_restriction_details = 16;

  // Open Close Indicator, mandatory for futures & cross-product spreads.
  optional dbag.energy.m7t.common.v7.OrderOpenCloseIndicator open_close_indicator = 17;

  // Indicates whether the order shall be automatically transferred to the linked contract
  // after trading in the specific delivery area ends in XBID. Default is "false".
  optional bool aot = 18;

  // Location data for the order. Available only for products with Locations enabled.
  optional dbag.energy.m7t.common.v7.LocationDetails location_details = 19;

  // Metadata which can be used by the client.
  optional dbag.energy.m7t.common.v7.ClientMetadata client_metadata = 20;

  // Indicates whether the order is fast_order or not.
  optional bool fast_order = 21;
}

/*
 * Information which is needed to identify a contract by product and delivery details.
 */
message ContractIdentificationByProduct {
  // Product identifier.
  optional string product = 1 [
    (energy.m7t.validation.v7.mandatory) = true,
    (energy.m7t.validation.v7.max_length) = 255
  ];

  // The start of delivery for the underlying contract.
  optional google.protobuf.Timestamp delivery_start = 2 [
    (energy.m7t.validation.v7.mandatory) = true
  ];

  // The end of delivery for the underlying contract.
  optional google.protobuf.Timestamp delivery_end   = 3 [
    (energy.m7t.validation.v7.mandatory) = true
  ];
}
