Skip to content

HistoricalTrade

interface cAlgo.API

DesktopCLICloud

Represents the historical trade interface.

Definition

public interface HistoricalTrade

Namespace: cAlgo.API · Group: History

Examples

Example 1

var lastTenTrades = History.OrderByDescending(trade => trade.ClosingTime).Take(10);
foreach (var trade in lastTenTrades)
    Print("{0} {1} {2} units, opened {3}, closed {4}, net profit {5}", trade.SymbolName, trade.TradeType, trade.VolumeInUnits, trade.EntryTime, trade.ClosingTime, trade.NetProfit);
lastTenTrades = sorted(api.History, key=lambda trade: trade.ClosingTime, reverse=True)[:10]
for trade in lastTenTrades:
    api.Print(f"{trade.SymbolName} {trade.TradeType} {trade.VolumeInUnits} units, opened {trade.EntryTime}, closed {trade.ClosingTime}, net profit {trade.NetProfit}")

Example 2

protected override void OnStart()
{
    Positions.Closed += OnPositionsClosed;
}

private void OnPositionsClosed(PositionClosedEventArgs args)
{
    var trade = History.FindByPositionId(args.Position.Id).LastOrDefault();
    if (trade != null)
        Print("Trade closed at {0}, pips {1}, balance {2}", trade.ClosingPrice, trade.Pips, trade.Balance);
}
def on_start(self):
    api.Positions.Closed += self.on_positions_closed

def on_positions_closed(self, args):
    trades = api.History.FindByPositionId(args.Position.Id)
    if len(trades) > 0:
        trade = trades[len(trades) - 1]
        api.Print(f"Trade closed at {trade.ClosingPrice}, pips {trade.Pips}, balance {trade.Balance}")

Properties

Name Description
BalanceDesktopCLIClouddouble Account balance after the Deal was filled
ChannelDesktopCLICloudstring Gets the channel via which the trade was executed in a string format.
ClosingDealDesktopCLICloudDeal Gets the closing deal.
ClosingDealIdDesktopCLICloudint Gets the unique closing deal identifier.
ClosingPriceDesktopCLIClouddouble The execution price of the Closing Deal.
ClosingTimeDesktopCLICloudDateTime Time of the Closing Deal.
CommentDesktopCLICloudstring The comment.
CommissionsDesktopCLIClouddouble Commission owed.
EntryPriceDesktopCLIClouddouble The VWAP (Volume Weighted Average Price) of the Opening Deals that are closed.
EntryTimeDesktopCLICloudDateTime Time of the Opening Deal, or the time of the first Opening deal that was closed.
GrossProfitDesktopCLIClouddouble Profit and loss before swaps and commission
LabelDesktopCLICloudstring The label.
NetProfitDesktopCLIClouddouble Profit and loss including swaps and commissions
PipsDesktopCLIClouddouble Represents the winning or loosing pips
PositionIdDesktopCLICloudint Gets the position unique identifier.
QuantityDesktopCLIClouddouble The Quantity (in lots) that was closed by the Closing Deal
SwapDesktopCLIClouddouble Swap is the overnight interest rate if any, accrued on the position.
SymbolDesktopCLICloudSymbol Gets the trade symbol.
SymbolNameDesktopCLICloudstring Gets the symbol name.
TradeTypeDesktopCLICloudTradeType The TradeType of the Opening Deal.
VolumeInUnitsDesktopCLIClouddouble The Volume that was closed by the Closing Deal.
Deprecated members (2)
  • string SymbolCode {get;} — Use SymbolName instead
  • long Volume {get;} — Use VolumeInUnits instead

See also