public bool ValidatePosition(Position position)
        {
            bool isOkey = true;
            if (_positionHistory.Count == 0)
            {
                _positionHistory.Add(position);
            }
            else
            {
                Position last = _positionHistory.Last();
                if (last.Direct == position.Direct)
                {
                    log.Error("Dispather => Signal should have different direction!");
                    isOkey = false;
                }

                //if(last.Date.AddMinutes(10) > position.Date)
                //{
                //    log.Error("Dispather => New signal should be at least 10 min later!");
                //    isOkey = false;
                //}
                    
                //3. allow max 3-4 changes in 1 day

            }

            return isOkey;
        }
        public bool AddIfValid(Position pos)
        {
            bool result = true;

            if (ValidationEnabled)
                result = ValidatePosition(pos);

            if(result)
                AddPosition(pos);

            return result;
        }
Esempio n. 3
0
        private void ChangePosition(Position current)
        {
            manager.Main.Pos = current;
            signals.Add(current);

            if (_client != null) //if client connected, updated his GUI, and give him chance to break alert
            {
                _client.UpdateUIAccount(manager.Main);
                _client.AlertNewSignal(current);
            }

            Thread t = new Thread(() =>
            {
                _decisionMadeEvent.WaitOne(TimeSpan.FromSeconds(20));
                if (!LastSignalCancelled)
                {
                    UpdateAllAccounts(current);
                    LastSignalCancelled = false;
                }
            });
            t.SetApartmentState(ApartmentState.STA);
            t.Start();
        }
Esempio n. 4
0
        private Position AdjustPosition4Account(Account acc, Position newPos)
        {
            Position p = new Position(newPos.Size, newPos.Direct, newPos.Price, newPos.Date);
            if(acc.Pos.Size == 0)
                return p;

            p.Size = p.Size*2;

            return p;
        }
Esempio n. 5
0
        public void UpdateAllAccounts(Position p)
        {
            bool res = dispatcher.AddIfValid(p);
            if(!res)
                return;
            
            Position org = new Position(p.Size, p.Direct, p.Price, p.Date);
            using (BossaSpider spider = new BossaSpider())
            {
                foreach (Account acc in AccountsToSync)
                {
                    //adjust position to each account
                    p = AdjustPosition4Account(acc, org);
                    
                    spider.Login(acc);
                    bool compleated = spider.ChangePositionTo(p);
                    //mozna by sprawdzic czy sie wykonalo !!
                    //currect = spider.GetCurrention Position(); 
                    spider.Logout();

                    if(compleated)
                    {
                        acc.Pos = org;
                        FireAccountUpdated(acc); 
                    }
                    
                }
            }
        }
 public void AddPosition(Position position)
 {
     _positionHistory.Add(position);
 }
Esempio n. 7
0
        private void UpdateAllAccounts(Position toPosition)
        {
            manager.UpdateAllAccounts(toPosition);

            //przejdz do watku glownego!!
            UpdateUi("Zakonczono update kont");
        }