Exemple #1
0
        private void RunStrategy()
        {
            UpdateAccountDetails();
            if (IsEnoughPositionToTrade())
            {
                for (var iPos = ((OandaAccount)this.CurrentAccount).PositionList.Count - 1; iPos >= 0; --iPos)
                {
                    this.StockObject = ((OandaAccount)this.CurrentAccount).PositionList[iPos];
                    posConfig        = this.GetPositionConfig(this.StockObject.Symbol);

                    if (IsReadyToSell())
                    {
                        if (PlaceSellOrder()) // Do we need to call account update here?
                        {
                            Console.WriteLine(this.StockObject.Symbol + " Sold at " + this.StockObject.SellPrice.ToString());
                        }
                    }
                    else
                    {
                        if (posConfig.TradeProcess)
                        {
                            ProcessTrade(); //Account update has an impact on position list becaus of closed positions
                        }
                        if (IsReadyToAddMore())
                        {
                            AddMoreStocks(); //Account update has an impact on position list becaus of closed positions
                        }
                    }
                }
            }
            else
            {
                AddEnoughPositions();
            }
        }
Exemple #2
0
        private void AddEnoughPositions()
        {
            Order          orderObject = null;
            PositionConfig pConfig     = null;

            try
            {
                IEnumerable <Quote> quoteList = ExchangeObject.GetQuoteList(null, this.CurrentAccount.Id);   //Service call 3  - Initially once and whenever new position added to account based on Max pos count
                foreach (Quote q in quoteList)
                {
                    if (!IsSymbolAlreadyAvailable(q.Symbol))
                    {
                        pConfig = this.GetPositionConfig(q.Symbol);
                        if (pConfig != null)
                        {
                            if (pConfig.InitialUnits > pConfig.MinQuantity)
                            {
                                if (this.CurrentAccount.Type == "Long")
                                {
                                    orderObject = new Order(q.Symbol, pConfig.InitialUnits, q.LastBuyTradePrice, Constants.OrderAction.BUY, this.OrderType);
                                }
                                else if (this.CurrentAccount.Type == "Short")
                                {
                                    orderObject = new Order(q.Symbol, pConfig.InitialUnits, q.LastSellTradePrice, Constants.OrderAction.SELL, this.OrderType);
                                }

                                if (ExchangeObject.PlaceOrder(orderObject, this.CurrentAccount.Id))   //Service call 4
                                {
                                    if (orderObject.Status == Constants.OrderState.FILLED)
                                    {
                                        DataAnalyzer dt        = new DataAnalyzer(orderObject.Symbol, this.CurrentAccount.Id, this.CurrentAccount.Type);
                                        Thread       newThread = new Thread(dt.SaveActiveTicker);
                                        newThread.Name = "AnalyzerAdd";
                                        newThread.Start();
                                    }
                                    else if (orderObject.Status == Constants.OrderState.PENDING)
                                    {
                                        Console.WriteLine(DateTime.Now + " : Order status " + Constants.OrderState.PENDING);
                                    }
                                    else if (orderObject.Status == Constants.OrderState.CANCELLED)
                                    {
                                        Console.WriteLine(DateTime.Now + " : Order status " + Constants.OrderState.CANCELLED);
                                    }
                                    if (((OandaAccount)this.CurrentAccount).PositionList.Count >= this.MaxPositionCount)
                                    {
                                        return;
                                    }
                                }
                            }
                        }
                    }
                }
                return;
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Exemple #3
0
 protected Form()
 {
     SuspendLayout();
     AutoScaleMode = AutoScaleMode.Font;
     PositionConfig = new PositionConfig(GetFileName)
     {
         Target = this
     };
     ResumeLayout(true);
 }
        protected UserConfig GetUserConfig(string symbol)
        {
            UserConfig uConfig = null;

            for (int i = 0; i < UserConfigList.Count(); i++)
            {
                PositionConfig pos = UserConfigList[i].BuyList.Find(x => x.Symbol == symbol);
                if (pos != null)
                {
                    return(UserConfigList[i]);
                }
            }
            return(uConfig);
        }
Exemple #5
0
        protected View(string configFileName = null)
        {
            Frame = new Form
            {
                Name = "Frame",
                Text = "?"
            };

            Frame.Closing += OnClosing;

            if(configFileName == null)
                configFileName = GetFileName();
            configFileName.FileHandle().AssumeDirectoryOfFileExists();

            PositionConfig = new PositionConfig(()=> configFileName)
            {
                Target = Frame
            };
        }
Exemple #6
0
        protected void SetPosition( Bean.BoxBean bean )
        {
            FormFloorList form = new FormFloorList("选择层架");
            form.Text = "请选择所属层架 档案盒:"+  bean.name;
            form.WindowState = FormWindowState.Normal;
            form.StartPosition = FormStartPosition.CenterParent;
            DialogResult result = form.ShowDialog();
            if (result != System.Windows.Forms.DialogResult.OK) return;

            Bean.FloorBean floor = form.SelectedFloorLabel;
            if (floor == null) return;

            if (backgroundWorker3.IsBusy) return;

            panelLoading.Visible = true;
            panelLoading.BringToFront();
            panelLoading.Location = new Point((this.Width / 2 - this.panelLoading.Width / 2), this.Height / 2 - this.panelLoading.Height - 20);
            lblLoadingText.Text = "正在请求设置层架操作,请稍等......";

            PositionConfig config = new PositionConfig();
            config.floorrfid = floor.rfid;
            config.boxrfid = bean.rfid;

            backgroundWorker3.RunWorkerAsync(config);

        }
 public TreeForm()
 {
     InitializeComponent();
     _positionConfig = new PositionConfig {Target = this};
 }
Exemple #8
0
        /// <exception cref="NotAvailableException">Channel object is no longer available.</exception>
        /// <exception cref="BassErrorException">
        ///     Some error occur to call a Bass function, check the error code and error message
        ///     to get more error information.
        /// </exception>
        /// <exception cref="BassNotLoadedException">
        ///     Bass DLL not loaded, you must use <see cref="BassManager.Initialize" /> to
        ///     load Bass DLL first.
        /// </exception>
        UInt64 IChannelInternal.GetLength(PositionConfig config)
        {
            CheckAvailable();

            return ChannelModule.ChannelGetLengthFunction.CheckResult(
                ChannelModule.ChannelGetLengthFunction.Delegate(Handle, config));
        }
Exemple #9
0
        /// <exception cref="NotAvailableException">Channel object is no longer available.</exception>
        /// <exception cref="BassErrorException">
        ///     Some error occur to call a Bass function, check the error code and error message
        ///     to get more error information.
        /// </exception>
        /// <exception cref="BassNotLoadedException">
        ///     Bass DLL not loaded, you must use <see cref="BassManager.Initialize" /> to
        ///     load Bass DLL first.
        /// </exception>
        void IChannelInternal.SetPosition(PositionConfig config, ulong value)
        {
            CheckAvailable();

            ChannelModule.ChannelSetPositionFunction.CheckResult(
                ChannelModule.ChannelSetPositionFunction.Delegate(Handle, value, config));
        }