Skip to content

Instantly share code, notes, and snippets.

@JCBarry
Created June 1, 2012 15:41
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save JCBarry/2853042 to your computer and use it in GitHub Desktop.
Save JCBarry/2853042 to your computer and use it in GitHub Desktop.
Tradeking API POST Example using different OAuth library on Google Code
<?php
require_once 'oauth.php';
$consumer_key = '';
$consumer_secret = '';
$access_token = '';
$access_secret = '';
$consumer = new OAuthConsumer($consumer_key,$consumer_secret);
$access = new OAuthToken($access_token,$access_secret);
// $url = 'https://api.tradeking.com/v1/market/ext/quotes.xml';
// $data = "symbols=fb";
$url = 'https://api.tradeking.com/v1/accounts/12345678/orders/preview.xml';
$data = '<?xml version="1.0"?>
<FIXML xmlns="http://www.fixprotocol.org/FIXML-5-0-SP2">
<Order TmInForce="0" Typ="1" Side="1" Acct="12345678">
<Instrmt SecTyp="CS" Sym="F"/>
<OrdQty Qty="1"/>
</Order>
</FIXML>';
$request = OAuthRequest::from_consumer_and_token($consumer, $access, 'POST', $url, OAuthUtil::parse_parameters($data));
$request->sign_request(new OAuthSignatureMethod_HMAC_SHA1(), $consumer, $access);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array($request->to_header()));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
echo $response = curl_exec($ch);
?>
@adityawebespire
Copy link

Hi sir i am Aditya Kumar i am software developer and i have to create a web application for brokers with use of tradeking API but i have sum problem to post request to tradeking api for order place in your example you use a oauth.php file i hope in this file you create own functions for handle this tradeking api my better understanding can you give me that oauth.php file becouse i am using php inbuilt OAuth class and i do not understand how can post order by using inbuilt Oauth class please help me..
my email ID: aditya.webespire@gmail.com
application url: http://trade.mobileitexperts.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment