Class: DhanHQ::Resources::TwapOrders

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

Overview

Resource client for TWAP order management.

Constant Summary collapse

API_TYPE =
:order_api
HTTP_PATH =
"/v2/orders/twap"

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, #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 TWAP orders for the account.

Returns:

  • (Array<Hash>)


17
18
19
# File 'lib/DhanHQ/resources/twap_orders.rb', line 17

def all
  get("")
end

#cancel(order_id) ⇒ Hash

Cancels a TWAP order.

Parameters:

  • order_id (String)

Returns:

  • (Hash)


55
56
57
58
59
# File 'lib/DhanHQ/resources/twap_orders.rb', line 55

def cancel(order_id)
  ensure_live_trading!
  log_order_context("DHAN_TWAP_ORDER_CANCEL_ATTEMPT", { order_id: order_id })
  delete("/#{order_id}")
end

#create(params) ⇒ Hash

Creates a new TWAP order.

Parameters:

  • params (Hash)

Returns:

  • (Hash)


25
26
27
28
29
30
# File 'lib/DhanHQ/resources/twap_orders.rb', line 25

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

#find(order_id) ⇒ Hash

Fetches a specific TWAP order by ID.

Parameters:

  • order_id (String)

Returns:

  • (Hash)


36
37
38
# File 'lib/DhanHQ/resources/twap_orders.rb', line 36

def find(order_id)
  get("/#{order_id}")
end

#update(order_id, params) ⇒ Hash

Updates an existing TWAP order.

Parameters:

  • order_id (String)
  • params (Hash)

Returns:

  • (Hash)


45
46
47
48
49
# File 'lib/DhanHQ/resources/twap_orders.rb', line 45

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