Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3/4TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

C Examples

Web API Categories

ASN.1
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
ECC
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
Geolocation
Google APIs
Google Calendar
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text

HTTP
HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
Microsoft Graph
NTLM
OAuth1
OAuth2
OneDrive
OpenSSL
Outlook
PEM
PFX/P12
POP3
PRNG
REST
REST Misc
RSA Encryption
SCP
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
SharePoint
Socket/SSL/TLS
Spider
Stream
Tar Archive
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl

 

 

 

(C) ETrade - Place Equity Order (JSON version)

Shows how to place an equity order using ETrade with OAuth1 authorization.

See https://developer.etrade.com/ctnt/dev-portal/getDetail?contentUri=V0_Documentation-OrderAPI-PlaceEquityOrder for more information.

Chilkat C/C++ Library Downloads

MS Visual C/C++

Linux/CentOS C/C++

Alpine Linux C/C++

MAC OS X C/C++

armhf/aarch64 C/C++

C++ Builder

iOS C/C++

Android C/C++

Win Mobile 5.0/Pocket PC 2003

Solaris C/C++

FreeBSD C/C++

OpenBSD C/C++

MinGW C/C++

#include <C_CkHttp.h>
#include <C_CkJsonObject.h>
#include <C_CkHttpResponse.h>

void ChilkatSample(void)
    {
    HCkHttp http;
    HCkJsonObject jsonToken;
    BOOL success;
    HCkJsonObject json;
    HCkHttpResponse resp;
    int statusCode;

    //  This example assumes the Chilkat HTTP API to have been previously unlocked.
    //  See HTTP Unlock Sample for sample code.

    http = CkHttp_Create();

    CkHttp_putOAuth1(http,TRUE);
    CkHttp_putOAuthVerifier(http,"");
    CkHttp_putOAuthConsumerKey(http,"ETRADE_CONSUMER_KEY");
    CkHttp_putOAuthConsumerSecret(http,"ETRADE_CONSUMER_SECRET");

    //  Load the access token previously obtained via the OAuth1 3-Legged Authorization
    jsonToken = CkJsonObject_Create();
    success = CkJsonObject_LoadFile(jsonToken,"qa_data/tokens/etrade.json");
    if (success != TRUE) {
        printf("Failed to load OAuth1 token\n");
        CkHttp_Dispose(http);
        CkJsonObject_Dispose(jsonToken);
        return;
    }

    CkHttp_putOAuthToken(http,CkJsonObject_stringOf(jsonToken,"oauth_token"));
    CkHttp_putOAuthTokenSecret(http,CkJsonObject_stringOf(jsonToken,"oauth_token_secret"));

    //  Build the JSON request body
    json = CkJsonObject_Create();
    CkJsonObject_UpdateString(json,"PlaceEquityOrder.-xmlns","http://order.etws.etrade.com");
    //  The accountId should be an 8-digit number such as "83405188"
    CkJsonObject_UpdateString(json,"PlaceEquityOrder.EquityOrderRequest.accountId","MY_ETRADE_ACCOUNT_ID");
    CkJsonObject_UpdateString(json,"PlaceEquityOrder.EquityOrderRequest.clientOrderId","45");
    CkJsonObject_UpdateString(json,"PlaceEquityOrder.EquityOrderRequest.limitPrice","3");
    CkJsonObject_UpdateString(json,"PlaceEquityOrder.EquityOrderRequest.quantity","4");
    CkJsonObject_UpdateString(json,"PlaceEquityOrder.EquityOrderRequest.symbol","ETFC");
    CkJsonObject_UpdateString(json,"PlaceEquityOrder.EquityOrderRequest.orderAction","BUY");
    CkJsonObject_UpdateString(json,"PlaceEquityOrder.EquityOrderRequest.priceType","LIMIT");
    CkJsonObject_UpdateString(json,"PlaceEquityOrder.EquityOrderRequest.marketSession","REGULAR");
    CkJsonObject_UpdateString(json,"PlaceEquityOrder.EquityOrderRequest.orderTerm","GOOD_FOR_DAY");
    CkJsonObject_putEmitCompact(json,FALSE);
    printf("%s\n",CkJsonObject_emit(json));

    //  The above code builds the following JSON:

    //  	{
    //  	  "PlaceEquityOrder": {
    //  	    "-xmlns": "http://order.etws.etrade.com",
    //  	    "EquityOrderRequest": {
    //  	      "accountId": "83405188",
    //  	      "clientOrderId": "45",
    //  	      "limitPrice": "3",
    //  	      "quantity": "4",
    //  	      "symbol": "ETFC",
    //  	      "orderAction": "BUY",
    //  	      "priceType": "LIMIT",
    //  	      "marketSession": "REGULAR",
    //  	      "orderTerm": "GOOD_FOR_DAY"
    //  	    }
    //  	  }
    //  	}

    //  POST the JSON and get the response.
    CkJsonObject_putEmitCompact(json,TRUE);
    //  Set the Accept property to get a JSON response.
    CkHttp_putAccept(http,"application/json");

    //  This example uses the sandbox URL.  The live URL is "https://etws.etrade.com/order/rest/placeequityorder"
    resp = CkHttp_PostJson2(http,"https://etwssandbox.etrade.com/order/sandbox/rest/placeequityorder","application/json",CkJsonObject_emit(json));
    if (CkHttp_getLastMethodSuccess(http) != TRUE) {
        printf("%s\n",CkHttp_lastErrorText(http));
        CkHttp_Dispose(http);
        CkJsonObject_Dispose(jsonToken);
        CkJsonObject_Dispose(json);
        return;
    }

    //  Examine the response status code.
    statusCode = CkHttpResponse_getStatusCode(resp);
    printf("Status Code = %d\n",statusCode);

    //  Load the JSON response body:
    CkJsonObject_Load(json,CkHttpResponse_bodyStr(resp));
    CkJsonObject_putEmitCompact(json,FALSE);

    //  If the status code was not 200, then it was an error..
    if (statusCode != 200) {
        printf("%s\n",CkJsonObject_emit(json));
        printf("Equity order failed.\n");
        CkHttp_Dispose(http);
        CkJsonObject_Dispose(jsonToken);
        CkJsonObject_Dispose(json);
        return;
    }

    printf("%s\n",CkJsonObject_emit(json));
    CkHttpResponse_Dispose(resp);

    //  To examine some information from the JSON:
    printf("quantity: %d\n",CkJsonObject_IntOf(json,"PlaceEquityOrderResponse.EquityOrderResponse.quantity"));
    printf("msgDesc: %s\n",CkJsonObject_stringOf(json,"PlaceEquityOrderResponse.EquityOrderResponse.messageList.msgDesc"));
    //  etc ..

    //  This is a sample response:
    //  	{
    //  	  "PlaceEquityOrderResponse": {
    //  	    "EquityOrderResponse": {
    //  	      "accountId": 83310056,
    //  	      "allOrNone": false,
    //  	      "estimatedCommission": 9.99,
    //  	      "estimatedTotalAmount": 1909.99,
    //  	      "messageList": {
    //  	        "msgDesc": "Your order was successfully entered during market hours.",
    //  	        "msgCode": 1026
    //  	      },
    //  	      "orderNum": 277,
    //  	      "orderTime": 1240982042179,
    //  	      "quantity": 100,
    //  	      "reserveOrder": false,
    //  	      "reserveQuantity": 0,
    //  	      "orderTerm": "GOOD_UNTIL_CANCEL",
    //  	      "limitPrice": 18,
    //  	      "stopPrice": 0,
    //  	      "symbolDesc": "CISCO SYS INC COM",
    //  	      "symbol": "CSCO",
    //  	      "orderAction": "BUY",
    //  	      "priceType": "LIMIT"
    //  	    }
    //  	  }
    //  	}
    // 


    CkHttp_Dispose(http);
    CkJsonObject_Dispose(jsonToken);
    CkJsonObject_Dispose(json);

    }

 

© 2000-2019 Chilkat Software, Inc. All Rights Reserved.