Class: DhanHQ::Resources::GlobalStocks::Orders

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

Overview

Resource client for the Global Stocks (US equities) order endpoints.

POST   /v2/globalstocks/orders
PUT    /v2/globalstocks/orders/{order-id}
DELETE /v2/globalstocks/orders/{order-id}
GET    /v2/globalstocks/orders
GET    /v2/globalstocks/orders/{order-id}

Writes go through the same Concerns::OrderAudit guardrails as domestic orders: ENV["LIVE_TRADING"]="true" is required, and every attempt emits a structured audit log line.

The pre-trade DhanHQ::Risk::Pipeline is intentionally not run here. Its checks (lot-size multiples, ASM/GSM surveillance lists, F&O product support, NSE/BSE market hours) resolve instruments from the Indian scrip master, which does not contain US securities.

Constant Summary collapse

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

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

#all ⇒ Array<Hash>

Retrieves the current trading day's Global Stocks order book.

Returns:

  • (Array<Hash>)


71
72
73
# File 'lib/DhanHQ/resources/global_stocks/orders.rb', line 71

def all
  get("")
end

#cancel(order_id) ⇒ Hash

Cancels a pending Global Stocks order.

Parameters:

  • order_id (String)

Returns:

  • (Hash) —

    { orderId:, orderStatus: }



62
63
64
65
66
# File 'lib/DhanHQ/resources/global_stocks/orders.rb', line 62

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

#create(params) ⇒ Hash

Places a new Global Stocks order.

Parameters:

Returns:

  • (Hash) —

    { orderId:, orderStatus: }

Raises:



39
40
41
42
43
44
# File 'lib/DhanHQ/resources/global_stocks/orders.rb', line 39

def create(params)
  ensure_live_trading!
  log_order_context("DHAN_GLOBAL_ORDER_ATTEMPT", params)
  validate_place_order!(params)
  post("", params: params)
end

#find(order_id) ⇒ Hash

Retrieves a single Global Stocks order by its Dhan order id.

Parameters:

  • order_id (String)

Returns:

  • (Hash)


79
80
81
# File 'lib/DhanHQ/resources/global_stocks/orders.rb', line 79

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

#update(order_id, params) ⇒ Hash

Modifies a pending Global Stocks order.

Parameters:

  • order_id (String)
  • params (Hash) —

    Fields to change, in snake_case.

Returns:

  • (Hash) —

    { orderId:, orderStatus: }



51
52
53
54
55
56
# File 'lib/DhanHQ/resources/global_stocks/orders.rb', line 51

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