/// <summary> /// When constructed, tries to connect to MT4 Server immediately /// </summary> /// <param name="acc">MT4 account id</param> /// <param name="passwd">MT4 account password</param> /// <param name="broker">MT4 Broker Name (known to NJ4X Terminal Server)</param> public Master(string acc, string passwd, string broker) { Acc = acc; Passwd = passwd; Broker = broker; if (acc == null || passwd == null || broker == null) { Logger.Info("There was an error connecting to the master account"); System.Environment.Exit(1); } // Slaves = new ArrayList(); // SetPositionListener( delegate(IPositionInfo info) { PositionInfo = info; }, delegate(IPositionInfo info, IPositionChangeInfo changes) { foreach (Copier c in Slaves) { ThreadPool.QueueUserWorkItem(c.OnChange, changes); } }); Connect(CarbonFX.TerminalHost, CarbonFX.TerminalPort, new Broker(Broker), Acc, Passwd); // Info("Master connected"); }
public void SyncPosition(IPositionInfo positionInfo) { if (positionInfo.MarketPrice <= 0) { return; } if (_orderMaker.Name == ProviderName.HUA_NAN) { _positionInfo = positionInfo; InitAccountPositionStatus(); BeginSync(); } else { foreach (var accountSettings in Accounts) { string symbol = accountSettings.Symbol; int lotsNeedOrder = GetLotsNeedOrder(positionInfo, accountSettings); if (lotsNeedOrder != 0) { decimal marketPrice = positionInfo.MarketPrice; bool dayTrade = _tradeSettings.DayTrade; MakeOrder(symbol, accountSettings.Account, marketPrice, lotsNeedOrder, dayTrade); } } } }
/// <summary> /// A dialog (window) just off the edge (xpos+width) of its parent dialog(window), /// the y-axis can be altered via yOffset. /// TODO: It should probably be possible to change the width(/height) of the dialog. /// </summary> /// <param name="dlgService"></param> /// <param name="posInfo"></param> /// <param name="yOffset">Determines how far from the top the dialog will appear in y-axis</param> public IntegerTextBoxDialogViewModel(IDialogService dlgService, IPositionInfo posInfo, double yOffset) : base(dlgService) { this.posInfo = posInfo; this.yOffset = yOffset; TextBoxText = string.Empty; closeNoSaveCommand = new MyCommand(CloseNoSave); }
/// <summary> /// A dialog (window) just off the edge (xpos+width) of its parent dialog(window), /// the y-axis can be altered via yOffset. /// TODO: It should probably be possible to change the width(/height) of the dialog. /// </summary> /// <param name="dlgService"></param> /// <param name="posInfo"></param> /// <param name="yOffset">Determines how far from the top the dialog will appear in y-axis</param> public IntegerTextBoxDialogViewModel(IDialogService dlgService, IPositionInfo posInfo, double yOffset) { this.dlgService = dlgService; this.posInfo = posInfo; this.yOffset = yOffset; closeSaveCommand = new MyCommand(CloseSave, CanCloseSave); closeNoSaveCommand = new MyCommand(CloseNoSave); }
public IntegerTextBoxDialogViewModel(IDialogService dialogService) : this(dialogService, null, 10) { posInfo = new PosInfo() { MaxY = 0, OwnerWidth = 500, OwnerHeight = 400, XPosition = 100, YPosition = 0 }; }
/// <summary> /// Creates an <see cref="FormatException"/> with the provided properties. /// </summary> public static FormatException Format(string message, IPositionInfo pos) { string location = null; if (pos != null) { location = $"line {pos.LineNumber}, pos {pos.LinePosition}"; } return(Format(message, location)); }
int GetLotsNeedOrder(IPositionInfo positionInfo, AccountSettings accountSettings) { string symbol = accountSettings.Symbol; string account = accountSettings.Account; int currentLots = _orderMaker.GetAccountPositions(account, symbol); int correctLots = positionInfo.Position * accountSettings.Lot; return(correctLots - currentLots); }
/// <summary> /// Creates an <see cref="FormatException"/> with the provided properties. /// </summary> public static FormatException Format(string message, IPositionInfo pos, Exception innerException = null) { if (pos != null) { return(Format(message, pos.LineNumber, pos.LinePosition, innerException)); } else { return(Format(message, (string)null, innerException)); } }
internal void SetMaster(object master) { _master = (Master)master; Info(String.Format("Attached to {0}", _master.Acc + "@" + _master.Broker)); // IPositionInfo positionInfo = _master.PositionInfo; foreach (IOrderInfo masterOrder in positionInfo.GetHistoricalOrders().Values) { MasterOrderClosedOrDeleted(masterOrder); } }
internal static FormatException Format(string message, IPositionInfo pos) { string excMessage; if (pos != null) { excMessage = String.Format("At line {0}, pos {1}: {2}", pos.LineNumber, pos.LinePosition, message); } else { excMessage = Error.formatMessage(message); } return(new FormatException(excMessage)); }
private void AddLocations(ISourceNode node, ref IPositionInfo lastNode, ref int lastCharPos, char[] chars) { int location = 0; IPositionInfo posInfo = (node as IAnnotated)?.Annotation <Hl7.Fhir.Serialization.XmlSerializationDetails>(); if (posInfo == null) { posInfo = (node as IAnnotated)?.Annotation <Hl7.Fhir.Serialization.JsonSerializationDetails>(); } if (posInfo != null) { if (lastNode == null) { location = 0; } else { var linesToSkip = posInfo.LineNumber - lastNode.LineNumber; var colsToSkip = posInfo.LinePosition; if (linesToSkip == 0) { colsToSkip -= lastNode.LinePosition; } while (linesToSkip > 0 && lastCharPos < chars.Length) { lastCharPos++; if (chars[lastCharPos] == '\r') { linesToSkip--; } } lastCharPos += colsToSkip; location = lastCharPos; // need to patch this } lastNode = posInfo; _locations.Add(location, node.Location); // System.Diagnostics.Trace.WriteLine($"{location}: {node.Location}"); } lastCharPos = location; foreach (var child in node.Children()) { AddLocations(child, ref lastNode, ref lastCharPos, chars); } }
/// <summary> /// Creates an <see cref="FormatException"/> with the provided properties. /// </summary> public static FormatException Format(string message, IPositionInfo pos) => pos != null? Format(message, pos.LineNumber, pos.LinePosition) : Format(message, (string)null);
public IPositionChangeInfo MergePosition(IPositionInfo positionInfo) { if (positionInfo == null) { PositionChangeImpl.AdjustPartiallyClosedOrders( LiveOrders.Values.ToList(), HistoricalOrders.Values.ToList(), out _notResolved ); // // todo: load some more history if _notResolved > 0 _notResolved.Clear(); return(new PositionChangeImpl()); } var newPositionInfo = (PositionImpl)positionInfo; _tCount = newPositionInfo._tCount; _hCount = newPositionInfo._hCount; // Dictionary <long, IOrderInfo> liveOrders = new Dictionary <long, IOrderInfo>(LiveOrders); Dictionary <long, IOrderInfo> historicalOrders = new Dictionary <long, IOrderInfo>(HistoricalOrders); // var pc = new PositionChangeImpl(); var newLiveOrders = newPositionInfo.LiveOrders; foreach (var o in newLiveOrders.Values) { var ticket = o.Ticket(); IOrderInfo orderInfo; if (liveOrders.TryGetValue(o.Ticket(), out orderInfo)) { if (o.IsModified()) { pc.ModifiedOrders.Add(orderInfo.Merge(o)); } } else { pc.AddNewOrder(o); liveOrders.Add(ticket, o); } } foreach (var o in newPositionInfo.HistoricalOrders.Values) { // object ticket = new Integer(o.GetTicket()); var ticket = o.Ticket(); //IOrderInfo orderInfo = liveOrders.Remove(ticket); IOrderInfo orderInfo; if (liveOrders.TryGetValue(ticket, out orderInfo)) { liveOrders.Remove(ticket); pc.AddClosedOrDeletedOrder(orderInfo.Merge(o)); historicalOrders.Add(ticket, orderInfo); } else { IOrderInfo ho; if (historicalOrders.TryGetValue(ticket, out ho)) { ho.Merge(o); } else { // ?? we've missed some order ?? pc.AddClosedOrDeletedOrder(o); historicalOrders.Add(ticket, o); } } } // foreach (var o in from IOrderInfo o in liveOrders.Values where !newLiveOrders.ContainsKey(o.Ticket()) select o) { liveOrders.Remove(o.Ticket()); pc.AddClosedOrDeletedOrder(o); } // LiveOrders = liveOrders; HistoricalOrders = historicalOrders; // if (_notResolved != null) { foreach (var o in _notResolved) { Logger.Warn("PARTIALLY CLOSED order to resolve: " + o); pc.AddClosedOrDeletedOrder(o); } } _notResolved = pc.AdjustPartiallyClosedOrders(); _str = AsString(); // return(pc); }
static PositionInfo() { SceneServer.Instance.UpdateManager.InitStaticImpl(typeof(PositionInfo), typeof(PositionInfoDefaultImpl), o => { mImpl = (IPositionInfo)o; }); }
private static bool FindLastChange(IPositionInfo p) { return(p.EntryBarNum > 0); }
private ITypedElement GetResourceNavigator(out EvaluationContext evalContext) { string parseErrors2; var inputNavDSTU2 = FhirPathProcessor.GetResourceNavigatorDSTU2(textboxInputXML.Text, out parseErrors2); string parseErrors3; var inputNavSTU3 = FhirPathProcessor.GetResourceNavigatorSTU3(textboxInputXML.Text, out parseErrors3); string parseErrors4; var inputNavR4 = FhirPathProcessor.GetResourceNavigatorR4(textboxInputXML.Text, out parseErrors4); if (!string.IsNullOrEmpty(parseErrors2) || !string.IsNullOrEmpty(parseErrors3) || !string.IsNullOrEmpty(parseErrors4)) { ResetResults(); AppendResults(String.Join("\r\n--------------------\r\n", parseErrors2, parseErrors3, parseErrors4), true); } if (inputNavR4 != null || inputNavSTU3 != null || inputNavDSTU2 != null) { ISourceNode node; if (textboxInputXML.Text.StartsWith("{")) { node = Hl7.Fhir.Serialization.FhirJsonNode.Parse(textboxInputXML.Text); } else { node = Hl7.Fhir.Serialization.FhirXmlNode.Parse(textboxInputXML.Text); } _locations.Clear(); int lastPos = 0; IPositionInfo lastNode = null; AddLocations(node, ref lastNode, ref lastPos, textboxInputXML.Text.ToCharArray()); string t = _locations.LastOrDefault(c => c.Key < textboxInputXML.SelectionStart).Value; System.Diagnostics.Trace.WriteLine($"Focused: {t}"); } if (inputNavR4 != null) { btnR4.Visibility = Visibility.Visible; } else { btnR4.Visibility = Visibility.Collapsed; } if (inputNavSTU3 != null) { btnSTU3.Visibility = Visibility.Visible; } else { btnSTU3.Visibility = Visibility.Collapsed; } if (inputNavDSTU2 != null) { btnDSTU2.Visibility = Visibility.Visible; } else { btnDSTU2.Visibility = Visibility.Collapsed; } if (inputNavR4 != null) { evalContext = new fp4.FhirEvaluationContext(inputNavR4); return(inputNavR4); } if (inputNavSTU3 != null) { evalContext = new fp3.FhirEvaluationContext(inputNavSTU3); return(inputNavSTU3); } evalContext = new fp2.FhirEvaluationContext(inputNavDSTU2); return(inputNavDSTU2); }
// Compute initial borders, fixed or not - but only "set" the fixed positions as // we let the ConstraintGenerator actually do that. internal void ComputeInitialBorders() { if (this.IsEmpty || this.HasDesiredPos) { return; } // Some verifications won't work if we've got more than one cluster with fixed // borders - so they'll check this and skip those checks. if (this.LeftBorderInfo.IsFixedPosition || this.RightBorderInfo.IsFixedPosition) { ++numClustersWithFixedBordersH; } if (this.TopBorderInfo.IsFixedPosition || this.BottomBorderInfo.IsFixedPosition) { ++numClustersWithFixedBordersV; } // Get the minimum variable positions. IPositionInfo posLeft = 0 == this.variableDefs.Count ? null : this.variableDefs[0]; IPositionInfo posRight = posLeft; IPositionInfo posTop = posLeft; IPositionInfo posBottom = posLeft; if (null != posLeft) { foreach (VariableDef varDef in this.variableDefs) { if (varDef.DesiredPosX < posLeft.DesiredPosX) { posLeft = varDef; } if (varDef.DesiredPosX > posRight.DesiredPosX) { posRight = varDef; } if (varDef.DesiredPosY < posTop.DesiredPosY) { posTop = varDef; } if (varDef.DesiredPosY > posBottom.DesiredPosY) { posBottom = varDef; } } // endfor each variable } // Get the minimum cluster positions. foreach (ClusterDef clusDef in this.clusterDefs) { clusDef.ComputeInitialBorders(); if (null == posLeft) { // We had no variables so initialize with the first OlapCluster. posLeft = clusDef; posRight = posLeft; posTop = posLeft; posBottom = posLeft; continue; } // Because child clusters have already evaluated their borders from their outer variables // as we've done above, compare the outer borders of child clusters rather than their DesiredX. if (clusDef.InitialLeft < posLeft.InitialLeft) { posLeft = clusDef; } if (clusDef.InitialRight > posRight.InitialRight) { posRight = clusDef; } if (clusDef.InitialTop < posTop.InitialTop) { posTop = clusDef; } if (clusDef.InitialBottom > posBottom.InitialBottom) { posBottom = clusDef; } } // Compute our initial positions based upon variable boundaries. Validate.IsNotNull(posLeft, "posLeft should not be null as we checked for IsEmpty above"); // ReSharper disable PossibleNullReferenceException this.SizeX = posRight.InitialRight - posLeft.InitialLeft; this.SizeY = posBottom.InitialBottom - posTop.InitialTop; // ReSharper restore PossibleNullReferenceException this.DesiredPosX = posLeft.InitialLeft + (this.SizeX / 2); this.DesiredPosY = posTop.InitialTop + (this.SizeY / 2); //// // Compute our fixed borders from the outer variables. For this, we set the fixed border's // position such that its inner edge is adjacent to the outer edge of the outermost variable // in that direction. Note that we do *not* set it to the outermost edge of all variables; // the outermost edge may belong to a variable whose position (midpoint) is inside that of // another variable, in which case the variable with the outermost edge would move inward, // leaving more than the minimally-satisfying space between the border and the variable that // ends up being outermost. For example: // ++ +-------+ // || | A | // ||+---------------------------+ // ||| B | // ||+---------------------------+ // || | | // ++ +-------+ // Nodes A and B are labelled at their midpoints. Node B has the leftmost edge, but during // solving, it will be moved right to resolve the overlap with A (ignore the fact that in // this diagram it would actually be moved up instead because of deferral to Vertical would // result in less movement; drawing it this way makes it easier to understand the diagram). // If we'd started the border at the left of B, where it is in this diagram, Solve() could // leave the space between the border and A to be greater than PaddingX, and thus the // Y-pass generation would generate an X position closer to A, causing us to run afoul of the // Assert in PostY(). (This is not an issue for non-fixed borders, because ConstraintGenerator // forces their positions initially to be at the opposite side; thus the Solver will force // them to move across the cluster to the point at which they minimally satisfy the constraints). // // Unfortunately it turns out that we cannot rely on this when we have nested clusters due to // the following case (=== is cluster, --- is node): // +=====================================+ // | +-----+ | // | | A | | // |+===================================+| // ||+---+ +---+|| // ||| C | | B ||| // ||+---+ +---+|| // |+===================================+| // | | | | // | +-----+ | // +=====================================+ // Node A is in the parent cluster, nodes B and C in the nested OlapCluster. This will generate // constraints to move A to the right of the nested cluster's right border, which will in turn // move B to the left if it's an unfixed border (which will have a lighter weight). Thus A // stays where it is, B and the nested cluster's right border move to the left of A, and we are // left with extra space between A and the right border of the parent OlapCluster. So we will // end up skipping this check in PostY() for fixed borders if there are nested clusters. // // Note that all the foregoing is just for predictability for testing purposes; for live runs, // they can put the fixed border anywhere and the variables will follow them. //// LeftBorderInfo = ComputeFixedBorder(LeftBorderInfo, posLeft.InitialLeft); RightBorderInfo = ComputeFixedBorder(RightBorderInfo, posRight.InitialRight); TopBorderInfo = ComputeFixedBorder(TopBorderInfo, posTop.InitialTop); BottomBorderInfo = ComputeFixedBorder(BottomBorderInfo, posBottom.InitialBottom); if (TestGlobals.VerboseLevel >= 3) { WriteLine("Cluster {0} initially computed borders (padding not included):", this.ClusterId); WriteLine(" LeftBorder ({0} {1}): {2} InitialX {3} SizeX {4}", posLeft.ClassName, posLeft.InstanceId, ComputeInitialBorder(LeftBorderInfo, this.InitialLeft), this.DesiredPosX, this.SizeX); WriteLine(" RightBorder ({0} {1}): {2}", posRight.ClassName, posRight.InstanceId, ComputeInitialBorder(RightBorderInfo, this.InitialRight)); WriteLine(" TopBorder ({0} {1}): {2} InitialY {3} SizeY {4}", posTop.ClassName, posTop.InstanceId, ComputeInitialBorder(TopBorderInfo, this.InitialTop), this.DesiredPosY, this.SizeY); WriteLine(" BottomBorder ({0} {1}): {2}", posBottom.ClassName, posBottom.InstanceId, ComputeInitialBorder(BottomBorderInfo, this.InitialBottom)); } } // end ComputeFixedBorders()
/// <summary> /// A dialog (window) just off the edge (xpos+width) of its parent dialog(window), the y-axis can be altered via yOffset. /// TODO: It should probably be possible to change the width(/height) of the dialog. /// </summary> /// <param name="dlgService"></param> /// <param name="posInfo"></param> /// <param name="yOffset">Determines how far from the top the dialog will appear in y-axis</param> /// <param name="startValue">The value the textbox should have when opening dialog</param> public IntegerTextBoxDialogViewModel(IDialogService dlgService, IPositionInfo posInfo, double yOffset, int startValue) : this(dlgService, posInfo, yOffset) { this.startValue = startValue + string.Empty; TextBoxText = this.startValue; }