Git Product home page Git Product logo

tradier.rb's People

Contributors

jcbarry avatar stve avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tradier.rb's Issues

Can't convert Symbol into Integer

TypeError - can't convert Symbol into Integer:
   () Users/jbarry/Projects/brokerage.tradier.com/.bundle/bundler/gems/tradier.rb-e4735c0c7b00/lib/tradier/api/utils.rb:170:in `block in nested_response_body'
   () Users/jbarry/Projects/brokerage.tradier.com/.bundle/bundler/gems/tradier.rb-e4735c0c7b00/lib/tradier/api/utils.rb:169:in `nested_response_body'
   () Users/jbarry/Projects/brokerage.tradier.com/.bundle/bundler/gems/tradier.rb-e4735c0c7b00/lib/tradier/api/utils.rb:147:in `nested_objects_from_response'
   () Users/jbarry/Projects/brokerage.tradier.com/.bundle/bundler/gems/tradier.rb-e4735c0c7b00/lib/tradier/api/utils.rb:103:in `position_objects_from_response'
   () Users/jbarry/Projects/brokerage.tradier.com/.bundle/bundler/gems/tradier.rb-e4735c0c7b00/lib/tradier/api/accounts.rb:24:in `positions'
  app/controllers/user/ajax/positions_controller.rb:5:in `index'

Setting new connection options breaks API integration

I tried to add a request timeout connection option, but it caused the API request to stop requesting JSON data and get XML data which was generated a JSON parse error.

client = Tradier::Client.new({
  access_token: 'token values here',
  connection_options: { request: { timeout: 30 } },
})

I would have expected my connection_options to be merged with default connection options and have the headers: { :accept => 'application/json' } configuration maintained.

Balances to_xml/to_json not working properly

irb(main):001:0> User.first.tradier.balances
  User Load (0.3ms)  SELECT `users`.* FROM `users` LIMIT 1
   (0.2ms)  SELECT COUNT(*) FROM `agreements` WHERE `agreements`.`user_id` = 1
  Oauth::AccessToken Load (0.2ms)  SELECT `access_tokens`.* FROM `access_tokens` WHERE `access_tokens`.`uuid` = 'test-ebenes' AND `access_tokens`.`app_id` = 'd3caaf2a-d098-4a28-8bde-387f407c92d0' LIMIT 1
