This package is a wrapper for the TD Ameritrade API. You will need a developer account to use this API.
composer require mackensiealvarezz/tdameritrade-laravel
php artisan vendor:publish
Include these two variables inside of your .env
// .env
TD_KEY="YOUR_KEY"
TD_CALLBACK="CALLBACK"
When using the package, don't forget to include It on top of the file
use Mackensiealvarezz\Tdameritrade\Tdameritrade;
To use the API, the must have an access_token. You can easily create an access token using the redirect function.
To create a OAuth URL, you will need to use:
Tdameritrade::redirectOAuth(); // will return string (url)
It is important that you create a callback route for the URL you set inside of the .env
To refresh the token and create another access_token.
//Create client
$client = Tdameritrade::create($access_token, $refresh_token);
//Refresh token
$response = $client->refreshToken();
The package is written to use every class inside of /src/api as a function.
This will return a list of all the accounts
//Create client
$client = Tdameritrade::create($access_token, $refresh_token);
$accounts = $client->accounts()->list();
This will return all the information for one account. Requires account_id
//Create client
$client = Tdameritrade::create($access_token, $refresh_token);
$accounts = $client->accounts()->get('account_id');
This will return a list of tickers based on the symbol entered
//Create client
$client = Tdameritrade::create($access_token, $refresh_token);
//Response
$response = $client->instruments()->search('TESLA');
This wil return one ticker information
//Create client
$client = Tdameritrade::create($access_token, $refresh_token);
//Response
$accounts = $client->instruments()->get('TSLA');
This will return a list of all the different market hours
//Create client
$client = Tdameritrade::create($access_token, $refresh_token);
//Response
$response = $client->market()->list();
This wil return one market information
//Create client
$client = Tdameritrade::create($access_token, $refresh_token);
//Response
$response = $client->market()->get('SPY.X');
This wil return a list of symbols that are moving
//Create client
$client = Tdameritrade::create($access_token, $refresh_token);
//Response
$response = $client->movers()->get('SPY.X', 'up', 'percent');
This will return a list of quotes for the ticker
//Create client
$client = Tdameritrade::create($access_token, $refresh_token);
//Response
$response = $client->price()->history('TSLA', 'end_date', 'start_date');
This wil return the quote for one ticker
//Create client
$client = Tdameritrade::create($access_token, $refresh_token);
//Response
$response = $client->price()->quote('TSLA');
This wil return the quote for multiple tickers
//Create client
$client = Tdameritrade::create($access_token, $refresh_token);
//Response
$response = $client->price()->quotes(['AAPL', 'FB']);
The MIT License (MIT). Please see MIT license for more information.