Class: DhanHQ::Resources::SuperOrders

Inherits:
BaseAPI
  • Object
show all
Includes:
Concerns::OrderAudit
Defined in:
lib/DhanHQ/resources/super_orders.rb

Overview

Resource client for multi-leg super orders.

Constant Summary collapse

API_TYPE =

Super orders are executed via the trading API.

:order_api
HTTP_PATH =

Base path for super order endpoints.

"/v2/super/orders"
SUPER_ORDER_LEGS =
%w[ENTRY_LEG STOP_LOSS_LEG TARGET_LEG].freeze

Instance Attribute Summary

Attributes inherited from BaseAPI

#client

Instance Method Summary collapse

Methods inherited from BaseAPI

#delete, #get, #initialize, #post, #put

Methods included from AttributeHelper

#camelize_keys, #deep_camelize_keys, #inspect, #normalize_keys, #snake_case, #titleize_keys

Methods included from APIHelper

#handle_response

Constructor Details

This class inherits a constructor from DhanHQ::BaseAPI

Instance Method Details

#allArray<Hash>

Lists all configured super orders.

Returns:

  • (Array<Hash>)


21
22
23
# File 'lib/DhanHQ/resources/super_orders.rb', line 21

def all
  get("")
end

#cancel(order_id, leg_name) ⇒ Hash

Cancels a specific leg from a super order.

Parameters:

  • order_id (String)
  • leg_name (String)

    One of ENTRY_LEG, STOP_LOSS_LEG, TARGET_LEG (per API path enum)

Returns:

  • (Hash)

Raises:



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/DhanHQ/resources/super_orders.rb', line 53

def cancel(order_id, leg_name)
  normalized = leg_name.to_s.upcase.strip
  unless SUPER_ORDER_LEGS.include?(normalized)
    raise DhanHQ::ValidationError,
          "leg_name must be one of: #{SUPER_ORDER_LEGS.join(", ")}"
  end

  ensure_live_trading!
  log_order_context("DHAN_SUPER_ORDER_CANCEL_ATTEMPT", { order_id: order_id, leg_name: normalized })
  delete("/#{order_id}/#{normalized}")
end

#create(params) ⇒ Hash

Creates a new super order.

Parameters:

  • params (Hash)

Returns:

  • (Hash)


29
30
31
32
33
34
# File 'lib/DhanHQ/resources/super_orders.rb', line 29

def create(params)
  ensure_live_trading!
  run_risk_checks!(params)
  log_order_context("DHAN_SUPER_ORDER_ATTEMPT", params)
  post("", params: params)
end

#update(order_id, params) ⇒ Hash

Updates an existing super order.

Parameters:

  • order_id (String)
  • params (Hash)

Returns:

  • (Hash)


41
42
43
44
45
# File 'lib/DhanHQ/resources/super_orders.rb', line 41

def update(order_id, params)
  ensure_live_trading!
  log_order_context("DHAN_SUPER_ORDER_MODIFY_ATTEMPT", params.merge(order_id: order_id))
  put("/#{order_id}", params: params)
end