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"
Constants included from ResponseHelper
ResponseHelper::STATUS_ERROR_FALLBACK
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
availabelBalancekey from the API response toavailable_balance. -
#to_prompt ⇒ Object
Returns a concise prompt-friendly summary of funds.
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, validation_contract, where
Methods included from APIHelper
Methods included from AttributeHelper
#camelize_keys, #deep_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.
122 123 124 |
# File 'lib/DhanHQ/models/funds.rb', line 122 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.
100 101 102 103 |
# File 'lib/DhanHQ/models/funds.rb', line 100 def fetch response = resource.fetch new(response, skip_validation: true) end |
.resource ⇒ DhanHQ::Resources::Funds
Provides a shared instance of the Funds resource.
63 64 65 |
# File 'lib/DhanHQ/models/funds.rb', line 63 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.
51 52 53 54 55 56 |
# File 'lib/DhanHQ/models/funds.rb', line 51 def assign_attributes if @attributes.key?(:availabel_balance) && !@attributes.key?(:available_balance) @attributes[:available_balance] = @attributes[:availabel_balance] end super end |
#to_prompt ⇒ Object
Returns a concise prompt-friendly summary of funds.
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/DhanHQ/models/funds.rb', line 33 def to_prompt parts = [] parts << "available=₹#{available_balance}" if available_balance parts << "utilized=₹#{utilized_amount}" if utilized_amount parts << "withdrawable=₹#{withdrawable_balance}" if withdrawable_balance parts << "collateral=₹#{collateral_amount}" if collateral_amount&.positive? parts << "sod_limit=₹#{sod_limit}" if sod_limit parts << "blocked_payout=₹#{blocked_payout_amount}" if blocked_payout_amount&.positive? parts.join(", ") end |