Order Status Checking

Questions about MultiCharts .NET and user contributed studies.
lstman
Posts: 18
Joined: 26 Feb 2013
Has thanked: 2 times
Been thanked: 1 time

Order Status Checking

Postby lstman » 08 Jan 2014

Hi

I want to confirm "order filled" or not, after order sending.
I put Limit order and cancel it after 100 milliseconds.
if order is not filled, TWS accepts cancel.
but already order filled, I have one position.

I want to confirm order status soon, after "p.CancelOrder(_id);".

Please advise.

Code: Select all

using System;
using System.Drawing;
using System.Linq;
using PowerLanguage.Function;
using PowerLanguage.TradeManager;
using ATCenterProxy.interop;

namespace PowerLanguage.Strategy
{
public class Test_TradeManager_5 : SignalObject
{
public Test_TradeManager_5(object _ctx):base(_ctx){}
private IOrderMarket buy_order;
protected override void Create()
{
}

protected override void StartCalc()
{
}

protected override void CalcBar()
{
foreach (TradeManager.ITradingProfile p in TradeManager.TradingProfiles)
{
if (p.PluginName.Contains("Interactive Brokers") && p.ConnectionState == ETM_ConnectionChanged.eTM_CC_Connected)
{
Output.WriteLine("Start");
MCSymbolInfo msymbInfo = new MCSymbolInfo();
msymbInfo.symbol.BigPointValue = Bars.Info.BigPointValue;
msymbInfo.symbol.MinMove = (int)Bars.Info.MinMove;
msymbInfo.symbol.PriceScale = Bars.Info.PriceScale;
msymbInfo.symbol.SymbolCategory = MTPA_MCSymbolCategories.eMTPA_MCSC_FUTURE;
msymbInfo.symbol.SymbolDescription = Bars.Info.Description; /*"USD DEC13 ES Futures ESZ3 MULT:50";*/
msymbInfo.data_feed = "Interactive Brokers";
msymbInfo.symbol.SymbolExchange = "GLOBEX";
msymbInfo.symbol.SymbolExpiry = Convert.ToDateTime("20.12.2013");
msymbInfo.symbol.SymbolName = Bars.Info.Name;
msymbInfo.symbol.SymbolRoot = "ES";
p.CurrentSymbol = msymbInfo;
OrderParams _pparam = new OrderParams();
_pparam.action = MTPA_OrdrActn.eMTPA_OA_Buy;

double _oPrice = Bars.LowValue - 0.5;

_pparam.category = MTPA_OrdrCtgry.eMTPA_OC_Limit;
_pparam.contracts = 10;
_pparam.tif = MTPA_OrdrTimeInForce.eMTPA_TIF_DAY;
_pparam.limit_price = _oPrice;

int _id = p.PlaceOrder(_pparam);
System.Threading.Thread.Sleep(100);
p.CancelOrder(_id);

////////////////////////////////////////////////////
//
// I want to confirm oder status in here.
// the above order is filled or not...
// Because, if this order is filled, I want to put other order soon.
//
////////////////////////////////////////////////////

Output.WriteLine("Success!");
}
}
}
}

}

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Order Status Checking

Postby Henry MultiСharts » 08 Jan 2014

Hello lstman,

"Generated" and "Filled\Canceled" values were added to TradeManager.Order in MultiCharts .NET 8.1 Beta1.
Please make sure you are running this version for accessing this functionality.
Here is a sample code for using it:

Code: Select all

using System;
using System.Drawing;
using System.Linq;
using PowerLanguage.Function;
using ATCenterProxy.interop;
using PowerLanguage.TradeManager;
using ATCenterProxy;
using System.Collections;
using System.Collections.Generic;
using System.Windows.Forms;


namespace PowerLanguage.Strategy {
public class Test_HistoryOrdersLookUp : SignalObject
{
public Test_HistoryOrdersLookUp(object _ctx):base(_ctx){}

protected override void Create()
{
}

protected override void StartCalc()
{
Output.Clear();
}

bool subscribed = false;

protected override void CalcBar()
{
if (!subscribed)
{
TradeManager.TradingData.Orders.FinishChanging += new EventHandler( Orders_FinishChanging );
subscribed = true;
}

if (Bars.CurrentBar == 1)
{
TradeManager.TradingData.Orders.IntervalFltr.From = DateTime.Now.AddDays(-20);
TradeManager.TradingData.Orders.ProfileFltr.CurrentValue = "CQG";
}

TradeManager.ProcessEvents();
}

void Orders_FinishChanging( object sender, EventArgs e )
{
TradeManager.IOrders ord = sender as TradeManager.IOrders;
Output.WriteLine("Data Count = {0}", ord.Items.Length);
foreach (TradeManager.Order o in ord.Items)
{
Output.WriteLine( "Order Profile = {0}, Order ID = {1} , ExecPrice = {2}, Generated = {3}, Filled\\Canceled = {4} ",
o.Profile, o.ID, o.ExecPrice, o.GeneratedDT, o.FinalDT.Value);
}
}
}
}


Return to “MultiCharts .NET”