Example #1
0
        public bool RemoveParentOrderByID(int ID)
        {
            int idx = -1;

            ParentOrder parentOrder = GetParentOrderByParentID(ID);

            if (parentOrder == null)
            {
                return(false);
            }

            lock (locker)
            {
                //Cancel open orders for this parentOrder
                var openOrders = parentOrder.GetOpenOrders();
                TradeManager.Instance.CancelOrders(openOrders);
            }

            Thread.Sleep(2000);

            lock (locker)
            {
                if (Parent_Child_Order_Map.ContainsKey(ID))
                {
                    Parent_Child_Order_Map.Remove(ID);
                }

                List <int> remove = new List <int>();
                foreach (int childID in Child_Parent_Order_Map.Keys)
                {
                    if (Child_Parent_Order_Map[childID] == parentOrder.ID)
                    {
                        remove.Add(childID);
                    }
                }

                foreach (int item in remove)
                {
                    Child_Parent_Order_Map.Remove(item);
                }


                for (int i = 0; i < ParentOrderList.Count; i++)
                {
                    if (ParentOrderList[i].ID == ID)
                    {
                        idx = i;
                        break;
                    }
                }
                if (idx != -1)
                {
                    ParentOrderList.RemoveAt(idx);
                }
            }

            StateManager.Save();
            return(idx != -1);
        }
Example #2
0
        /// <summary>
        /// MExchangeテーブルの設定内容で初期化する
        /// </summary>
        public void InitializeExchange()
        {
            // 初期化
            // 資産情報
            CollateralList = InitializeDictionary(CollateralList);

            // 注文情報
            ParentOrderList = InitializeDictionary(ParentOrderList);
            ChildOrderList  = InitializeDictionary(ChildOrderList);

            // 建玉情報
            PositionList = InitializeDictionary(PositionList);

            // 取引所状態情報
            StateList = InitializeDictionary(StateList);

            // テクニカル管理
            TechnicalList = InitializeDictionary(TechnicalList);

            // クライアント
            Client = InitializeDictionary(Client);

            // パラメータ読み込み
            using (var db = new MExchangeDbContext(DbContextOptions))
            {
                // データを取得
                var mExchange = db.MExchange;

                foreach (var item in mExchange)
                {
                    if (item.Enabled == Enabled)
                    {
                        // 資産情報
                        CollateralList.Add(item.Id, new Collateral(new RawCollateral()));

                        // 注文情報
                        ParentOrderList.Add(item.Id, new List <Order>());
                        ChildOrderList.Add(item.Id, new List <Order>());

                        // 建玉情報
                        PositionList.Add(item.Id, new List <Position>());

                        // 取引所状態情報
                        StateList.Add(item.Id, new RawBoardState());

                        // テクニカル管理生成
                        Dictionary <int, PubnubManager> pubnub = null;
                        if (PubnubList.ContainsKey(item.Id))
                        {
                            pubnub = PubnubList[item.Id];
                        }
                        TechnicalList.Add(item.Id, new TechnicalManager(item.Id, pubnub, TimeScaleList, DbContextOptions, TechnicalList));

                        // 通信用クライアント生成
                        Client.Add(item.Id, new BitflyerClient(item.Id, DbContextOptions));
                    }
                }
            }
        }
Example #3
0
        public void AddParentOrder(ParentOrder parentOrder)
        {
            lock (locker)
            {
                ParentOrderList.Add(parentOrder);

                if (!Parent_Child_Order_Map.ContainsKey(parentOrder.ID))
                {
                    Parent_Child_Order_Map[parentOrder.ID] = new List <int>();
                }
            }
        }