Class: DhanHQ::Models::IcebergOrder
- Includes:
- Concerns::ApiResponseHandler
- Defined in:
- lib/DhanHQ/models/iceberg_order.rb
Overview
Static IP Whitelisting: Iceberg order creation, modification, and cancellation APIs require Static IP whitelisting.
Model for creating and managing Iceberg Orders.
Iceberg orders allow you to place a large order while revealing only a small "visible" portion (disclosed quantity) to the market at a time. The remaining quantity is hidden and filled as prior legs execute, reducing market impact and information leakage.
Constant Summary
Constants included from ResponseHelper
ResponseHelper::STATUS_ERROR_FALLBACK
Instance Attribute Summary
Attributes inherited from BaseModel
Class Method Summary collapse
-
.all ⇒ Array<IcebergOrder>
Retrieves all iceberg orders for the day.
-
.create(params) ⇒ IcebergOrder?
Creates a new iceberg order.
-
.find(order_id) ⇒ IcebergOrder?
Retrieves a specific iceberg order by ID.
- .resource ⇒ DhanHQ::Resources::IcebergOrders
Instance Method Summary collapse
-
#cancel ⇒ Boolean
Cancels the iceberg order.
-
#modify(new_params) ⇒ IcebergOrder?
Modifies an existing iceberg order.
Methods inherited from BaseModel
api, api_type, #assign_attributes, attributes, #delete, #destroy, #id, #initialize, #new_record?, #optionchain_api?, parse_collection_response, #persisted?, resource_path, #save, #save!, #to_request_params, #update, #valid?, validate_attributes, validation_contract, #validation_contract, where
Methods included from APIHelper
Methods included from AttributeHelper
#camelize_keys, #inspect, #normalize_keys, #snake_case, #titleize_keys
Methods included from ValidationHelper
#valid?, #validate!, #validate_params!
Methods included from RequestHelper
Constructor Details
This class inherits a constructor from DhanHQ::BaseModel
Class Method Details
.all ⇒ Array<IcebergOrder>
Retrieves all iceberg orders for the day.
71 72 73 74 75 76 |
# File 'lib/DhanHQ/models/iceberg_order.rb', line 71 def all response = resource.all return [] unless response.is_a?(Array) response.map { |o| new(o, skip_validation: true) } end |
.create(params) ⇒ IcebergOrder?
Creates a new iceberg order.
93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/DhanHQ/models/iceberg_order.rb', line 93 def create(params) normalized = snake_case(params) config = DhanHQ.configuration normalized[:dhan_client_id] ||= config.client_id if config&.client_id validate_params!(normalized, DhanHQ::Contracts::IcebergOrderCreateContract) formatted = camelize_keys(normalized) response = resource.create(formatted) return nil unless response.is_a?(Hash) && response["orderId"] new(order_id: response["orderId"], order_status: response["orderStatus"], skip_validation: true) end |
.find(order_id) ⇒ IcebergOrder?
Retrieves a specific iceberg order by ID.
82 83 84 85 86 87 |
# File 'lib/DhanHQ/models/iceberg_order.rb', line 82 def find(order_id) response = resource.find(order_id) return nil unless response.is_a?(Hash) && response.any? new(response, skip_validation: true) end |
.resource ⇒ DhanHQ::Resources::IcebergOrders
64 65 66 |
# File 'lib/DhanHQ/models/iceberg_order.rb', line 64 def resource @resource ||= DhanHQ::Resources::IcebergOrders.new end |
Instance Method Details
#cancel ⇒ Boolean
Cancels the iceberg order.
131 132 133 134 135 136 |
# File 'lib/DhanHQ/models/iceberg_order.rb', line 131 def cancel raise "Order ID is required to cancel an iceberg order" unless order_id response = self.class.resource.cancel(order_id) response.is_a?(Hash) && response["orderStatus"] == DhanHQ::Constants::OrderStatus::CANCELLED end |
#modify(new_params) ⇒ IcebergOrder?
Modifies an existing iceberg order.
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/DhanHQ/models/iceberg_order.rb', line 110 def modify(new_params) raise "Order ID is required to modify an iceberg order" unless order_id DhanHQ.logger&.info("[DhanHQ::Models::IcebergOrder] Modifying order #{order_id}") full_params = snake_case(new_params) config = DhanHQ.configuration full_params[:dhan_client_id] ||= config.client_id if config&.client_id full_params[:order_id] = order_id validate_params!(full_params, DhanHQ::Contracts::IcebergOrderModifyContract) formatted = camelize_keys(full_params) response = self.class.resource.update(order_id, formatted) success = handle_api_response(response, success_key: "orderId", context: "[DhanHQ::Models::IcebergOrder] Modification") return self.class.find(order_id) if success nil end |