private void Save_btn_Click(object sender, EventArgs e) { //Валидация double c1 = 0.0, c2 = 0.0; Indicator ind1 = null, ind2 = null; ParameterCondition par1 = ParameterCondition.Indicator, par2 = par1; if (rb_Price1.Checked) { par1 = Config.str2paramPrice[cb_Param1.Text]; } else { Type typeInd = Config.name2indicator[cb_Param1.Text]; int period1 = Int32.Parse(cb_periodInd1.Text); //получаем конструктор ConstructorInfo ci = typeInd.GetConstructor(new Type[] { typeof(int) }); ind1 = (Indicator)ci.Invoke(new object[] { period1 }); } if (rb_Price2.Checked) { par2 = Config.str2paramPrice[cb_Param2.Text]; } else if (rb_Const2.Checked) { par2 = ParameterCondition.Const; string s = tb_Const2.Text.Replace('.', ','); c2 = Double.Parse(s); } else { Type typeInd = Config.name2indicator[cb_Param2.Text]; int period2 = Int32.Parse(cb_periodInd2.Text); //получаем конструктор ConstructorInfo ci = typeInd.GetConstructor(new Type[] { typeof(int) }); ind2 = (Indicator)ci.Invoke(new object[] { period2 }); } int index1 = Int32.Parse(cb_index1.Text), index2 = 0; if (par2 != ParameterCondition.Const) { index2 = Int32.Parse(cb_index2.Text); } Predicate pred = Config.str2predicate[cb_Predicate.Text]; Condition newCond = new Condition(index1, index2, par1, par2, ind1, ind2, c1, c2, pred); strategy.add_condition(indexRule, newCond); parent.Show(); this.Close(); }
public void TestMethod1() { //Входные данные //Создать 2 условия int index1 = 0, index2 = 0; int curIndex = 60; ParameterCondition par1 = ParameterCondition.PriceClose; ParameterCondition par2 = ParameterCondition.PriceOpen; Predicate predicate = Predicate.Less; Condition cond = new Condition(index1, index2, par1, par2, null, null, 0.0, 0.0, predicate); int index1_ = 1, index2_ = 1; ParameterCondition par1_ = ParameterCondition.Indicator; ParameterCondition par2_ = ParameterCondition.Indicator; Predicate predicate_ = Predicate.MoreEqual; Indicator ind1 = new SMA(14); Indicator ind2 = new SMA(28); Condition cond2 = new Condition(index1_, index2_, par1_, par2_, ind1, ind2, 0.0, 0.0, predicate_); //Накопить данные для индикаторов for (int i = 0; i < curIndex; i++) { ind1.update_value(i, instrument); ind2.update_value(i, instrument); } //Создать правило TradingRule rule = new TradingRule(); rule.add_condition(cond); rule.add_condition(cond2); string name = "TestStrategy1"; DateTime dateTime = DateTime.Now; TradingStrategy strat = new TradingStrategy(name); strat.add_rule(rule); strat.save_to_xml(); controller.add_strategy(new CaretakerStrategy(strat)); TradingStrategy strat1 = controller.get_strategy(name).Originator; File.Delete("Strategies\\TestStrategy1.xml"); Assert.AreEqual(strat.Loaded && strat.Name == name && strat.DateOfChange == dateTime && strat.DateOfCreation == dateTime, true); }
public Condition(int index1, int index2, ParameterCondition par1, ParameterCondition par2, Indicator ind1, Indicator ind2, double c1, double c2, Predicate pred) { indexOfInterval1 = index1; parameter1 = par1; indicator1 = ind1; predicate = pred; indicator2 = ind2; parameter2 = par2; indexOfInterval2 = index2; const1 = c1; const2 = c2; }
private void InitConditions() { List <int> ids = ruleObject.parametersConditionsIds; conditions = new List <IParameterCondition>(); foreach (int cId in ids) { var c = new ParameterCondition(cId); if (c == null) { continue; } conditions.Add(c); } }
public void MatchesEventSignatureAndParameterCondition() { var fromCondition = ParameterCondition.Create( 1, ParameterConditionOperator.Equals, "0x12890d2cce102216644c59dae5baed380d84830c"); var eventSubscription = new EventSubscription <TestData.Contracts.StandardContract.TransferEvent>( parameterConditions: new IParameterCondition[] { fromCondition }); var transferLog = TestData.Contracts.StandardContract.SampleTransferLog(); var transferWithDifferentFromAddress = TestData.Contracts.StandardContract.SampleTransferLog(); transferWithDifferentFromAddress.Topics[1] = "0x00000000000000000000000013f022d72158410433cbd66f5dd8bf6d2d129924"; Assert.True(eventSubscription.IsLogForEvent(transferLog)); Assert.False(eventSubscription.IsLogForEvent(transferWithDifferentFromAddress)); }
public void to_string_price_price() { //Входные данные int index1 = 2, index2 = 1; ParameterCondition par1 = ParameterCondition.PriceClose; ParameterCondition par2 = ParameterCondition.PriceOpen; Predicate predicate = Predicate.Less; Condition cond = new Condition(index1, index2, par1, par2, null, null, 0.0, 0.0, predicate); string expected = "Цена закрытия на интервале i - 2 < Цена открытия на интервале i - 1 "; Assert.AreEqual(expected, cond.ToString()); }
void SetOnChanged() { ReleaseOnChanged(); int conditionCount = _ConditionList.conditionCount; for (int conditionIndex = 0; conditionIndex < conditionCount; conditionIndex++) { ParameterCondition condition = _ConditionList.GetCondition(conditionIndex); Parameter parameter = condition.reference.parameter; if (parameter != null) { parameter.onChanged += OnChangedParam; _Parameters.Add(parameter); } } }
//Тест проверяет правильно ли срабатывает Condition public void test_method_check_1() { //Входные данные int index1 = 0, index2 = 2; int curIndex = 60; ParameterCondition par1 = ParameterCondition.Volume; ParameterCondition par2 = ParameterCondition.Volume; Predicate predicate = Predicate.Less; Condition cond = new Condition(index1, index2, par1, par2, null, null, 0.0, 0.0, predicate); bool expected = instrument.get_interval(curIndex, index1).Volume < instrument.get_interval(curIndex, index1).Volume; Assert.AreEqual(expected, cond.check(curIndex, instrument)); }
//Тест проверяет правильно ли срабатывает TradingRule public void test_TradingRule() { //Входные данные //Создать 2 условия int index1 = 0, index2 = 0; int curIndex = 60; ParameterCondition par1 = ParameterCondition.PriceMax; ParameterCondition par2 = ParameterCondition.PriceMin; Predicate predicate = Predicate.Less; Condition cond = new Condition(index1, index2, par1, par2, null, null, 0.0, 0.0, predicate); int index1_ = 1, index2_ = 1; ParameterCondition par1_ = ParameterCondition.Indicator; ParameterCondition par2_ = ParameterCondition.Indicator; Predicate predicate_ = Predicate.MoreEqual; Indicator ind1 = new SMA(14); Indicator ind2 = new MACD(28); Condition cond2 = new Condition(index1_, index2_, par1_, par2_, ind1, ind2, 0.0, 0.0, predicate_); //Накопить данные для индикаторов for (int i = 0; i < curIndex; i++) { ind1.update_value(i, instrument); ind2.update_value(i, instrument); } //Создать правило TradingRule rule = new TradingRule(Signal.Buy); rule.add_condition(cond); rule.add_condition(cond2); bool expected = instrument.get_interval(curIndex, index1).ClosingPrice < instrument.get_interval(curIndex, index1).OpeningPrice&& ind1.get_value(curIndex, index1_) >= ind2.get_value(curIndex, index2_); Assert.AreEqual(expected, rule.check(curIndex, instrument)); }
private string FormatParameterCondition(ParameterCondition paramCond, ref Dictionary <String, Object> parameters) { string param1 = null; string param2 = null; //Param1 Formatting Default FieldEscape switch (paramCond.Param1Formatting) { case ParameterFormat.PREPARED_STATEMENT_ARGUMENT: param1 = String.Format("@val{0}", (parameters.Count + 1)); parameters.Add("@val" + (parameters.Count + 1), paramCond.Param1); break; case ParameterFormat.RAW: param1 = paramCond.Param1; break; default: param1 = FieldEscape(paramCond.Param1); break; } //Param2 Formatting Default Value Escape switch (paramCond.Param2Formatting) { case ParameterFormat.ESCAPE_PARAMETER_AS_FIELD: param2 = FieldEscape(paramCond.Param2); break; case ParameterFormat.RAW: param2 = paramCond.Param2; break; default: param2 = String.Format("@val{0}", (parameters.Count + 1)); parameters.Add("@val" + (parameters.Count + 1), paramCond.Param2); break; } return(String.Format("{0} {1} {2}", param1, paramCond.Operator, param2)); }
public void FromEventAbis_SetsDefaultDependencies() { var state = new EventSubscriptionStateDto(); var eventHandlerHistoryDb = new Mock <IEventHandlerHistoryRepository>().Object; var contractAddresses = new[] { "0x243e72b69141f6af525a9a5fd939668ee9f2b354" }; var parameterConditions = new[] { ParameterCondition.Create(1, ParameterConditionOperator.Equals, "x") }; var eventSubscription = new EventSubscription( TestData.Contracts.StandardContract.ContractAbi.Events, contractAddresses, parameterConditions, 1, 2, state, eventHandlerHistoryDb); Assert.Equal(1, eventSubscription.Id); Assert.Equal(2, eventSubscription.SubscriberId); var eventHandlerManager = eventSubscription.HandlerManager as EventHandlerManager; Assert.NotNull(eventHandlerManager); Assert.Same(eventHandlerHistoryDb, eventHandlerManager.History); Assert.IsType <EventHandlerManager>(eventSubscription.HandlerManager); Assert.Same(state, eventSubscription.State); var eventMatcher = eventSubscription.Matcher as EventMatcher; Assert.NotNull(eventMatcher); var eventAddressMatcher = eventMatcher.AddressMatcher as EventAddressMatcher; Assert.NotNull(eventAddressMatcher); Assert.Equal(contractAddresses, eventAddressMatcher.AddressesToMatch); var parameterMatcher = eventMatcher.ParameterMatcher as EventParameterMatcher; Assert.NotNull(eventMatcher.ParameterMatcher); Assert.Equal(parameterConditions, parameterMatcher.ParameterConditions); }
public ParamNumbers(float Numbers, ParameterCondition ParamCondition) { this.numbers = Numbers; this.paramCondition = ParamCondition; }
public ParamString(string StringVal, ParameterCondition ParamCondition) { this.stringVal = StringVal; this.paramCondition = ParamCondition; }
public ParamDate(DateTime Date, ParameterCondition ParamCondition) { this.date = Date; this.paramCondition = ParamCondition; }