Пример #1
0
        void UpdateAccounts()
        {
            OrderExecutionSourceStub stub    = _stub;
            FXCMConnectionManager    manager = Manager;

            if (stub == null || manager == null)
            {
                return;
            }

            // The newly produced accounts have no Guids.
            List <AccountInfo> accounts = manager.GetAvailableAccounts(IntegrationAdapter.AdvisedAccountDecimalsPrecision);

            foreach (AccountInfo info in accounts)
            {// Update / insert accounts.
                AccountInfo actualInfo = info;

                AccountInfo?existingInfo = stub.GetAccountInfo(info.Id);
                if (existingInfo.HasValue == false)
                {// New info, assign a Guid.
                    actualInfo.Guid = Guid.NewGuid();
                }
                else
                {
                    actualInfo.Guid = existingInfo.Value.Guid;
                }

                stub.UpdateAccountInfo(actualInfo);
            }
        }
Пример #2
0
        /// <summary>
        /// Make sure to call on Invoke'd thread.
        /// </summary>
        /// <param name="account"></param>
        void PerformUpdate(MbtAccount account, bool updateAccount, bool updateOrders, bool updatePositions)
        {
            //SystemMonitor.CheckError(_messageLoopOperator.InvokeRequred == false, "Invoke must not be required in baseMethod call.");

            MbtOrderClient             orderClient = _orderClient;
            MBTradingConnectionManager manager     = _manager;
            MBTradingQuote             quotes      = null;

            if (orderClient == null || manager == null)
            {
                return;
            }

            quotes = manager.Quotes;
            if (quotes == null)
            {
                return;
            }

            AccountInfo info;
            Dictionary <string, OrderInfo> pendingOrderInfos = new Dictionary <string, OrderInfo>();
            List <PositionInfo>            positionsInfos    = new List <PositionInfo>();

            lock (this)
            {
                if (updateOrders)
                {
                    // We need to send up only the latest of each orders histories, since prev ones are for previous states.
                    foreach (MbtOrderHistory history in _orderClient.OrderHistories)
                    {
                        Order.UpdateTypeEnum updateType;
                        OrderInfo?           orderInfo = ConvertToOrderInfo(history, out updateType);
                        if (orderInfo.HasValue)
                        {
                            pendingOrderInfos[orderInfo.Value.Id] = orderInfo.Value;
                        }
                    }

                    // Make sure open orders orderInfo is always on top.
                    foreach (MbtOpenOrder pOrd in _orderClient.OpenOrders)
                    {
                        OrderInfo?orderInfo = ConvertToOrderInfo(pOrd);
                        if (orderInfo.HasValue)
                        {
                            pendingOrderInfos[orderInfo.Value.Id] = orderInfo.Value;
                        }
                    }
                }

                if (updatePositions)
                {
                    foreach (MbtPosition position in _orderClient.Positions)
                    {
                        PositionInfo?positionInfo = ConvertToPositionInfo(position);
                        if (positionInfo.HasValue)
                        {
                            positionsInfos.Add(positionInfo.Value);
                        }
                    }
                }

                if (_accountInfo.HasValue)
                {
                    info = _accountInfo.Value;
                }
                else
                {
                    info      = new AccountInfo();
                    info.Guid = Guid.NewGuid();
                }

                ConvertAccount(account, ref info);

                _accountInfo = info;
            }

            MBTradingAdapter adapter = _adapter;

            if (adapter != null)
            {
                OrderExecutionSourceStub stub = adapter.OrderExecutionSourceStub;
                if (stub != null)
                {
                    if (updateAccount)
                    {
                        stub.UpdateAccountInfo(_accountInfo.Value);
                    }

                    if (updateOrders)
                    {
                        stub.UpdateOrdersInfo(_accountInfo.Value,
                                              GeneralHelper.GenerateSingleValueArray <Order.UpdateTypeEnum>(pendingOrderInfos.Count, Order.UpdateTypeEnum.Update),
                                              GeneralHelper.EnumerableToArray <OrderInfo>(pendingOrderInfos.Values));
                    }

                    if (updatePositions)
                    {
                        stub.UpdatePositionsInfo(_accountInfo.Value, positionsInfos.ToArray());
                    }
                }
            }
        }