Пример #1
0
        public void tdSink_ITradeDeskEvents_Event_OnRowChanged(object tableDisp, string rowID)
        {
            if (_manager.LoggedIn)
            {
                try
                {
                    FXCore.ITableAut t = (FXCore.ITableAut)tableDisp;

                    if ("offers".Equals(t.Type))
                    {
                        DataTick dataTick    = new DataTick();
                        TableAut offersTable = (TableAut)_manager.Desk.FindMainTable("offers");

                        RowAut instrumentRow = (RowAut)offersTable.FindRow("OfferID", rowID, 0);
                        dataTick.Ask      = (decimal)((double)instrumentRow.CellValue("Ask"));
                        dataTick.Bid      = (decimal)((double)instrumentRow.CellValue("Bid"));
                        dataTick.DateTime = (DateTime)instrumentRow.CellValue("Time");

                        PostQuoteUpdate((string)instrumentRow.CellValue("Instrument"), dataTick);

                        // TODO: this may be way too often, since it will update on each tick of any symbol...
                        // Also update the accounts informations.
                        foreach (AccountInfo accountInfo in _manager.Orders.GetAvailableAccounts())
                        {
                            _orderExecutionStub.UpdateAccountInfo(accountInfo);
                        }
                    }
                }
                catch (System.Exception ex)
                {
                    SystemMonitor.Error(ex.ToString());
                }
            }
        }
        /// <summary>
        /// Managed thread entrance only.
        /// </summary>
        void Managed_tdSink_ITradeDeskEvents_Event_OnRowChanged(object tableDisp, string rowID)
        {
            if (LoggedIn)
            {
                TradeDeskAut desk = _desk;
                if (desk == null)
                {
                    return;
                }

                try
                {
                    FXCore.ITableAut t = (FXCore.ITableAut)tableDisp;
                    if ("offers".Equals(t.Type))
                    {
                        TableAut offersTable   = (TableAut)desk.FindMainTable("offers");
                        RowAut   instrumentRow = (RowAut)offersTable.FindRow("OfferID", rowID, 0);

                        DataTick dataTick = new DataTick();
                        dataTick.Ask      = (decimal)((double)instrumentRow.CellValue("Ask"));
                        dataTick.Bid      = (decimal)((double)instrumentRow.CellValue("Bid"));
                        dataTick.DateTime = (DateTime)instrumentRow.CellValue("Time");

                        QuoteUpdateDelegate delegateInstance = QuoteUpdatedEvent;
                        if (delegateInstance != null)
                        {
                            GeneralHelper.FireAndForget(delegateInstance, this, (string)instrumentRow.CellValue("Instrument"), dataTick);
                        }
                    }
                    else if ("orders".Equals(t.Type))
                    {
                        // Orders table empty?
                        //TableAut offersTable = (TableAut)desk.FindMainTable("orders");
                        //RowAut instrumentRow = (RowAut)offersTable.FindRow("OrderID", rowID, 0);

                        //string accountId;
                        //OrderInfo? info = Managed_ExtractOrderInfo(instrumentRow, out accountId);

                        //OrderUpdateDelegate delegateInstance = OrderUpdatedEvent;
                        //if (info.HasValue && delegateInstance != null)
                        //{
                        //    GeneralHelper.FireAndForget(delegateInstance, this, accountId, info.Value);
                        //}
                    }
                    else if ("accounts".Equals(t.Type))
                    {
                        ItemUpdateDelegate delegateInstance = AccountUpdatedEvent;
                        if (delegateInstance != null)
                        {
                            GeneralHelper.FireAndForget(delegateInstance, this, rowID);
                        }
                    }
                }
                catch (System.Exception ex)
                {
                    SystemMonitor.Error("Failed to handle OnRow event", ex);
                }
            }
        }
        /// <summary>
        /// Helper, convert to known order information.
        /// </summary>
        /// <returns></returns>
        OrderInfo?Managed_ExtractOrderInfo(RowAut orderInstrumentRow, out string accountId)
        {
            accountId = (string)orderInstrumentRow.CellValue("AccountID");
            OrderInfo info = new OrderInfo();


            return(null);
        }
Пример #4
0
        public bool ExecuteMarketOrder(AccountInfo accountInfo, Symbol symbol, OrderTypeEnum orderType, int volume, decimal?allowedSlippage, decimal?desiredPrice, decimal?takeProfit, decimal?stopLoss, string comment, out OrderInfo?orderPlaced, out string operationResultMessage)
        {
            operationResultMessage = string.Empty;
            string operationResultMessageCopy = string.Empty;
            object orderId, psd;

            bool isBuy = OrderInfo.TypeIsBuy(orderType);

            OrderInfo?order = null;

            GeneralHelper.GenericReturnDelegate <bool> operationDelegate = delegate()
            {
                _manager.Desk.OpenTrade(accountInfo.Id, symbol.Name, isBuy, _adapter.DefaultLotSize, (double)desiredPrice.Value, (string)_adapter.GetInstrumentData(symbol.Name, "QuoteID"), 0, (double)stopLoss.Value, (double)takeProfit.Value, 0, out orderId, out psd);

                order = new OrderInfo();
                OrderInfo tempOrder = order.Value;
                tempOrder.Id = orderId.ToString();

                TableAut accountsTable = (FXCore.TableAut)_manager.Desk.FindMainTable("trades");

                RowAut item = (RowAut)accountsTable.FindRow("OrderID", orderId, 0);

                return(true);
            };

            orderPlaced = order;

            object result;

            if (_messageLoopOperator.Invoke(operationDelegate, TimeSpan.FromSeconds(8), out result) == false)
            {            // Timed out.
                operationResultMessage = "Timeout submiting order.";
                return(false);
            }

            if (string.IsNullOrEmpty((string)result))
            {            // Operation error.
                operationResultMessage = operationResultMessageCopy;
                return(false);
            }

            return(true);
        }
        /// <summary>
        /// Helper, convert to known order information.
        /// </summary>
        /// <returns></returns>
        OrderInfo? Managed_ExtractOrderInfo(RowAut orderInstrumentRow, out string accountId)
        {
            accountId = (string)orderInstrumentRow.CellValue("AccountID");
            OrderInfo info = new OrderInfo();

            return null;
        }