Working with fills
TT .NET SDK offers two methods to receive fills.
- The TradeSubscription class provides events for fills that occurred since the TT .NET SDK application started running.
- The FillsSubscription class provides events for fills that occurred since the beginning of the trading session as well as fills that occurred since the TT .NET SDK application started running.
Supported update events
A FillsSubscription object fires the following events.
- FillAdded: Fired to deliver fills that occurred since the application started running
- FillAmended: Fired when a fill's details have been modified
- FillBookDownload: Fired to deliver fills that occurred since the beginning of the trading session for a given market. Will not fire if fills have not occurred.
- FillConfirmed:Fired when a fill confirmation is received
- FillDeleted: Fired when a fill is deleted
- FillListEnd: Fired when the fill download for fills that occurred since the beginning of the trading session is completed for a given market
- FillListStart: Fired when the fill download for fills that occurred since the beginning of the trading session begins for a given market.
If fills have not yet occurred, a FillListStart event will be received followed by a FillListEnd event. A FillBookDownload does not fire if there are no fills.
Subscribing for update events
You can subscribe for update events as follows before calling the FillsSubscription.Start() method. The following example demonstrates this process.
m_api.StartFillFeed();
FillSubscription m_fs = new FillsSubscription(tt_net_sdk.Dispatcher.Current);
m_fs.FillAdded += m_fs_FillAdded;
m_fs.FillBookDownload += m_fs_FillBookDownload;
m_fs.FillListEnd += m_fs_FillListEnd;
m_fs.FillListStart += m_fs_FillListStart;
m_fs.Start()
Defining event handlers
The following code snippet shows the structure for these event handlers.
void m_fs_FillListStart(object sender, FillListEventArgs e)
{
}
void m_fs_FillListEnd(object sender, FillListEventArgs e)
{
}
void m_fs_FillBookDownload(object sender, FillBookDownloadEventArgs e)
{
foreach (Fill f in e.Fills)
{
// process fill
}
}
void m_fs_FillAdded(object sender, FillAddedEventArgs e)
{
// process fill contained in e.Fill
}
Publishing Manual Fills
TT .NET SDK also allows publishing manual fills via the API as demonstrated in the following code snippet.
public bool send_ManualFill(out string response)
{
Price price = Price.FromDecimal(instrument, Convert.ToDecimal(2986));
m_fp = new FillProfile(instrument);
m_fp.MarketId = MarketId.CME;
m_fp.Quantity = Quantity.FromDecimal(instrument, Convert.ToDecimal(5));
m_fp.Account = m_apiInstance.DefaultAccount;
bool isPublishedManualFill = m_ts.PublishManualFill(m_fp, out response);
return isPublishedManualFill;
}
Downloading Fills
You can use the FillDownload class to download fills for a specific period of time. The FillDownload class allows you to select a start and end time, provided in nanos past the epoch. The download can be either synchronous via Get() or asynchronous via GetAsync().
public void DownloadFills()
{
DateTime UtcEpochTimeStart_ = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
// start and end times in nanos past the epoch
DateTime dt = new DateTime(2023, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
UInt64 start = (UInt64)(from - UtcEpochTimeStart_).Ticks * 100;
dt = new DateTime(2023, 2, 1, 0, 0, 0, 0, DateTimeKind.Utc);
UInt64 end = (UInt64)(from - UtcEpochTimeStart_).Ticks * 100;
FillDownload fd = new FillDownload(this.dispatcher, MarketId.CME, start, 0);
// synchronous retrieval
FillDownloadResult code = fd.Get();
if (code == FillDownloadResult.Success)
{
// fd.Fills contains downloaded fills
}
}