1. Go to this page and download the library: Download zechdc/oauth1-etrade library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?phprequire_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
zechdc / oauth1-etrade example snippets
//Step 1, setup an Etrade instance
$server = new Zechdc\OAuth1\Client\Server\Etrade(array(
'identifier' => 'oauth_customer_key',
'secret' => 'consumer_secret',
));
//Step 2, get create your Request Token ($temporaryCredentials)publicfunctiongetRequestTokenAndAuthorizeApplication(){
//This creates your Request Token
$temporaryCredentials = $this->server->getTemporaryCredentials();
//Save the $temporaryCredentials in a session or DB to be used later.
Session::set('temporary_credentials', $temporaryCredentials);
//This will allow the user to Authorize your Application. It will redirect the user//to etrade. After they login and accept your application, it will either// 1) Redirect to your website - this erifier);//Save the Access Token so we can make and authorize more API calls.
Session::set('token_credentials', $tokenCredentials);
}
//Step 4, now that you have your Access Token, lets call an endpointpublicfunctiongetMarketData(){
$client = new Guzzle\Client();
$accessToken = Session::get('token_credentials');
$url = "https://etwssandbox.etrade.com/market/sandbox/rest/quote/GOOGL.json";
$method = 'GET';
$params = ['detailFlag' => 'FUNDAMENTAL'];
//This constructs our Authorization header and the oauth signature.
$headers = $this->server->getHeaders($accessToken, $method, $url, $params);
$res = $client->request($method, $url, [
'headers' => $headers,
'query' => $params
]);
echo $res->getStatusCode();
echo $res->getBody();
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.