Class: Darwinex::Client
- Inherits:
-
Object
- Object
- Darwinex::Client
- Defined in:
- lib/darwinex/client.rb
Constant Summary collapse
- MAX_RETRIES =
5
Instance Method Summary collapse
-
#initialize(consumer_key:, consumer_secret:, max_retries: MAX_RETRIES, logger: Logger.new(STDOUT, progname: 'Darwinex')) ⇒ Client
constructor
A new instance of Client.
- #investor_account(account_id) ⇒ Object
- #list_investor_accounts ⇒ Object
- #list_products(status: nil, page: nil, per_page: nil) ⇒ Object
- #product(product_name) ⇒ Object
- #refresh_access_token(refresh_token) ⇒ Object
Constructor Details
#initialize(consumer_key:, consumer_secret:, max_retries: MAX_RETRIES, logger: Logger.new(STDOUT, progname: 'Darwinex')) ⇒ Client
Returns a new instance of Client.
15 16 17 18 19 20 |
# File 'lib/darwinex/client.rb', line 15 def initialize(consumer_key:, consumer_secret:, max_retries: MAX_RETRIES, logger: Logger.new(STDOUT, progname: 'Darwinex')) @consumer_key = consumer_key @consumer_secret = consumer_secret @max_retries = max_retries @logger = logger end |
Instance Method Details
#investor_account(account_id) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/darwinex/client.rb', line 36 def investor_account(account_id) InvestorAccount.new( account_id: account_id, trading_api: trading_api, investor_account_info_api: investor_account_info_api ) end |
#list_investor_accounts ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/darwinex/client.rb', line 26 def list_investor_accounts investor_account_info_api.list_investor_accounts.map do |investor_account| InvestorAccount.new( account_id: investor_account['id'], trading_api: trading_api, investor_account_info_api: investor_account_info_api ) end end |
#list_products(status: nil, page: nil, per_page: nil) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/darwinex/client.rb', line 44 def list_products(status: nil, page: nil, per_page: nil) args = { status: status, page: page, per_page: per_page } api_response = info_api.list_products(args) products = api_response['content'].map { |product| product(product['productName']) } response = api_response.tap { |h| h.delete('content') } response['products'] = products response end |
#product(product_name) ⇒ Object
62 63 64 65 66 67 |
# File 'lib/darwinex/client.rb', line 62 def product(product_name) Product.new( product_name: product_name, info_api: info_api ) end |
#refresh_access_token(refresh_token) ⇒ Object
22 23 24 |
# File 'lib/darwinex/client.rb', line 22 def refresh_access_token(refresh_token) config.refresh_access_token(refresh_token) end |