Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Unicode C) ETrade Cancel OrderThe cancel order API is used to cancel an existing order. For more information, see https://apisb.etrade.com/docs/api/order/api-order-v1.html#/definition/cancelOrder
#include <C_CkHttpW.h> #include <C_CkJsonObjectW.h> #include <C_CkXmlW.h> #include <C_CkHttpResponseW.h> void ChilkatSample(void) { HCkHttpW http; HCkJsonObjectW jsonToken; BOOL success; const wchar_t *sandboxUrl; const wchar_t *liveUrl; HCkXmlW xml; HCkHttpResponseW resp; int accountId; int orderId; const wchar_t *cancelTime; int code; const wchar_t *description; const wchar_t *v_type; // This requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. http = CkHttpW_Create(); CkHttpW_putOAuth1(http,TRUE); CkHttpW_putOAuthVerifier(http,L""); CkHttpW_putOAuthConsumerKey(http,L"ETRADE_CONSUMER_KEY"); CkHttpW_putOAuthConsumerSecret(http,L"ETRADE_CONSUMER_SECRET"); // Load the access token previously obtained via the OAuth1 Authorization jsonToken = CkJsonObjectW_Create(); success = CkJsonObjectW_LoadFile(jsonToken,L"qa_data/tokens/etrade.json"); if (success != TRUE) { wprintf(L"Failed to load OAuth1 token\n"); CkHttpW_Dispose(http); CkJsonObjectW_Dispose(jsonToken); return; } CkHttpW_putOAuthToken(http,CkJsonObjectW_stringOf(jsonToken,L"oauth_token")); CkHttpW_putOAuthTokenSecret(http,CkJsonObjectW_stringOf(jsonToken,L"oauth_token_secret")); sandboxUrl = L"https://apisb.etrade.com/v1/accounts/{$accountIdKey}/orders/cancel"; liveUrl = L"https://api.etrade.com/v1/accounts/{$accountIdKey}/orders/cancel"; CkHttpW_SetUrlVar(http,L"accountIdKey",L"6_Dpy0rmuQ9cu9IbTfvF2A"); // Send a PUT with the following XML body // Use this online tool to generate the code from sample XML: // Generate Code to Create XML // <CancelOrderRequest> // <orderId>11</orderId> // </CancelOrderRequest> xml = CkXmlW_Create(); CkXmlW_putTag(xml,L"CancelOrderRequest"); CkXmlW_UpdateChildContent(xml,L"orderId",L"11"); CkXmlW_putEmitCompact(xml,TRUE); resp = CkHttpW_PText(http,L"PUT",sandboxUrl,CkXmlW_getXml(xml),L"utf-8",L"application/xml",FALSE,FALSE); if (CkHttpW_getLastMethodSuccess(http) != TRUE) { wprintf(L"%s\n",CkHttpW_lastErrorText(http)); CkHttpW_Dispose(http); CkJsonObjectW_Dispose(jsonToken); CkXmlW_Dispose(xml); return; } // Make sure a successful response was received. if (CkHttpResponseW_getStatusCode(resp) > 200) { wprintf(L"%s\n",CkHttpResponseW_statusLine(resp)); wprintf(L"%s\n",CkHttpResponseW_header(resp)); wprintf(L"%s\n",CkHttpResponseW_bodyStr(resp)); CkHttpW_Dispose(http); CkJsonObjectW_Dispose(jsonToken); CkXmlW_Dispose(xml); return; } // Sample XML response: // Use this online tool to generate parsing code from sample XML: // Generate Parsing Code from XML // <CancelOrderResponse> // <accountId>63438617</accountId> // <orderId>11</orderId> // <cancelTime>1529563499081</cancelTime> // <Messages> // <Message> // <code>5011</code> // <description>200|Your request to cancel your order is being processed.</description> // <type>WARNING</type> // </Message> // </Messages> // </CancelOrderResponse> CkXmlW_LoadXml(xml,CkHttpResponseW_bodyStr(resp)); wprintf(L"%s\n",CkXmlW_getXml(xml)); accountId = CkXmlW_GetChildIntValue(xml,L"accountId"); orderId = CkXmlW_GetChildIntValue(xml,L"orderId"); cancelTime = CkXmlW_getChildContent(xml,L"cancelTime"); code = CkXmlW_GetChildIntValue(xml,L"Messages|Message|code"); description = CkXmlW_getChildContent(xml,L"Messages|Message|description"); v_type = CkXmlW_getChildContent(xml,L"Messages|Message|type"); wprintf(L"Success.\n"); CkHttpW_Dispose(http); CkJsonObjectW_Dispose(jsonToken); CkXmlW_Dispose(xml); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.