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
(PowerBuilder) 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.)
integer li_rc oleobject loo_Http oleobject loo_Json integer li_Success oleobject loo_Xml string ls_XmlContent string ls_EndpointUrl oleobject loo_Resp integer li_StatusCode string ls_TagPath string ls_OrderType string ls_OrderTerm string ls_PriceType string ls_LimitPrice integer li_StopPrice string ls_MarketSession string ls_AllOrNone string ls_Symbol string ls_SecurityType string ls_SymbolDescription string ls_OrderAction string ls_QuantityType integer li_Quantity string ls_CancelQuantity string ls_ReserveOrder string ls_ReserveQuantity integer li_Code string ls_Description string ls_V_type string ls_EgQual string ls_EstimatedCommission string ls_EstimatedTotalAmount integer li_NetPrice integer li_NetBid integer li_NetAsk integer li_Gcd string ls_DstFlag integer li_OptionLevelCd string ls_MarginLevelCd integer li_OrderId string ls_PlacedTime integer li_AccountId // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. loo_Http = create oleobject // Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0 li_rc = loo_Http.ConnectToNewObject("Chilkat.Http") if li_rc < 0 then destroy loo_Http MessageBox("Error","Connecting to COM object failed") return end if loo_Http.OAuth1 = 1 loo_Http.OAuthVerifier = "" loo_Http.OAuthConsumerKey = "ETRADE_CONSUMER_KEY" loo_Http.OAuthConsumerSecret = "ETRADE_CONSUMER_SECRET" // Load the access token previously obtained via the OAuth1 3-Legged Authorization examples Step1 and Step2. loo_Json = create oleobject // Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject") li_Success = loo_Json.LoadFile("qa_data/tokens/etrade.json") if li_Success <> 1 then Write-Debug "Failed to load OAuth1 token" destroy loo_Http destroy loo_Json return end if loo_Http.OAuthToken = loo_Json.StringOf("oauth_token") loo_Http.OAuthTokenSecret = loo_Json.StringOf("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> loo_Xml = create oleobject // Use "Chilkat_9_5_0.Xml" for versions of Chilkat < 10.0.0 li_rc = loo_Xml.ConnectToNewObject("Chilkat.Xml") loo_Xml.Tag = "PlaceOrderRequest" loo_Xml.UpdateChildContent("orderType","EQ") loo_Xml.UpdateChildContent("clientOrderId","sd464333") loo_Xml.UpdateChildContent("PreviewIds|previewId","730206520") loo_Xml.UpdateChildContent("Order|allOrNone","false") loo_Xml.UpdateChildContent("Order|priceType","LIMIT") loo_Xml.UpdateChildContent("Order|orderTerm","GOOD_FOR_DAY") loo_Xml.UpdateChildContent("Order|marketSession","REGULAR") loo_Xml.UpdateChildContent("Order|stopPrice","") loo_Xml.UpdateChildContent("Order|limitPrice","188.51") loo_Xml.UpdateChildContent("Order|Instrument|Product|securityType","EQ") loo_Xml.UpdateChildContent("Order|Instrument|Product|symbol","FB") loo_Xml.UpdateChildContent("Order|Instrument|orderAction","BUY") loo_Xml.UpdateChildContent("Order|Instrument|quantityType","QUANTITY") loo_Xml.UpdateChildContent("Order|Instrument|quantity","150") ls_XmlContent = loo_Xml.GetXml() ls_EndpointUrl = "https://apisb.etrade.com/v1/accounts/{accountIdKey}/orders/place" loo_Resp = loo_Http.PostXml(ls_EndpointUrl,ls_XmlContent,"utf-8") if loo_Http.LastMethodSuccess <> 1 then Write-Debug loo_Http.LastErrorText destroy loo_Http destroy loo_Json destroy loo_Xml return end if // A 200 status code indicates success. li_StatusCode = loo_Resp.StatusCode Write-Debug "statusCode = " + string(li_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... loo_Xml.LoadXml(loo_Resp.BodyStr) destroy loo_Resp ls_OrderType = loo_Xml.GetChildContent("orderType") ls_OrderTerm = loo_Xml.GetChildContent("Order|orderTerm") ls_PriceType = loo_Xml.GetChildContent("Order|priceType") ls_LimitPrice = loo_Xml.GetChildContent("Order|limitPrice") li_StopPrice = loo_Xml.GetChildIntValue("Order|stopPrice") ls_MarketSession = loo_Xml.GetChildContent("Order|marketSession") ls_AllOrNone = loo_Xml.GetChildContent("Order|allOrNone") ls_Symbol = loo_Xml.GetChildContent("Order|Instrument|Product|symbol") ls_SecurityType = loo_Xml.GetChildContent("Order|Instrument|Product|securityType") ls_SymbolDescription = loo_Xml.GetChildContent("Order|Instrument|symbolDescription") ls_OrderAction = loo_Xml.GetChildContent("Order|Instrument|orderAction") ls_QuantityType = loo_Xml.GetChildContent("Order|Instrument|quantityType") li_Quantity = loo_Xml.GetChildIntValue("Order|Instrument|quantity") ls_CancelQuantity = loo_Xml.GetChildContent("Order|Instrument|cancelQuantity") ls_ReserveOrder = loo_Xml.GetChildContent("Order|Instrument|reserveOrder") ls_ReserveQuantity = loo_Xml.GetChildContent("Order|Instrument|reserveQuantity") li_Code = loo_Xml.GetChildIntValue("Order|messages|Message|code") ls_Description = loo_Xml.GetChildContent("Order|messages|Message|description") ls_V_type = loo_Xml.GetChildContent("Order|messages|Message|type") ls_EgQual = loo_Xml.GetChildContent("Order|egQual") ls_EstimatedCommission = loo_Xml.GetChildContent("Order|estimatedCommission") ls_EstimatedTotalAmount = loo_Xml.GetChildContent("Order|estimatedTotalAmount") li_NetPrice = loo_Xml.GetChildIntValue("Order|netPrice") li_NetBid = loo_Xml.GetChildIntValue("Order|netBid") li_NetAsk = loo_Xml.GetChildIntValue("Order|netAsk") li_Gcd = loo_Xml.GetChildIntValue("Order|gcd") ls_DstFlag = loo_Xml.GetChildContent("dstFlag") li_OptionLevelCd = loo_Xml.GetChildIntValue("optionLevelCd") ls_MarginLevelCd = loo_Xml.GetChildContent("marginLevelCd") li_OrderId = loo_Xml.GetChildIntValue("OrderIds|orderId") ls_PlacedTime = loo_Xml.GetChildContent("placedTime") li_AccountId = loo_Xml.GetChildIntValue("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 destroy loo_Http destroy loo_Json destroy loo_Xml |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.