Skip to content

Algo.RefreshData

method · Algo · cAlgo.API.Internals

DesktopCLICloud

Updates Bars, Positions, PendingOrders, History, etc. And sends postponed events after Thread sleep call. If you put the main thread on sleep by calling Thread sleep method then you have to call RefreshData after Thread wakes up to send the postponed events while thread was sleeping.

Definition

public void RefreshData()
api.RefreshData() -> None

Examples

var operations = new List<TradeOperation>();
for (var i = 0; i < 5; i++)
    operations.Add(ExecuteMarketOrderAsync(TradeType.Buy, SymbolName, Symbol.VolumeInUnitsMin));
while (operations.Any(operation => operation.IsExecuting))
{
    System.Threading.Thread.Sleep(100);
    // Without RefreshData the trade results are not delivered while the thread sleeps
    RefreshData();
}
Print("Open positions: {0}", Positions.Count);
operations = [api.ExecuteMarketOrderAsync(TradeType.Buy, api.SymbolName, api.Symbol.VolumeInUnitsMin) for i in range(5)]
while any(operation.IsExecuting for operation in operations):
    api.Sleep(100)
    # Without RefreshData the trade results are not delivered while the thread sleeps
    api.RefreshData()
api.Print(f"Open positions: {api.Positions.Count}")