Get script and agent settings

Add TSLab.DataModel.dll and TSLab.ScriptEngine.dll to the External script block.

using System.Text;
using TSLab.DataModel;
using TSLab.Script;
using TSLab.Script.Handlers;
using TSLab.ScriptExecution.Realtime;

namespace MyLib
{
    public class TestSettings: IExternalScript
    {
        public void Execute (IContext ctx, ISecurity sec)
        {
            // TSLab.DataModel.dll, TSLab.ScriptExecution.dll must be added to the 'External script' block.
                        
            // Get script settings
            var labOptions = ctx.GetLabOptions ();
            if (labOptions! = null)
            {
                var sb = new StringBuilder ();
                sb.AppendLine ($ "=== LabOptions ===");
                sb.AppendLine ($ "Date from: ({labOptions.UseDateFrom}) {labOptions.DateFromEdit}");
                sb.AppendLine ($ "Date to: ({labOptions.UseDateTo}) {labOptions.DateToEdit}");
                ctx.Log (sb.ToString (), MessageType.Info, true);
            }

            // Get agent settings
            var rtOptions = ctx.GetRtOptions ();
            if (rtOptions! = null)
            {
                var sb = new StringBuilder ();
                sb.AppendLine ($ "=== RtOptions ===");
                sb.AppendLine ($ "Execute entries immediately: {rtOptions.DefEntryApprove}");
                sb.AppendLine ($ "Execute exits immediately: {rtOptions.DefExitApprove}");
                ctx.Log (sb.ToString (), MessageType.Info, true);
            }
        }
    }

    public static class TSLabExtensions
    {
        public static LabOptions GetLabOptions (this IContext ctx)
        {
            var fi = ctx.Runtime.GetType (). GetProperty ("Options");
            return fi? .GetValue (ctx.Runtime) as LabOptions;
        }

        public static RealtimeScriptOptions GetRtOptions (this IContext ctx)
        {
            var fi = ctx.Runtime.GetType (). GetProperty ("Manager");
            var val = fi? .GetValue (ctx.Runtime) as RealtimeDataManager;
            return val? .RtData? .Options;
        }
    }
}

Full list of agent settings:

var rtOptions = Ctx.GetAgentSettings ();
if (rtOptions! = null)
{
var sb = new StringBuilder ();
sb.AppendLine ($ "=== AgentSettings ===");

sb.AppendLine ($ "\ n \ n === Agent execution ===");
sb.AppendLine ($ "\ nFeed inputs immediately: {rtOptions.DefEntryApprove}"); // True
sb.AppendLine ($ "\ nExits immediately: {rtOptions.DefExitApprove}"); // True
sb.AppendLine ($ "\ nAutoopen (bars): {rtOptions.AutoEntryBars}"); // 0
sb.AppendLine ($ "\ nBlock by market with a fixed price for autoopening: {rtOptions.AutoEntryIgnoreByMarketAsLimit}"); // False
sb.AppendLine ($ "\ nAutoclose (bars): {rtOptions.AutoCloseBars}"); // 0
sb.AppendLine ($ "\ nBlock by market with a fixed price for auto close: {rtOptions.AutoCloseIgnoreByMarketAsLimit}"); // False
sb.AppendLine ($ "\ nIgnore positions out of history: {rtOptions.RemoveInactivePositions}"); // False
sb.AppendLine ($ "\ nNotify about missed entries: {rtOptions.WarnSkippedOpenPositions}"); // True
sb.AppendLine ($ "\ nDo not open if skipped entry: {rtOptions.NotOpenIfHasSkippedExit}");
sb.AppendLine ($ "\ nDo not notify recount: {rtOptions.NoCalcInfo}");
sb.AppendLine ($ "\ nVirtual position of max. candles: {rtOptions.MaxBarsForSignal}");
sb.AppendLine ($ "\ nIgnore exit signal not on the last candlestick: {rtOptions.ExitSignalOnlyForLastBar}");
sb.AppendLine ($ "\ nWait for exit execution: {rtOptions.WaitExecutionExitBars}");
sb.AppendLine ($ "\ nWait for login execution: {rtOptions.WaitExecutionEntryBars}");
sb.AppendLine ($ "\ nTake into account the commission: {rtOptions.UseCommissionInProfit}");

sb.AppendLine ($ "\ n \ n === Placing orders ===");
sb.AppendLine ($ "\ nSlipping in steps: {rtOptions.Slippage}");
sb.AppendLine ($ "\ nSlipping in%: {rtOptions.SlippagePct}");
sb.AppendLine ($ "\ nTakeProfit no slippage: {rtOptions.TakeProfitNoSlippage}");
sb.AppendLine ($ "\ nOpening by limit orders: {rtOptions.OpenPositionNoSlippage}");
sb.AppendLine ($ "\ n \" By market \ "with a fixed price: {rtOptions.ByMarketAsLimt}");
sb.AppendLine ($ "\ n \" Bad \ "market orders: {rtOptions.InvalidStopsByMarket}");

sb.AppendLine ($ "\ n \ n === Events ===");
sb.AppendLine ($ "\ nApplication rejected: {rtOptions.EventOrderRejected}");
sb.AppendLine ($ "\ nApplication completed in full: {rtOptions.EventOrderFilled}");
sb.AppendLine ($ "\ nOpening position: {rtOptions.EventPositionOpening}");
sb.AppendLine ($ "\ nClosing position: {rtOptions.EventPositionClosing}");
sb.AppendLine ($ "\ nChanging the quantity in the order: {rtOptions.EventOrderQtyChanged}");
sb.AppendLine ($ "\ nTrading started: {rtOptions.EventTradingIsStarted}");
sb.AppendLine ($ "\ nTrading stopped: {rtOptions.EventTradingIsStopped}");
sb.AppendLine ($ "\ nApplication canceled: {rtOptions.EventOrderCanceled}");
sb.AppendLine ($ "\ nPretrade limitation: {rtOptions.EventPretradeLimitation}");

ctx.Log (sb.ToString (), MessageType.Info, true);
}

Last updated