private static void whatIfSamples(EClientSocket client, int nextOrderId) { /*** Placing what-if order ***/ //! [whatiforder] client.placeOrder(nextOrderId++, ContractSamples.USStockAtSmart(), OrderSamples.WhatIfLimitOrder("BUY", 200, 120)); //! [whatiforder] }
private static void ConditionSamples(EClientSocket client, int nextOrderId) { //! [order_conditioning_activate] Order mkt = OrderSamples.MarketOrder("BUY", 100); //Order will become active if conditioning criteria is met mkt.ConditionsCancelOrder = true; mkt.Conditions.Add(OrderSamples.PriceCondition(208813720, "SMART", 600, false, false)); mkt.Conditions.Add(OrderSamples.ExecutionCondition("EUR.USD", "CASH", "IDEALPRO", true)); mkt.Conditions.Add(OrderSamples.MarginCondition(30, true, false)); mkt.Conditions.Add(OrderSamples.PercentageChangeCondition(15.0, 208813720, "SMART", true, true)); mkt.Conditions.Add(OrderSamples.TimeCondition("20160118 23:59:59", true, false)); mkt.Conditions.Add(OrderSamples.VolumeCondition(208813720, "SMART", false, 100, true)); client.placeOrder(nextOrderId++, ContractSamples.EuropeanStock(), mkt); //! [order_conditioning_activate] //Conditions can make the order active or cancel it. Only LMT orders can be conditionally canceled. //! [order_conditioning_cancel] Order lmt = OrderSamples.LimitOrder("BUY", 100, 20); //The active order will be cancelled if conditioning criteria is met lmt.ConditionsCancelOrder = true; lmt.Conditions.Add(OrderSamples.PriceCondition(208813720, "SMART", 600, false, false)); client.placeOrder(nextOrderId++, ContractSamples.EuropeanStock(), lmt); //! [order_conditioning_cancel] }
private static void TestAlgoSamples(EClientSocket client, int nextOrderId) { //! [algo_base_order] Order baseOrder = OrderSamples.LimitOrder("BUY", 1000, 1); //! [algo_base_order] //! [arrivalpx] AvailableAlgoParams.FillArrivalPriceParams(baseOrder, 0.1, "Aggressive", "09:00:00 CET", "16:00:00 CET", true, true); client.placeOrder(nextOrderId++, ContractSamples.USStockAtSmart(), baseOrder); //! [arrivalpx] Thread.Sleep(500); //! [darkice] AvailableAlgoParams.FillDarkIceParams(baseOrder, 10, "09:00:00 CET", "16:00:00 CET", true); client.placeOrder(nextOrderId++, ContractSamples.USStockAtSmart(), baseOrder); //! [darkice] Thread.Sleep(500); //! [ad] AvailableAlgoParams.FillAccumulateDistributeParams(baseOrder, 10, 60, true, true, 1, true, true, "09:00:00 CET", "16:00:00 CET"); client.placeOrder(nextOrderId++, ContractSamples.USStockAtSmart(), baseOrder); //! [ad] Thread.Sleep(500); //! [twap] AvailableAlgoParams.FillTwapParams(baseOrder, "Marketable", "09:00:00 CET", "16:00:00 CET", true); client.placeOrder(nextOrderId++, ContractSamples.USStockAtSmart(), baseOrder); //! [twap] Thread.Sleep(500); //! [vwap] AvailableAlgoParams.FillVwapParams(baseOrder, 0.2, "09:00:00 CET", "16:00:00 CET", true, true); client.placeOrder(nextOrderId++, ContractSamples.USStockAtSmart(), baseOrder); //! [vwap] Thread.Sleep(500); //! [balanceimpactrisk] AvailableAlgoParams.FillBalanceImpactRiskParams(baseOrder, 0.1, "Aggressive", true); client.placeOrder(nextOrderId++, ContractSamples.USOptionContract(), baseOrder); //! [balanceimpactrisk] Thread.Sleep(500); //! [minimpact] AvailableAlgoParams.FillMinImpactParams(baseOrder, 0.3); client.placeOrder(nextOrderId++, ContractSamples.USOptionContract(), baseOrder); //! [minimpact] //! [adaptive] AvailableAlgoParams.FillAdaptiveParams(baseOrder, "Normal"); client.placeOrder(nextOrderId++, ContractSamples.USStockAtSmart(), baseOrder); //! [adaptive] }
private static void BracketSample(EClientSocket client, int nextOrderId) { //BRACKET ORDER //! [bracketsubmit] List <Order> bracket = OrderSamples.BracketOrder(nextOrderId++, "BUY", 100, 30, 40, 20); foreach (Order o in bracket) { client.placeOrder(o.OrderId, ContractSamples.EuropeanStock(), o); } //! [bracketsubmit] }
private static void OcaSample(EClientSocket client, int nextOrderId) { //OCA ORDER //! [ocasubmit] List <Order> ocaOrders = new List <Order>(); ocaOrders.Add(OrderSamples.LimitOrder("BUY", 1, 10)); ocaOrders.Add(OrderSamples.LimitOrder("BUY", 1, 11)); ocaOrders.Add(OrderSamples.LimitOrder("BUY", 1, 12)); OrderSamples.OneCancelsAll("TestOCA_" + nextOrderId, ocaOrders, 2); foreach (Order o in ocaOrders) { client.placeOrder(nextOrderId++, ContractSamples.USStock(), o); } //! [ocasubmit] }
private static void HedgeSample(EClientSocket client, int nextOrderId) { //F Hedge order //! [hedgesubmit] //Parent order on a contract which currency differs from your base currency Order parent = OrderSamples.LimitOrder("BUY", 100, 10); parent.OrderId = nextOrderId++; //Hedge on the currency conversion Order hedge = OrderSamples.MarketFHedge(parent.OrderId, "BUY"); //Place the parent first... client.placeOrder(parent.OrderId, ContractSamples.EuropeanStock(), parent); //Then the hedge order client.placeOrder(nextOrderId++, ContractSamples.EurGbpFx(), hedge); //! [hedgesubmit] }
private static void TestAlgoSamples(EClientSocket client, int nextOrderId) { //! [algo_base_order] Order baseOrder = OrderSamples.LimitOrder("BUY", 1000, 1); //! [algo_base_order] //! [arrivalpx] AvailableAlgoParams.FillArrivalPriceParams(baseOrder, 0.1, "Aggressive", "09:00:00 CET", "16:00:00 CET", true, true, 100000); client.placeOrder(nextOrderId++, ContractSamples.USStockAtSmart(), baseOrder); //! [arrivalpx] Thread.Sleep(500); //! [darkice] AvailableAlgoParams.FillDarkIceParams(baseOrder, 10, "09:00:00 CET", "16:00:00 CET", true, 100000); client.placeOrder(nextOrderId++, ContractSamples.USStockAtSmart(), baseOrder); //! [darkice] Thread.Sleep(500); //! [ad] // The Time Zone in "startTime" and "endTime" attributes is ignored and always defaulted to GMT AvailableAlgoParams.FillAccumulateDistributeParams(baseOrder, 10, 60, true, true, 1, true, true, "20161010-12:00:00 GMT", "20161010-16:00:00 GMT"); client.placeOrder(nextOrderId++, ContractSamples.USStockAtSmart(), baseOrder); //! [ad] Thread.Sleep(500); //! [twap] AvailableAlgoParams.FillTwapParams(baseOrder, "Marketable", "09:00:00 CET", "16:00:00 CET", true, 100000); client.placeOrder(nextOrderId++, ContractSamples.USStockAtSmart(), baseOrder); //! [twap] Thread.Sleep(500); //! [vwap] AvailableAlgoParams.FillVwapParams(baseOrder, 0.2, "09:00:00 CET", "16:00:00 CET", true, true, true, 100000); client.placeOrder(nextOrderId++, ContractSamples.USStockAtSmart(), baseOrder); //! [vwap] Thread.Sleep(500); //! [balanceimpactrisk] AvailableAlgoParams.FillBalanceImpactRiskParams(baseOrder, 0.1, "Aggressive", true); client.placeOrder(nextOrderId++, ContractSamples.USOptionContract(), baseOrder); //! [balanceimpactrisk] Thread.Sleep(500); //! [minimpact] AvailableAlgoParams.FillMinImpactParams(baseOrder, 0.3); client.placeOrder(nextOrderId++, ContractSamples.USOptionContract(), baseOrder); //! [minimpact] //! [adaptive] AvailableAlgoParams.FillAdaptiveParams(baseOrder, "Normal"); client.placeOrder(nextOrderId++, ContractSamples.USStockAtSmart(), baseOrder); //! [adaptive] //! [closepx] AvailableAlgoParams.FillClosePriceParams(baseOrder, 0.5, "Neutral", "12:00:00 EST", true, 100000); client.placeOrder(nextOrderId++, ContractSamples.USStockAtSmart(), baseOrder); //! [closepx] //! [pctvol] AvailableAlgoParams.FillPctVolParams(baseOrder, 0.5, "12:00:00 EST", "14:00:00 EST", true, 100000); client.placeOrder(nextOrderId++, ContractSamples.USStockAtSmart(), baseOrder); //! [pctvol] //! [pctvolpx] AvailableAlgoParams.FillPriceVariantPctVolParams(baseOrder, 0.1, 0.05, 0.01, 0.2, "12:00:00 EST", "14:00:00 EST", true, 100000); client.placeOrder(nextOrderId++, ContractSamples.USStockAtSmart(), baseOrder); //! [pctvolpx] //! [pctvolsz] AvailableAlgoParams.FillSizeVariantPctVolParams(baseOrder, 0.2, 0.4, "12:00:00 EST", "14:00:00 EST", true, 100000); client.placeOrder(nextOrderId++, ContractSamples.USStockAtSmart(), baseOrder); //! [pctvolsz] //! [pctvoltm] AvailableAlgoParams.FillTimeVariantPctVolParams(baseOrder, 0.2, 0.4, "12:00:00 EST", "14:00:00 EST", true, 100000); client.placeOrder(nextOrderId++, ContractSamples.USStockAtSmart(), baseOrder); //! [pctvoltm] //! [jeff_vwap_algo] AvailableAlgoParams.FillJefferiesVWAPParams(baseOrder, "10:00:00 EST", "16:00:00 EST", 10, 10, "Exclude_Both", 130, 135, 1, 10, "Patience", false, "Midpoint"); client.placeOrder(nextOrderId++, ContractSamples.JefferiesContract(), baseOrder); //! [jeff_vwap_algo] //! [csfb_inline_algo] AvailableAlgoParams.FillCSFBInlineParams(baseOrder, "10:00:00 EST", "16:00:00 EST", "Patient", 10, 20, 100, "Default", false, 40, 100, 100, 35); client.placeOrder(nextOrderId++, ContractSamples.CSFBContract(), baseOrder); //! [csfb_inline_algo] }
private static void orderOperations(EClientSocket client, int nextOrderId) { /*** Requesting the next valid id ***/ //! [reqids] //The parameter is always ignored. client.reqIds(-1); //! [reqids] //Thread.Sleep(1000); /*** Requesting all open orders ***/ //! [reqallopenorders] client.reqAllOpenOrders(); //! [reqallopenorders] //Thread.Sleep(1000); /*** Taking over orders to be submitted via TWS ***/ //! [reqautoopenorders] client.reqAutoOpenOrders(true); //! [reqautoopenorders] //Thread.Sleep(1000); /*** Requesting this API client's orders ***/ //! [reqopenorders] client.reqOpenOrders(); //! [reqopenorders] //Thread.Sleep(1000); //BracketSample(client, nextOrderId); /*** Placing/modifying an order - remember to ALWAYS increment the nextValidId after placing an order so it can be used for the next one! * Note if there are multiple clients connected to an account, the order ID must also be greater than all order IDs returned for orders to orderStatus and openOrder to this client. ***/ //! [order_submission] client.placeOrder(nextOrderId++, ContractSamples.USStock(), OrderSamples.TrailingStopLimit("BUY", 1, 5, 5, 110)); //! [order_submission] //! [faorderoneaccount] Order faOrderOneAccount = OrderSamples.MarketOrder("BUY", 100); // Specify the Account Number directly faOrderOneAccount.Account = "DU119915"; client.placeOrder(nextOrderId++, ContractSamples.USStock(), faOrderOneAccount); //! [faorderoneaccount] //! [faordergroupequalquantity] Order faOrderGroupEQ = OrderSamples.LimitOrder("SELL", 200, 2000); faOrderGroupEQ.FaGroup = "Group_Equal_Quantity"; faOrderGroupEQ.FaMethod = "EqualQuantity"; client.placeOrder(nextOrderId++, ContractSamples.SimpleFuture(), faOrderGroupEQ); //! [faordergroupequalquantity] //! [faordergrouppctchange] Order faOrderGroupPC = OrderSamples.MarketOrder("BUY", 0);; // You should not specify any order quantity for PctChange allocation method faOrderGroupPC.FaGroup = "Pct_Change"; faOrderGroupPC.FaMethod = "PctChange"; faOrderGroupPC.FaPercentage = "100"; client.placeOrder(nextOrderId++, ContractSamples.EurGbpFx(), faOrderGroupPC); //! [faordergrouppctchange] //! [faorderprofile] Order faOrderProfile = OrderSamples.LimitOrder("BUY", 200, 100); faOrderProfile.FaProfile = "Percent_60_40"; client.placeOrder(nextOrderId++, ContractSamples.EuropeanStock(), faOrderProfile); //! [faorderprofile] //! [modelorder] Order modelOrder = OrderSamples.LimitOrder("BUY", 200, 100); modelOrder.Account = "DF12345"; // master FA account number modelOrder.ModelCode = "Technology"; // model for tech stocks first created in TWS client.placeOrder(nextOrderId++, ContractSamples.USStock(), modelOrder); //! [modelorder] //client.placeOrder(nextOrderId++, ContractSamples.OptionAtBOX(), OrderSamples.Block("BUY", 50, 20)); //client.placeOrder(nextOrderId++, ContractSamples.OptionAtBOX(), OrderSamples.BoxTop("SELL", 10)); //client.placeOrder(nextOrderId++, ContractSamples.FutureComboContract(), OrderSamples.ComboLimitOrder("SELL", 1, 1, false)); //client.placeOrder(nextOrderId++, ContractSamples.StockComboContract(), OrderSamples.ComboMarketOrder("BUY", 1, true)); //client.placeOrder(nextOrderId++, ContractSamples.OptionComboContract(), OrderSamples.ComboMarketOrder("BUY", 1, false)); //client.placeOrder(nextOrderId++, ContractSamples.StockComboContract(), OrderSamples.LimitOrderForComboWithLegPrices("BUY", 1, new double[]{10, 5}, true)); //client.placeOrder(nextOrderId++, ContractSamples.USStock(), OrderSamples.Discretionary("SELL", 1, 45, 0.5)); //client.placeOrder(nextOrderId++, ContractSamples.OptionAtBOX(), OrderSamples.LimitIfTouched("BUY", 1, 30, 34)); //client.placeOrder(nextOrderId++, ContractSamples.USStock(), OrderSamples.LimitOnClose("SELL", 1, 34)); //client.placeOrder(nextOrderId++, ContractSamples.USStock(), OrderSamples.LimitOnOpen("BUY", 1, 35)); //client.placeOrder(nextOrderId++, ContractSamples.USStock(), OrderSamples.MarketIfTouched("BUY", 1, 30)); //client.placeOrder(nextOrderId++, ContractSamples.USStock(), OrderSamples.MarketOnClose("SELL", 1)); //client.placeOrder(nextOrderId++, ContractSamples.USStock(), OrderSamples.MarketOnOpen("BUY", 1)); //client.placeOrder(nextOrderId++, ContractSamples.USStock(), OrderSamples.MarketOrder("SELL", 1)); //client.placeOrder(nextOrderId++, ContractSamples.USStock(), OrderSamples.MarketToLimit("BUY", 1)); //client.placeOrder(nextOrderId++, ContractSamples.OptionAtIse(), OrderSamples.MidpointMatch("BUY", 1)); //client.placeOrder(nextOrderId++, ContractSamples.USStock(), OrderSamples.MarketToLimit("BUY", 1)); //client.placeOrder(nextOrderId++, ContractSamples.USStock(), OrderSamples.Stop("SELL", 1, 34.4)); //client.placeOrder(nextOrderId++, ContractSamples.USStock(), OrderSamples.StopLimit("BUY", 1, 35, 33)); //client.placeOrder(nextOrderId++, ContractSamples.USStock(), OrderSamples.StopWithProtection("SELL", 1, 45)); //client.placeOrder(nextOrderId++, ContractSamples.USStock(), OrderSamples.SweepToFill("BUY", 1, 35)); //client.placeOrder(nextOrderId++, ContractSamples.USStock(), OrderSamples.TrailingStop("SELL", 1, 0.5, 30)); //client.placeOrder(nextOrderId++, ContractSamples.USStock(), OrderSamples.TrailingStopLimit("BUY", 1, 2, 5, 50)); //client.placeOrder(nextOrderId++, ContractSamples.NormalOption(), OrderSamples.Volatility("SELL", 1, 5, 2)); //NOTE: the following orders are not supported for Paper Trading //client.placeOrder(nextOrderId++, ContractSamples.USStock(), OrderSamples.AtAuction("BUY", 100, 30.0)); //client.placeOrder(nextOrderId++, ContractSamples.OptionAtBOX(), OrderSamples.AuctionLimit("SELL", 10, 30.0, 2)); //client.placeOrder(nextOrderId++, ContractSamples.OptionAtBOX(), OrderSamples.AuctionPeggedToStock("BUY", 10, 30, 0.5)); //client.placeOrder(nextOrderId++, ContractSamples.OptionAtBOX(), OrderSamples.AuctionRelative("SELL", 10, 0.6)); //client.placeOrder(nextOrderId++, ContractSamples.SimpleFuture(), OrderSamples.MarketWithProtection("BUY", 1)); //client.placeOrder(nextOrderId++, ContractSamples.USStock(), OrderSamples.PassiveRelative("BUY", 1, 0.5)); //208813720 (GOOG) //client.placeOrder(nextOrderId++, ContractSamples.USStock(), // OrderSamples.PeggedToBenchmark("SELL", 100, 33, true, 0.1, 1, 208813720, "ISLAND", 750, 650, 800)); //STOP ADJUSTABLE ORDERS //Order stpParent = OrderSamples.Stop("SELL", 100, 30); //stpParent.OrderId = nextOrderId++; //client.placeOrder(stpParent.OrderId, ContractSamples.EuropeanStock(), stpParent); //client.placeOrder(nextOrderId++, ContractSamples.EuropeanStock(), OrderSamples.AttachAdjustableToStop(stpParent, 35, 32, 33)); //client.placeOrder(nextOrderId++, ContractSamples.EuropeanStock(), OrderSamples.AttachAdjustableToStopLimit(stpParent, 35, 33, 32, 33)); //client.placeOrder(nextOrderId++, ContractSamples.EuropeanStock(), OrderSamples.AttachAdjustableToTrail(stpParent, 35, 32, 32, 1, 0)); //Order lmtParent = OrderSamples.LimitOrder("BUY", 100, 30); //lmtParent.OrderId = nextOrderId++; //client.placeOrder(lmtParent.OrderId, ContractSamples.EuropeanStock(), lmtParent); //Attached TRAIL adjusted can only be attached to LMT parent orders. //client.placeOrder(nextOrderId++, ContractSamples.EuropeanStock(), OrderSamples.AttachAdjustableToTrailAmount(lmtParent, 34, 32, 33, 0.008)); //TestAlgoSamples(client, nextOrderId); //Thread.Sleep(30000); //! [cancelorder] client.cancelOrder(nextOrderId - 1); //! [cancelorder] /*** Cancel all orders for all accounts ***/ //! [reqglobalcancel] client.reqGlobalCancel(); //! [reqglobalcancel] /*** Request the day's executions ***/ //! [reqexecutions] client.reqExecutions(10001, new ExecutionFilter()); //! [reqexecutions] }
private static void testConnectDisconnect(EWrapperImpl wrapper) { //Order order = OrderSamples.LimitOrder(); //Contract contract = ContractSamples.getOption(); //wrapper.ClientSocket.reqMktData(1, ContractSamples.getOption(), "", false); //wrapper.ClientSocket.reqMktData(3, ContractSamples.getEuropeanStock(), "", false); //wrapper.ClientSocket.reqGlobalCancel(); //wrapper.ClientSocket.reqCurrentTime(); //wrapper.ClientSocket.reqMktData(1, ContractSamples.getForex(), "", false); //wrapper.ClientSocket.calculateImpliedVolatility(2, ContractSamples.getOption(), 10, 345); //wrapper.ClientSocket.calculateOptionPrice(3, ContractSamples.getOption(), 4.69, 345); //wrapper.ClientSocket.reqAccountSummary(1, "All", AccountSummaryTags.GetAllTags()); //wrapper.ClientSocket.reqAccountUpdates(true, "DU150462"); //wrapper.ClientSocket.reqAllOpenOrders(); //wrapper.ClientSocket.reqAutoOpenOrders(true); //wrapper.ClientSocket.reqOpenOrders(); //wrapper.ClientSocket.placeOrder(wrapper.NextOrderId, ContractSamples.getForex(), order); wrapper.ClientSocket.placeOrder(wrapper.NextOrderId, ContractSamples.getComboContract(), OrderSamples.LimitOrderForComboWithLegPrice()); //wrapper.ClientSocket.reqContractDetails(1, ContractSamples.getForex()); //wrapper.ClientSocket.reqExecutions(1, new ExecutionFilter()); //wrapper.ClientSocket.reqMktData(2, ContractSamples.getForex(), "", false); //wrapper.ClientSocket.reqFundamentalData(1, ContractSamples.getEuropeanStock(), "snapshot"); //wrapper.ClientSocket.reqHistoricalData(1, ContractSamples.getEurUsdForex(), "20130722 23:59:59", "1 D", "1 hour", "MIDPOINT", 1, 1); //wrapper.ClientSocket.cancelHistoricalData(1); //wrapper.ClientSocket.reqFundamentalData(2, ContractSamples.getEuropeanStock(), "snapshot"); //wrapper.ClientSocket.reqIds(-1); //wrapper.ClientSocket.reqManagedAccts(); //wrapper.ClientSocket.reqMarketDataType(1); //wrapper.ClientSocket.reqMarketDepth(1, ContractSamples.getForex(), 5); //wrapper.ClientSocket.reqNewsBulletins(true); //wrapper.ClientSocket.reqPositions(); //wrapper.ClientSocket.reqRealTimeBars(1, ContractSamples.getForex(), -1, "MIDPOINT", true); //wrapper.ClientSocket.reqScannerParameters(); //wrapper.ClientSocket.exerciseOptions(1, ContractSamples.getOption(), 1, 20, null, 1); //wrapper.ClientSocket.reqScannerSubscription(1, GetScannerSubscription()); //wrapper.ClientSocket.requestFA(Constants.FaProfiles); //NOT WORKING (ALSO CHECKED WITH JAVA 969) wrapper.ClientSocket.setServerLogLevel(1); Thread.Sleep(500000); }