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 v1 Place OrderSubmits an order after it has been successfully previewed. (Your application must first send the POST to preview the order. Then it can send this POST to place the order.)
#include <C_CkHttpW.h> #include <C_CkJsonObjectW.h> #include <C_CkXmlW.h> #include <C_CkHttpResponseW.h> void ChilkatSample(void) { HCkHttpW http; HCkJsonObjectW json; BOOL success; HCkXmlW xml; const wchar_t *xmlContent; const wchar_t *endpointUrl; HCkHttpResponseW resp; int statusCode; const wchar_t *tagPath; const wchar_t *orderType; const wchar_t *orderTerm; const wchar_t *priceType; const wchar_t *limitPrice; int stopPrice; const wchar_t *marketSession; const wchar_t *allOrNone; const wchar_t *symbol; const wchar_t *securityType; const wchar_t *symbolDescription; const wchar_t *orderAction; const wchar_t *quantityType; int quantity; const wchar_t *cancelQuantity; const wchar_t *reserveOrder; const wchar_t *reserveQuantity; int code; const wchar_t *description; const wchar_t *v_type; const wchar_t *egQual; const wchar_t *estimatedCommission; const wchar_t *estimatedTotalAmount; int netPrice; int netBid; int netAsk; int gcd; const wchar_t *dstFlag; int optionLevelCd; const wchar_t *marginLevelCd; int orderId; const wchar_t *placedTime; int accountId; // This example 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 3-Legged Authorization examples Step1 and Step2. json = CkJsonObjectW_Create(); success = CkJsonObjectW_LoadFile(json,L"qa_data/tokens/etrade.json"); if (success != TRUE) { wprintf(L"Failed to load OAuth1 token\n"); CkHttpW_Dispose(http); CkJsonObjectW_Dispose(json); return; } CkHttpW_putOAuthToken(http,CkJsonObjectW_stringOf(json,L"oauth_token")); CkHttpW_putOAuthTokenSecret(http,CkJsonObjectW_stringOf(json,L"oauth_token_secret")); // See the ETrade v1 API documentation HERE. // Sample XML Request // Use this online tool to generate the code from sample XML: // Generate Code to Create XML // <?xml version="1.0" encoding="UTF-8"?> // <PlaceOrderRequest> // <orderType>EQ</orderType> // <clientOrderId>sd464333</clientOrderId> // <PreviewIds> // <previewId>730206520</previewId> // </PreviewIds> // <Order> // <allOrNone>false</allOrNone> // <priceType>LIMIT</priceType> // <orderTerm>GOOD_FOR_DAY</orderTerm> // <marketSession>REGULAR</marketSession> // <stopPrice /> // <limitPrice>188.51</limitPrice> // <Instrument> // <Product> // <securityType>EQ</securityType> // <symbol>FB</symbol> // </Product> // <orderAction>BUY</orderAction> // <quantityType>QUANTITY</quantityType> // <quantity>150</quantity> // </Instrument> // </Order> // </PlaceOrderRequest> xml = CkXmlW_Create(); CkXmlW_putTag(xml,L"PlaceOrderRequest"); CkXmlW_UpdateChildContent(xml,L"orderType",L"EQ"); CkXmlW_UpdateChildContent(xml,L"clientOrderId",L"sd464333"); CkXmlW_UpdateChildContent(xml,L"PreviewIds|previewId",L"730206520"); CkXmlW_UpdateChildContent(xml,L"Order|allOrNone",L"false"); CkXmlW_UpdateChildContent(xml,L"Order|priceType",L"LIMIT"); CkXmlW_UpdateChildContent(xml,L"Order|orderTerm",L"GOOD_FOR_DAY"); CkXmlW_UpdateChildContent(xml,L"Order|marketSession",L"REGULAR"); CkXmlW_UpdateChildContent(xml,L"Order|stopPrice",L""); CkXmlW_UpdateChildContent(xml,L"Order|limitPrice",L"188.51"); CkXmlW_UpdateChildContent(xml,L"Order|Instrument|Product|securityType",L"EQ"); CkXmlW_UpdateChildContent(xml,L"Order|Instrument|Product|symbol",L"FB"); CkXmlW_UpdateChildContent(xml,L"Order|Instrument|orderAction",L"BUY"); CkXmlW_UpdateChildContent(xml,L"Order|Instrument|quantityType",L"QUANTITY"); CkXmlW_UpdateChildContent(xml,L"Order|Instrument|quantity",L"150"); xmlContent = CkXmlW_getXml(xml); endpointUrl = L"https://apisb.etrade.com/v1/accounts/{accountIdKey}/orders/place"; resp = CkHttpW_PostXml(http,endpointUrl,xmlContent,L"utf-8"); if (CkHttpW_getLastMethodSuccess(http) != TRUE) { wprintf(L"%s\n",CkHttpW_lastErrorText(http)); CkHttpW_Dispose(http); CkJsonObjectW_Dispose(json); CkXmlW_Dispose(xml); return; } // A 200 status code indicates success. statusCode = CkHttpResponseW_getStatusCode(resp); wprintf(L"statusCode = %d\n",statusCode); // Use the following online tool to generate parsing code from sample XML: // Generate Parsing Code from XML // A sample XML response is shown below... CkXmlW_LoadXml(xml,CkHttpResponseW_bodyStr(resp)); CkHttpResponseW_Dispose(resp); orderType = CkXmlW_getChildContent(xml,L"orderType"); orderTerm = CkXmlW_getChildContent(xml,L"Order|orderTerm"); priceType = CkXmlW_getChildContent(xml,L"Order|priceType"); limitPrice = CkXmlW_getChildContent(xml,L"Order|limitPrice"); stopPrice = CkXmlW_GetChildIntValue(xml,L"Order|stopPrice"); marketSession = CkXmlW_getChildContent(xml,L"Order|marketSession"); allOrNone = CkXmlW_getChildContent(xml,L"Order|allOrNone"); symbol = CkXmlW_getChildContent(xml,L"Order|Instrument|Product|symbol"); securityType = CkXmlW_getChildContent(xml,L"Order|Instrument|Product|securityType"); symbolDescription = CkXmlW_getChildContent(xml,L"Order|Instrument|symbolDescription"); orderAction = CkXmlW_getChildContent(xml,L"Order|Instrument|orderAction"); quantityType = CkXmlW_getChildContent(xml,L"Order|Instrument|quantityType"); quantity = CkXmlW_GetChildIntValue(xml,L"Order|Instrument|quantity"); cancelQuantity = CkXmlW_getChildContent(xml,L"Order|Instrument|cancelQuantity"); reserveOrder = CkXmlW_getChildContent(xml,L"Order|Instrument|reserveOrder"); reserveQuantity = CkXmlW_getChildContent(xml,L"Order|Instrument|reserveQuantity"); code = CkXmlW_GetChildIntValue(xml,L"Order|messages|Message|code"); description = CkXmlW_getChildContent(xml,L"Order|messages|Message|description"); v_type = CkXmlW_getChildContent(xml,L"Order|messages|Message|type"); egQual = CkXmlW_getChildContent(xml,L"Order|egQual"); estimatedCommission = CkXmlW_getChildContent(xml,L"Order|estimatedCommission"); estimatedTotalAmount = CkXmlW_getChildContent(xml,L"Order|estimatedTotalAmount"); netPrice = CkXmlW_GetChildIntValue(xml,L"Order|netPrice"); netBid = CkXmlW_GetChildIntValue(xml,L"Order|netBid"); netAsk = CkXmlW_GetChildIntValue(xml,L"Order|netAsk"); gcd = CkXmlW_GetChildIntValue(xml,L"Order|gcd"); dstFlag = CkXmlW_getChildContent(xml,L"dstFlag"); optionLevelCd = CkXmlW_GetChildIntValue(xml,L"optionLevelCd"); marginLevelCd = CkXmlW_getChildContent(xml,L"marginLevelCd"); orderId = CkXmlW_GetChildIntValue(xml,L"OrderIds|orderId"); placedTime = CkXmlW_getChildContent(xml,L"placedTime"); accountId = CkXmlW_GetChildIntValue(xml,L"accountId"); // Sample XML Response // <?xml version="1.0" encoding="UTF-8"?> // <PlaceOrderResponse> // <orderType>EQ</orderType> // <Order> // <orderTerm>GOOD_FOR_DAY</orderTerm> // <priceType>LIMIT</priceType> // <limitPrice>188.51</limitPrice> // <stopPrice>0</stopPrice> // <marketSession>REGULAR</marketSession> // <allOrNone>false</allOrNone> // <Instrument> // <Product> // <symbol>FB</symbol> // <securityType>EQ</securityType> // </Product> // <symbolDescription>FACEBOOK INC CL A</symbolDescription> // <orderAction>BUY</orderAction> // <quantityType>QUANTITY</quantityType> // <quantity>150</quantity> // <cancelQuantity>0.0</cancelQuantity> // <reserveOrder>true</reserveOrder> // <reserveQuantity>0.0</reserveQuantity> // </Instrument> // <messages> // <Message> // <code>1027</code> // <description>200|The market was closed when we received your order. It has been entered into our system and will be reviewed prior to market open on the next regular trading day. After market open, please check to make sure your order was accepted.</description> // <type>WARNING</type> // </Message> // </messages> // <egQual>EG_QUAL_NOT_A_MARKET_ORDER</egQual> // <estimatedCommission>6.95</estimatedCommission> // <estimatedTotalAmount>28283.45</estimatedTotalAmount> // <netPrice>0</netPrice> // <netBid>0</netBid> // <netAsk>0</netAsk> // <gcd>0</gcd> // <ratio /> // </Order> // <dstFlag>true</dstFlag> // <optionLevelCd>4</optionLevelCd> // <marginLevelCd>MARGIN_TRADING_ALLOWED</marginLevelCd> // <OrderIds> // <orderId>5</orderId> // </OrderIds> // <placedTime>1528764717641</placedTime> // <accountId>84312767</accountId> // </PlaceOrderResponse CkHttpW_Dispose(http); CkJsonObjectW_Dispose(json); CkXmlW_Dispose(xml); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.