public void ChangePrice(Trade trade, TypeOfFunction type) //Change price after trade management { Commodity commodity = context.Commodities.Find(trade.CommodityId); double priceVariation = ((commodity.CurrentPrice * trade.Quantity) / (commodity.BasePrice * 100)); if (trade.Side == Side.Buy) { if (type == TypeOfFunction.Add) { commodity.CurrentPrice += priceVariation; } else if (type == TypeOfFunction.Delete) { if (priceVariation > commodity.CurrentPrice) { commodity.CurrentPrice = 0; } else { commodity.CurrentPrice -= priceVariation; } } else { commodity.CurrentPrice += priceVariation; } } else { if (type == TypeOfFunction.Add) { if (priceVariation > commodity.CurrentPrice) { commodity.CurrentPrice = 0; } else { commodity.CurrentPrice -= priceVariation; } } else if (type == TypeOfFunction.Delete) { commodity.CurrentPrice += priceVariation; } else { if (priceVariation > commodity.CurrentPrice) { commodity.CurrentPrice = 0; } else { commodity.CurrentPrice -= priceVariation; } } } UpdateTickerNotification(commodity); context.SaveChanges(); }
public string GetFuncTypeName(CompilerState State, TypeOfFunction FuncType) { var FuncCh = FuncType.Children; var Rec = State.Language.Root.GetObject <CallingConventionRecognizer>(); var Mod = Rec.GetCallingConventionName(FuncType.CallConv); var Out = Mod + " "; if (FuncCh.Length == 1) { Out += "void"; } else { for (var i = 1; i < FuncCh.Length; i++) { Out += State.GenerateName(FuncCh[i].TypeOfSelf); if (i < FuncCh.Length - 1) { Out += ", "; } } } Out += " -> "; var RetType = FuncCh[0]; if (RetType.RealId is TupleType) { var Tuple = RetType.RealId as TupleType; var Members = Tuple.StructuredScope.IdentifierList; for (var i = 0; i < Members.Count; i++) { Out += State.GenerateName(Members[i].TypeOfSelf); if (i < Members.Count - 1) { Out += ", "; } } } else { Out += State.GenerateName(RetType); } return(Out); }
protected Function(string name, int dimension, TypeOfFunction typeOfFunction, double[] optimalCoordinates, double[] lowerSearchBorders, double[] upperSearchBorders) { Assert(name.Length > 0); Assert(dimension > 0); Assert(typeOfFunction != TypeOfFunction.Unknown); Assert(dimension == optimalCoordinates.Length); Assert(dimension == lowerSearchBorders.Length); Assert(dimension == upperSearchBorders.Length); Name = $"{name}-{dimension}D"; Dimension = dimension; TypeOfFunction = typeOfFunction; OptimalCoordinates = optimalCoordinates.Copy(); LowerSearchBorders = lowerSearchBorders.Copy(); UpperSearchBorders = upperSearchBorders.Copy(); }
/// <summary> /// get (the) response for... /// </summary> /// <param name="theException">the exception</param> /// <param name="theMethod">the type of method</param> /// <param name="useLoggingScope">use (the) logging scope</param> /// <returns>the currently running task containing the http response message</returns> public async Task <HttpResponseMessage> GetResponseFor(Exception theException, TypeOfFunction theMethod, IScopeLoggingContext useLoggingScope) { var exceptionType = theException.GetType(); if (_methodMap[theMethod].ContainsKey(exceptionType)) { await InformOn(theException, useLoggingScope); return(_methodMap[theMethod][exceptionType].Invoke(theException)); } await useLoggingScope.ExceptionDetail(theException); return(_methodMap[theMethod][typeof(FallbackActionException)].Invoke(theException)); }
public SimpleRecResult Recognize(IdContainer Container, CodeString Code, GetIdOptions Options, ref Identifier Ret) { if (Code.StartsWith(Operators, Skip, IdCharCheck: new IdCharCheck(true)).Index == 0) { var State = Container.State; if (Code[Code.Length - 1] != ')') { if (Options.EnableMessages) { State.Messages.Add(MessageId.NotExpected, Code); } return(SimpleRecResult.Failed); } var BracketPos = Code.GetBracketPos(State, true, Options.EnableMessages); if (BracketPos == -1) { return(SimpleRecResult.Failed); } var Left = Code.TrimmedSubstring(State, 3, BracketPos - 3, Options.EnableMessages); if (!Left.IsValid) { return(SimpleRecResult.Failed); } CallingConvention CallConv; if (!Modifiers.GetCallConv(Container, ref Left, out CallConv)) { return(SimpleRecResult.Failed); } if (CallConv == CallingConvention.Unknown) { CallConv = Container.DefaultCallConv; } var TOptions = Options; TOptions.Func = x => x.RealId is Type; var RetType = Identifiers.Recognize(Container, Left, TOptions); var StrParams = Code.Substring(BracketPos + 1, Code.Length - BracketPos - 2).Trim(); var Flags = VarDeclarationListFlags.EnableUnnamed | VarDeclarationListFlags.EnableInitValue; if (Options.EnableMessages) { Flags |= VarDeclarationListFlags.EnableMessages; } var DeclList = VarDeclarationList.Create(Container, StrParams, null, Flags); if (DeclList == null || RetType == null) { return(SimpleRecResult.Failed); } if (!(RetType.RealId is Type)) { State.Messages.Add(MessageId.UnknownType, Left); return(SimpleRecResult.Failed); } var Params = DeclList.ToFuncParams(Container.GetPlugin()); if (Params == null || Params.Contains(null)) { return(SimpleRecResult.Failed); } Ret = new TypeOfFunction(Container, CallConv, RetType, Params); if (Options.Func == null || Options.Func(Ret)) { return(SimpleRecResult.Succeeded); } } return(SimpleRecResult.Unknown); }
public SimpleRecResult Recognize(IdContainer Container, CodeString Code, GetIdOptions Options, ref Identifier Out) { var State = Container.State; var Result = RecognizerHelper.Find(this, State, Code.String); if (Result.Position != -1) { var OldCode = Code; var Mods = Modifiers.Recognize(Container, ref Code); if (Mods == null) { return(SimpleRecResult.Failed); } Result.Position -= Code.Index - OldCode.Index; var Left = Code.TrimmedSubstring(State, 0, Result.Position, Options.EnableMessages); if (!Left.IsValid) { return(SimpleRecResult.Failed); } var Right = Code.TrimmedSubstring(State, Result.Position + Result.String.Length, Options.EnableMessages); if (!Right.IsValid) { return(SimpleRecResult.Failed); } var Flags = VarDeclarationListFlags.EnableUnnamed | VarDeclarationListFlags.EnableInitValue | VarDeclarationListFlags.EnableVoidOnly; if (Options.EnableMessages) { Flags |= VarDeclarationListFlags.EnableMessages; } var ParamDeclList = VarDeclarationList.Create(Container, Left, null, Flags); if (ParamDeclList == null) { return(SimpleRecResult.Failed); } if (ParamDeclList.Count == 1 && ParamDeclList[0].Type.RealId is VoidType) { ParamDeclList.RemoveAt(0); } var Params = ParamDeclList.ToFuncParams(Container.GetPlugin()); if (Params == null || Params.Contains(null)) { return(SimpleRecResult.Failed); } Flags &= ~VarDeclarationListFlags.EnableInitValue; var RetDeclList = VarDeclarationList.Create(Container, Right, null, Flags); if (RetDeclList == null) { return(SimpleRecResult.Failed); } Identifier RetType; if (RetDeclList.Count == 1 && !RetDeclList[0].Name.IsValid) { RetType = RetDeclList[0].Type; } else { RetType = RetDeclList.ToTupleType(Container, Options.EnableMessages); if (RetType == null) { return(SimpleRecResult.Failed); } } var CallConv = Container.DefaultCallConv; var Succeeded = true; var Static = false; Mods.ForEach(x => { if (x is CallingConventionModifier) { var CCM = x as CallingConventionModifier; CallConv = CCM.CallingConvention; } else if (x is FlagModifier) { var FM = x as FlagModifier; if ((FM.Flags & IdentifierFlags.Static) != 0) { Static = true; } if ((FM.Flags & ~IdentifierFlags.Static) != 0) { if (Options.EnableMessages) { State.Messages.Add(MessageId.ModifierCantBeUsed, x.Code); } Succeeded = false; } } else { if (Options.EnableMessages) { State.Messages.Add(MessageId.ModifierCantBeUsed, x.Code); } Succeeded = false; } }); if (!Succeeded) { return(SimpleRecResult.Failed); } Identifier FuncType = new TypeOfFunction(Container, CallConv, RetType, Params); Out = Static ? FuncType : new NonstaticFunctionType(Container, FuncType); if (Options.Func == null || Options.Func(Out)) { return(SimpleRecResult.Succeeded); } return(SimpleRecResult.Succeeded); } return(SimpleRecResult.Unknown); }
protected Function(string name, int dimension, TypeOfFunction typeOfFunction, double[] optimalCoordinates) : this(name, dimension, typeOfFunction, optimalCoordinates, NewByValue(dimension, -10.0), NewByValue(dimension, 10.0)) { }