Class: Webull::Account
- Inherits:
-
Object
- Object
- Webull::Account
- Defined in:
- lib/webull/account.rb
Overview
Account defines a user account object for the Webull API
Instance Method Summary collapse
- #account_id ⇒ Object
-
#initialize(params = {}) ⇒ Account
constructor
A new instance of Account.
- #orders(params = {}) ⇒ Object
- #refresh ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Account
Returns a new instance of Account.
7 8 9 10 |
# File 'lib/webull/account.rb', line 7 def initialize(params = {}) @tokens = params[:tokens] || raise('API tokens not provided') @udid = params[:udid] || raise('Device ID (udid) not provided') end |
Instance Method Details
#account_id ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/webull/account.rb', line 22 def account_id return @account_id if @account_id resp = HTTParty.get( 'https://tradeapi.webullbroker.com/api/trade/account/getSecAccountList/v4', headers: headers ) raise("Account ID request failed: #{resp.code}") unless resp.success? raise("Account ID error received: #{resp['msg']}") unless resp['success'] @account_id = resp['data'].first['secAccountId'] end |
#orders(params = {}) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/webull/account.rb', line 33 def orders(params = {}) HTTParty.get( 'https://tradeapi.webullbroker.com/api/trade/v2/option/list', query: { secAccountId: account_id }.merge(params), headers: headers ) end |
#refresh ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/webull/account.rb', line 12 def refresh resp = HTTParty.post( 'https://userapi.webull.com/api/passport/refreshToken', query: { refreshToken: @tokens.refresh }, headers: headers ) raise("Refresh request failed: #{resp.code}") unless resp.success? @tokens = Tokens.from_resp(resp) end |