Beispiel #1
0
        public static List <string> BuildPropertyLinesForSingleMarketSetting(string mainMarket, string marketPair, List <SingleMarketSetting> appliedSettings, Dictionary <string, object> properties, Dictionary <string, List <string> > matchedTriggers, Dictionary <string, string> fullProperties, List <string> newPropertyLines, PTMagicConfiguration systemConfiguration, LogHelper log)
        {
            if (properties.Keys.Count > 0)
            {
                string appliedSettingsStringList = "";
                foreach (SingleMarketSetting sms in appliedSettings)
                {
                    if (!appliedSettingsStringList.Equals(""))
                    {
                        appliedSettingsStringList += ", ";
                    }
                    appliedSettingsStringList += sms.SettingName;
                }

                newPropertyLines.Add("# " + marketPair + " - Current active settings: " + appliedSettingsStringList);

                foreach (string settingProperty in properties.Keys)
                {
                    int    valueMode   = Constants.ValueModeDefault;
                    string propertyKey = settingProperty;

                    // Check for offset values
                    if (propertyKey.IndexOf("_OFFSETPERCENT") > -1)
                    {
                        valueMode   = Constants.ValueModeOffsetPercent;
                        propertyKey = propertyKey.Replace("_OFFSETPERCENT", "");
                    }
                    else if (propertyKey.IndexOf("_OFFSET") > -1)
                    {
                        valueMode   = Constants.ValueModeOffset;
                        propertyKey = propertyKey.Replace("_OFFSET", "");
                    }

                    string newValueString = SystemHelper.PropertyToString(properties[settingProperty]);
                    if (newValueString.ToLower().Equals("true") || newValueString.ToLower().Equals("false"))
                    {
                        newValueString = newValueString.ToLower();
                    }

                    string propertyMarketName = marketPair;

                    // Adjust market pair name
                    propertyMarketName = propertyMarketName.Replace(mainMarket, "").Replace("_", "").Replace("-", "");

                    string propertyKeyString = "";
                    if (propertyKey.StartsWith("ALL", StringComparison.InvariantCultureIgnoreCase))
                    {
                        propertyKeyString = propertyKey.Replace("ALL", propertyMarketName, StringComparison.InvariantCultureIgnoreCase);
                    }
                    else if (propertyKey.StartsWith("DEFAULT", StringComparison.InvariantCultureIgnoreCase))
                    {
                        propertyKeyString = propertyKey.Replace("DEFAULT", propertyMarketName, StringComparison.InvariantCultureIgnoreCase);
                    }
                    else
                    {
                        if (propertyKey.StartsWith("_", StringComparison.InvariantCultureIgnoreCase))
                        {
                            propertyKeyString = propertyMarketName + propertyKey;
                        }
                        else
                        {
                            propertyKeyString = propertyMarketName + "_" + propertyKey;
                        }
                    }

                    switch (valueMode)
                    {
                    case Constants.ValueModeOffset:
                        // Offset value by a fixed amount
                        double offsetValue = SystemHelper.TextToDouble(newValueString, 0, "en-US");
                        if (offsetValue != 0)
                        {
                            double oldValue = SystemHelper.TextToDouble(SettingsHandler.GetCurrentPropertyValue(fullProperties, propertyKey, propertyKey.Replace("ALL_", "DEFAULT_")), 0, "en-US");
                            newValueString = Math.Round((oldValue + offsetValue), 8).ToString(new System.Globalization.CultureInfo("en-US"));
                        }
                        break;

                    case Constants.ValueModeOffsetPercent:
                        // Offset value by percentage
                        double offsetValuePercent = SystemHelper.TextToDouble(newValueString, 0, "en-US");
                        if (offsetValuePercent != 0)
                        {
                            double oldValue = SystemHelper.TextToDouble(SettingsHandler.GetCurrentPropertyValue(fullProperties, propertyKey, propertyKey.Replace("ALL_", "DEFAULT_")), 0, "en-US");
                            if (oldValue < 0)
                            {
                                offsetValuePercent = offsetValuePercent * -1;
                            }
                            double oldValueOffset = (oldValue * (offsetValuePercent / 100));
                            newValueString = Math.Round((oldValue + oldValueOffset), 8).ToString(new System.Globalization.CultureInfo("en-US"));
                        }
                        break;

                    default:
                        break;
                    }

                    newPropertyLines.Add(propertyKeyString + " = " + newValueString);
                }
                newPropertyLines.Add("");
            }

            return(newPropertyLines);
        }
Beispiel #2
0
        public static List <string> BuildPropertyLinesForSingleMarketSetting(string mainMarket, string marketPair, List <SingleMarketSetting> appliedSettings, Dictionary <string, object> properties, Dictionary <string, List <string> > matchedTriggers, Dictionary <string, string> fullProperties, List <string> newPropertyLines, PTMagicConfiguration systemConfiguration, LogHelper log)
        {
            if (properties.Keys.Count > 0)
            {
                string appliedSettingsStringList = "";
                foreach (SingleMarketSetting sms in appliedSettings)
                {
                    if (!appliedSettingsStringList.Equals(""))
                    {
                        appliedSettingsStringList += ", ";
                    }

                    appliedSettingsStringList += sms.SettingName;
                }

                newPropertyLines.Add("# " + marketPair + " - Current active settings: " + appliedSettingsStringList);

                foreach (string settingProperty in properties.Keys)
                {
                    string propertyKey = settingProperty;

                    string propertyKeyName = propertyKey.Replace("_OFFSETPERCENT", "");
                    propertyKeyName = propertyKeyName.Replace("_OFFSET", "");

                    string newValueString = SystemHelper.PropertyToString(properties[settingProperty]);
                    string oldValueString = SettingsHandler.GetCurrentPropertyValue(fullProperties, propertyKeyName, propertyKeyName.Replace("ALL_", "DEFAULT_"));

                    newValueString = CalculatePropertyValue(settingProperty, oldValueString, newValueString, out propertyKey);

                    string propertyMarketName = marketPair;

                    // Adjust market pair name
                    propertyMarketName = propertyMarketName.Replace(mainMarket, "").Replace("_", "").Replace("-", "");

                    string propertyKeyString = "";
                    if (propertyKey.StartsWith("ALL", StringComparison.InvariantCultureIgnoreCase))
                    {
                        propertyKeyString = propertyKey.Replace("ALL", propertyMarketName, StringComparison.InvariantCultureIgnoreCase);
                    }
                    else if (propertyKey.StartsWith("DEFAULT", StringComparison.InvariantCultureIgnoreCase))
                    {
                        propertyKeyString = propertyKey.Replace("DEFAULT", propertyMarketName, StringComparison.InvariantCultureIgnoreCase);
                    }
                    else
                    {
                        if (propertyKey.StartsWith("_", StringComparison.InvariantCultureIgnoreCase))
                        {
                            propertyKeyString = propertyMarketName + propertyKey;
                        }
                        else
                        {
                            propertyKeyString = propertyMarketName + "_" + propertyKey;
                        }
                    }

                    newPropertyLines.Add(propertyKeyString + " = " + newValueString);
                }
            }

            return(newPropertyLines);
        }