Class: TDAmeritrade::Operations::CreateWatchlist
- Inherits:
-
BaseOperation
- Object
- BaseOperation
- TDAmeritrade::Operations::CreateWatchlist
- Includes:
- Support::BuildWatchlistItems
- Defined in:
- lib/tdameritrade/operations/create_watchlist.rb
Constant Summary
Constants inherited from BaseOperation
BaseOperation::HTTP_DEBUG_OUTPUT
Instance Attribute Summary
Attributes inherited from BaseOperation
Instance Method Summary collapse
Methods included from Support::BuildWatchlistItems
Methods inherited from BaseOperation
Methods included from Util
handle_api_error, parse_json_response, response_success?
Constructor Details
This class inherits a constructor from TDAmeritrade::Operations::BaseOperation
Instance Method Details
#call(account_id, watchlist_name, symbols) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/tdameritrade/operations/create_watchlist.rb', line 8 def call(account_id, watchlist_name, symbols) body = { "name": watchlist_name, "watchlistItems": build_watchlist_items(symbols) }.to_json uri = URI("https://api.tdameritrade.com/v1/accounts/#{account_id}/watchlists") request = Net::HTTP::Post.new( uri.path, 'authorization' => "Bearer #{client.access_token}", 'content-type' => 'application/json' ) request.body = body response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) { |http| http.request(request) } if response_success?(response) true else parse_api_response(response) end end |