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

Ally Invest API

PHP

This short example will show you how to authorize your own account against the API and make requests. Note that we aren't following a full OAuth flow here because as a developer you already have access to your own access token and secret.

<?php
  // This is using the PHP OAuth extension.
  // http://www.php.net/manual/en/book.oauth.php
  // Your keys/secrets for access
  $consumer_key     = '0cc175b9c0f1b6a831c399e269772661';
  $consumer_secret  = 'ff2513194e75315625628304c9eb66e8';
  $access_token     = '150a96573adf12b21dab621e85497e6e';
  $access_secret    = '5c7b57d450a71d378a5eda991f809e56';
  try {
    // Setup an OAuth consumer
    $oauth = new OAuth($consumer_key,$consumer_secret,OAUTH_SIG_METHOD_HMACSHA1,OAUTH_AUTH_TYPE_AUTHORIZATION);
    // Manually update the access token/secret.  Typically this would be done through an OAuth callback when 
    // authenticating other users.
    $oauth->setToken($access_token,$access_secret);
    // Make a request to the API endpoint
    $oauth->fetch("https://api.tradeking.com/v1/member/profile.json");
    // Handle the response
    $response_info = $oauth->getLastResponseInfo();
    // header("Content-Type: {$response_info["content_type"]}");
    echo $oauth->getLastResponse();
  } catch(OAuthException $E) {
    // Display any errors
    echo "Exception caught!\n";
    echo "Response: ". $E->lastResponse . "\n";
  }
?>
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.