Class: DhanHQ::Models::Funds
- Defined in:
- lib/DhanHQ/models/funds.rb
Overview
The API response contains a typo in the field name (‘availabelBalance`). The model automatically maps this to the correctly spelled `available_balance` attribute for convenience.
Model for retrieving trading account fund information including balance, margin utilized, collateral, etc.
This endpoint provides comprehensive information about your trading account including available balance, start of day limit, collateral amounts, utilized amounts, and withdrawable balance.
Constant Summary collapse
- HTTP_PATH =
Base path used by the funds resource.
"/v2/fundlimit"
Instance Attribute Summary
Attributes inherited from BaseModel
Class Method Summary collapse
-
.balance ⇒ Float
Convenience method to fetch only the available balance.
-
.fetch ⇒ Funds
Fetches all fund limit details for your trading account.
-
.resource ⇒ DhanHQ::Resources::Funds
Provides a shared instance of the Funds resource.
Instance Method Summary collapse
-
#assign_attributes ⇒ void
Normalizes the typo’d ‘availabelBalance` key from the API response to `available_balance`.
Methods inherited from BaseModel
all, api, api_type, attributes, create, #delete, #destroy, find, #id, #initialize, #new_record?, #optionchain_api?, parse_collection_response, #persisted?, resource_path, #save, #save!, #to_request_params, #update, #valid?, validate_attributes, 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
.balance ⇒ Float
Convenience method to fetch only the available balance.
This method calls fetch internally and returns just the ‘available_balance` attribute, which is the amount available to trade.
110 111 112 |
# File 'lib/DhanHQ/models/funds.rb', line 110 def balance fetch.available_balance end |
.fetch ⇒ Funds
This is a GET request with no body parameters required
Fetches all fund limit details for your trading account.
Retrieves comprehensive information about account balance, margin utilized, collateral, receivable amounts, and withdrawable balance. No request parameters are required.
88 89 90 91 |
# File 'lib/DhanHQ/models/funds.rb', line 88 def fetch response = resource.fetch new(response, skip_validation: true) end |
.resource ⇒ DhanHQ::Resources::Funds
Provides a shared instance of the Funds resource.
51 52 53 |
# File 'lib/DhanHQ/models/funds.rb', line 51 def resource @resource ||= DhanHQ::Resources::Funds.new end |
Instance Method Details
#assign_attributes ⇒ void
This method returns an undefined value.
Normalizes the typo’d ‘availabelBalance` key from the API response to `available_balance`.
The API currently returns ‘availabelBalance` (note the typo). This method ensures backwards compatibility while exposing a correctly spelled attribute accessor.
39 40 41 42 43 44 |
# File 'lib/DhanHQ/models/funds.rb', line 39 def assign_attributes if @attributes.key?(:availabel_balance) && !@attributes.key?(:available_balance) @attributes[:available_balance] = @attributes[:availabel_balance] end super end |