List of deals
Getting a list of deals
To get a list of deals, there is the ISecurity.GetTrades (...) method. It has two implementations:
GetTrades (int barNum) - Get a list of deals by candle number.
GetTrades (int firstBarIndex, int lastBarIndex) - Get a list of deals by several candles.
In both cases, the methods return a list of ITrade objects.
Interface ITrade
Date
date and time
TradeNo
Trade number
Direction
Trade direction (Buy, Sell)
Price
Price
Quantity
Quantity
OpenInterest
Open interest
Example, we get the last 5 deals and print them to the log:
using System;
using System.Linq;
using System.Text;
using TSLab.Script;
using TSLab.Script.Handlers;
namespace MyLib
{
public class GetTrades : IExternalScript
{
public void Execute(IContext ctx, ISecurity sec)
{
// We get a list of deals for the last bar and take only the last 5 pieces.
var trades = sec.GetTrades(ctx.BarsCount - 1).Reverse().Take(5).ToList();
var sb = new StringBuilder();
// We display information on each transaction in the log.
foreach (var trade in trades)
{
sb.AppendFormat("Date: {0}; ", trade.Date);
sb.AppendFormat("TradeNo: {0}; ", trade.TradeNo);
sb.AppendFormat("Direction: {0}; ", trade.Direction);
sb.AppendFormat("Price: {0}; ", trade.Price);
sb.AppendFormat("Quantity: {0}; ", trade.Quantity);
sb.AppendFormat("OpenInterest: {0}; ", trade.OpenInterest);
sb.AppendLine();
}
ctx.Log(sb.ToString());
}
}
}
The information from TSLab completely matches the data from the terminal.

Last updated
Was this helpful?