• Invest: 1-855-880-2559
  • Open 24/7

Ally Invest API

Ruby Streaming

Ruby's EventMachine is used to sign, make and handle API requests with an evented approach.

require 'em-http'
require 'em-http/middleware/oauth'
credentials = {
  :consumer_key        => "<CONSUMER_KEY>",
  :consumer_secret     => "<CONSUMER_SECRET>",
  :access_token        => "<ACCESS_TOKEN>",
  :access_token_secret => "<ACCESS_TOKEN_SECRET>"
}
EM.run do
  conn = EventMachine::HttpRequest.new('https://stream.tradeking.com/v1/market/quotes.json?symbols=F')
  conn.use EventMachine::Middleware::OAuth, credentials
  http = conn.get
  http.stream { |chunk| puts chunk }
  http.errback do
    EM.stop
  end
  trap("INT")  { http.close; EM.stop }
  trap("TERM") { http.close; EM.stop }
end
Disclaimer:

Any mention of actual symbols are to be used for coding purposes only and do not imply a recommendation or solicitation to buy or sell a particular security or to engage in any particular investment strategy.

At the time of publication and in the preceding month, Ally Invest did not have ownership greater than 1% in any stocks mentioned here and does not have any other actual, material conflict of interest known at the time of publication.

Ally Invest did not receive compensation from a public offering or from investment banking services related to any companies mentioned here within the past 12 months, or expects to receive any in the next 3 months. Ally Invest did not engage in market making in the securities mentioned here.

Ally Invest Securities' background can be found at FINRA's BrokerCheck. Options involve risk and are not suitable for all investors.

Review the Characteristics and Risks of Standardized Options brochure (PDF) before you begin trading options. Options investors may lose the entire amount of their investment in a relatively short period of time.