=> [#<Tradier::BalanceCollection:0x007f91b9b09738 @attrs={:balances=>{:account_number=>10026165, :account_type=>1, :cash=>3293903.03913, :close_pl=>0.0, :dividend_balance=>0.0, :equity=>3298548.99913, :long_liquid_value=>0.0, :long_market_value=>20761.42, :market_value=>41522.82, :net_value=>-235000.0, :open_pl=>172.7, :option_long_value=>11.0, :option_requirement=>0.0, :option_short_value=>0.0, :pending_cash=>119.5, :pending_orders_count=>3, :short_liquid_value=>0.0, :short_market_value=>0.0, :stock_long_value=>4628.03, :stock_short_value=>0.0, :sweep=>0.0, :cash_available=>20761.42, :prev_day_cash_available=>0.0}, :account_number=>10026165}>, #<Tradier::BalanceCollection:0x007f91b9b09710 @attrs={:balances=>{:account_number=>15970260, :account_type=>2, :cash=>0.0, :close_pl=>0.0, :dividend_balance=>0.0, :equity=>10048225.16, :long_liquid_value=>67484.98, :long_market_value=>67484.98, :market_value=>0.0, :net_value=>0.0, :open_pl=>-1818.37, :option_long_value=>831.0, :option_requirement=>0.0, :option_short_value=>0.0, :pending_cash=>0.0, :pending_orders_count=>0, :short_liquid_value=>0.0, :short_market_value=>0.0, :stock_long_value=>48034.03, :stock_short_value=>0.0, :sweep=>0.0, :day_trade_buying_power=>20000000.0, :excess=>10000000.0, :fed_call=>0.0, :maintenance_call=>0.0, :maintenance_call_previous=>0, :option_buying_power=>20000000.0, :sma=>-35307.0, :sma_change=>0.0, :sma_or_call_previous=>0, :stock_buying_power=>20000000.0}, :account_number=>15970260}>, #<Tradier::BalanceCollection:0x007f91b9b096c0 @attrs={:balances=>{:account_number=>10060892, :account_type=>2, :cash=>0.0, :close_pl=>0.0, :dividend_balance=>0.0, :equity=>0.0, :long_liquid_value=>260.88, :long_market_value=>260.88, :market_value=>0.0, :net_value=>0.0, :open_pl=>0.0, :option_long_value=>0.0, :option_requirement=>0.0, :option_short_value=>0.0, :pending_cash=>0.0, :pending_orders_count=>0, :short_liquid_value=>0.0, :short_market_value=>0.0, :stock_long_value=>0.0, :stock_short_value=>0.0, :sweep=>0.0, :fed_call=>0.0, :maintenance_call=>0.0, :option_buying_power=>0.0, :sma=>-130.0, :sma_change=>0.0, :sma_or_call_previous=>0, :stock_buying_power=>0.0}, :account_number=>10060892}>]
irb(main):002:0> User.first.tradier.balances.to_xml
  User Load (0.4ms)  SELECT `users`.* FROM `users` LIMIT 1
   (0.3ms)  SELECT COUNT(*) FROM `agreements` WHERE `agreements`.`user_id` = 1
  Oauth::AccessToken Load (0.3ms)  SELECT `access_tokens`.* FROM `access_tokens` WHERE `access_tokens`.`uuid` = 'test-ebenes' AND `access_tokens`.`app_id` = 'd3caaf2a-d098-4a28-8bde-387f407c92d0' LIMIT 1
=> "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<tradier-balance-collections type=\"array\">\n  <tradier-balance-collection type=\"Tradier::BalanceCollection\">#&lt;Tradier::BalanceCollection:0x007f91b9a89ec0&gt;</tradier-balance-collection>\n  <tradier-balance-collection type=\"Tradier::BalanceCollection\">#&lt;Tradier::BalanceCollection:0x007f91b9a89d58&gt;</tradier-balance-collection>\n  <tradier-balance-collection type=\"Tradier::BalanceCollection\">#&lt;Tradier::BalanceCollection:0x007f91b9a89d30&gt;</tradier-balance-collection>\n</tradier-balance-collections>\n"
irb(main):003:0> User.first.tradier.balances.to_json
  User Load (0.4ms)  SELECT `users`.* FROM `users` LIMIT 1
   (0.3ms)  SELECT COUNT(*) FROM `agreements` WHERE `agreements`.`user_id` = 1
  Oauth::AccessToken Load (0.3ms)  SELECT `access_tokens`.* FROM `access_tokens` WHERE `access_tokens`.`uuid` = 'test-ebenes' AND `access_tokens`.`app_id` = 'd3caaf2a-d098-4a28-8bde-387f407c92d0' LIMIT 1
NoMethodError: undefined method `map' for nil:NilClass
    from /Users/jbarry/Projects/brokerage.tradier.com/.bundle/bundler/gems/tradier.rb-571c278384cc/lib/tradier/balance_collection.rb:15:in `balances'
    from /Users/jbarry/Projects/brokerage.tradier.com/.bundle/bundler/gems/tradier.rb-571c278384cc/lib/tradier/balance_collection.rb:9:in `each'
    from /Users/jbarry/Projects/brokerage.tradier.com/.bundle/gems/activesupport-3.2.13/lib/active_support/json/encoding.rb:201:in `to_a'
    from /Users/jbarry/Projects/brokerage.tradier.com/.bundle/gems/activesupport-3.2.13/lib/active_support/json/encoding.rb:201:in `as_json'
    from /Users/jbarry/Projects/brokerage.tradier.com/.bundle/gems/activesupport-3.2.13/lib/active_support/json/encoding.rb:55:in `block in as_json'
    from /Users/jbarry/Projects/brokerage.tradier.com/.bundle/gems/activesupport-3.2.13/lib/active_support/json/encoding.rb:77:in `check_for_circular_references'
    from /Users/jbarry/Projects/brokerage.tradier.com/.bundle/gems/activesupport-3.2.13/lib/active_support/json/encoding.rb:54:in `as_json'
    from /Users/jbarry/Projects/brokerage.tradier.com/.bundle/gems/activesupport-3.2.13/lib/active_support/json/encoding.rb:209:in `block in as_json'
    from /Users/jbarry/Projects/brokerage.tradier.com/.bundle/gems/activesupport-3.2.13/lib/active_support/json/encoding.rb:209:in `map'
    from /Users/jbarry/Projects/brokerage.tradier.com/.bundle/gems/activesupport-3.2.13/lib/active_support/json/encoding.rb:209:in `as_json'
    from /Users/jbarry/Projects/brokerage.tradier.com/.bundle/gems/activesupport-3.2.13/lib/active_support/json/encoding.rb:47:in `block in encode'
    from /Users/jbarry/Projects/brokerage.tradier.com/.bundle/gems/activesupport-3.2.13/lib/active_support/json/encoding.rb:77:in `check_for_circular_references'
    from /Users/jbarry/Projects/brokerage.tradier.com/.bundle/gems/activesupport-3.2.13/lib/active_support/json/encoding.rb:46:in `encode'
    from /Users/jbarry/Projects/brokerage.tradier.com/.bundle/gems/activesupport-3.2.13/lib/active_support/json/encoding.rb:31:in `encode'
    from /Users/jbarry/Projects/brokerage.tradier.com/.bundle/gems/activesupport-3.2.13/lib/active_support/core_ext/object/to_json.rb:16:in `to_json'
    from (irb):3
    from /Users/jbarry/Projects/brokerage.tradier.com/.bundle/gems/railties-3.2.13/lib/rails/commands/console.rb:47:in `start'
    from /Users/jbarry/Projects/brokerage.tradier.com/.bundle/gems/railties-3.2.13/lib/rails/commands/console.rb:8:in `start'
    from /Users/jbarry/Projects/brokerage.tradier.com/.bundle/gems/railties-3.2.13/lib/rails/commands.rb:41:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'irb(main):004:0> 

Exception

Sometimes when I call Tradier::Client#quote, I see the following:

2017-03-01 02:24:09.863 -0500 /home/stockbot/stockbot/vendor/bundle/ruby/2.3.0/gems/tradier-0.5.6/lib/tradier/api/utils/base.rb:37:in `block in nested_response_body'
/home/stockbot/stockbot/vendor/bundle/ruby/2.3.0/gems/tradier-0.5.6/lib/tradier/api/utils/base.rb:36:in `each'
/home/stockbot/stockbot/vendor/bundle/ruby/2.3.0/gems/tradier-0.5.6/lib/tradier/api/utils/base.rb:36:in `nested_response_body'
/home/stockbot/stockbot/vendor/bundle/ruby/2.3.0/gems/tradier-0.5.6/lib/tradier/api/utils/base.rb:20:in `nested_array'
/home/stockbot/stockbot/vendor/bundle/ruby/2.3.0/gems/tradier-0.5.6/lib/tradier/api/utils/quote.rb:9:in `body'
/home/stockbot/stockbot/vendor/bundle/ruby/2.3.0/gems/tradier-0.5.6/lib/tradier/api/markets.rb:17:in `quotes'
/home/stockbot/stockbot/simple_tradier_client.rb:25:in `get_last_price'
stopper2.rb:130:in `get_last_price'
stopper2.rb:52:in `do_stop'
stopper2.rb:39:in `block in run_once'
stopper2.rb:38:in `each'
stopper2.rb:38:in `run_once'
stopper2.rb:21:in `block in run'
stopper2.rb:20:in `loop'
stopper2.rb:20:in `run'
stopper2.rb:145:in `<main>'
undefined method `[]' for nil:NilClass

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.