Skip to content

A PHP library used to interact with the TD Ameritrade API

License

Notifications You must be signed in to change notification settings

ApopheniaPays/td-ameritrade-api

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

50 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

td-ameritrade-api

Packagist GitHub issues GitHub stars GitHub forks GitHub license

A PHP library used to interact with the TD Ameritrade API

Visit the link below to set up your developer account with TD Ameritrade, and get information on how to authenticate with their API. https://developer.tdameritrade.com/

// How to create a TDAmeritrade API client.
$userName                     = 'joeuser123';
$accessToken                  = 'stringFromTDAmeritradeAuthentication';
$refreshToken                 = 'anotherStringFromTDAmeritradeAuthentication';
$refreshTokenExpiresInSeconds = intFromTDAmeritradeAuthentication;
$debug                        = false;
$tdaClient = TDAmeritradeAPI( $userName,
                              $accessToken,
                              $refreshToken,
                              $refreshTokenExpiresInSeconds,
                              $debug );
// Once you have a client, you can buy stocks at market price.
$accountId = 123456789;
$ticker    = 'LODE';
$quantity  = 1;

try {
   $tdaClient->buyStockSharesMarketPrice($accountId, $ticker, $quantity);
} catch (Exception $exception) {
   echo $exception->getMessage();
}

// Now, log into your TDAmeritrade account online, and you should see a new order.

// To sell some shares at the market price...
try {
   $tdaClient->sellStockSharesMarketPrice($accountId, $ticker, $quantity);
} catch (Exception $exception) {
   echo $exception->getMessage();
}

You can look through the TDAmeritradeAPI.php file for a complete list of the actions I have written code for.

Happy trading!

-Mike

About

A PHP library used to interact with the TD Ameritrade API

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%