Class: DhanHQ::Resources::GlobalStocks::MarginCalculator

Inherits:
BaseAPI
  • Object
show all
Defined in:
lib/DhanHQ/resources/global_stocks/margin_calculator.rb

Overview

Resource client for the Global Stocks pre-trade calculators.

POST /v2/globalstocks/margincalculator  

Both endpoints take the same request body. The API documents price and quantity as strings, so numeric input is stringified before sending.

Constant Summary collapse

API_TYPE =
:non_trading_api
HTTP_PATH =
"/v2/globalstocks"

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

#calculate(params) ⇒ Hash

Calculates the margin required for a Global Stocks order.

Parameters:

  • params (Hash) —

    :security_id, :transaction_type, :price, :quantity

Returns:

  • (Hash) —

    Margin breakdown.



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

def calculate(params)
  post("/margincalculator", params: wire_params(params))
end

#estimate(params) ⇒ Hash

Estimates the charges applicable to a Global Stocks order.

Parameters:

  • params (Hash) —

    :security_id, :transaction_type, :price, :quantity

Returns:

  • (Hash) —

    Charge breakdown.



29
30
31
# File 'lib/DhanHQ/resources/global_stocks/margin_calculator.rb', line 29

def estimate(params)
  post("/transEstimate", params: wire_params(params))
end