Beispiel #1
0
        /// <summary>
        /// 通知成交價
        /// </summary>
        private static void MrWangConnection_OnMatchInfo(Match match)
        {
            foreach (var orders in listOCO)
            {
                if (orders.Item1.Price >= match.MatchPrice)
                {
                    MrWangConnection.SnedOrder(orders.Item1);
                    listOCORemove.Add(orders);
                }
                else if (orders.Item2.Price <= match.MatchPrice)
                {
                    MrWangConnection.SnedOrder(orders.Item2);
                    listOCORemove.Add(orders);
                }
            }

            if (listOCORemove.Count > 0)
            {
                foreach (var orders in listOCORemove)
                {
                    listOCO.Remove(orders);
                }

                listOCORemove.Clear();
            }
        }
Beispiel #2
0
 /// <summary>
 /// 通知成交價
 /// </summary>
 private static void MrWangConnection_OnMatchInfo(Match match)
 {
     Console.ForegroundColor = ConsoleColor.White;
     Console.WriteLine($"{match.Symbol} Last:{match.MatchPrice}");
     foreach (var order in orders.ToArray())
     {
         if (order.Symbol == match.Symbol)
         {
             if (order.Side == SideEnum.Buy)
             {
                 if (match.MatchPrice >= order.Price)
                 {
                     order.TimeInForce = TimeInForceEnum.ROD;
                     order.OrderType   = OrderTypeEnum.otLimit;
                     MrWangConnection.SnedOrder(order);
                     orders.Remove(order);
                 }
             }
             else if (order.Side == SideEnum.Sell)
             {
                 if (match.MatchPrice <= order.Price)
                 {
                     order.TimeInForce = TimeInForceEnum.ROD;
                     order.OrderType   = OrderTypeEnum.otLimit;
                     MrWangConnection.SnedOrder(order);
                     orders.Remove(order);
                 }
             }
             else
             {
                 Console.WriteLine("Error");
             }
         }
     }
 }
Beispiel #3
0
        private static void SendOrder(QuoteOrder quoteOrder)
        {
            var bidOrder = new Order()
            {
                Side        = SideEnum.Buy,
                Symbol      = quoteOrder.Symbol,
                Qty         = quoteOrder.BidQty,
                Price       = quoteOrder.Bid,
                TimeInForce = TimeInForceEnum.ROD,
                OrderType   = OrderTypeEnum.otLimit,
            };

            quoteOrder.BidOrderBook = MrWangConnection.SnedOrder(bidOrder);

            var AskOrder = new Order()
            {
                Side        = SideEnum.Sell,
                Symbol      = quoteOrder.Symbol,
                Qty         = quoteOrder.AskQty,
                Price       = quoteOrder.Ask,
                TimeInForce = TimeInForceEnum.ROD,
                OrderType   = OrderTypeEnum.otLimit,
            };

            quoteOrder.AskOrderBook = MrWangConnection.SnedOrder(AskOrder);
        }
Beispiel #4
0
 /// <summary>
 /// 通知登入結果事件
 /// </summary>
 private static void MrWangConnection_OnLogonReply(int Code, string Msg)
 {
     if (Code == 0)
     {
         //登入成功
         Console.WriteLine("登入成功。");
         Console.WriteLine("訂閱商品TXFD9。");
         //地4步 訂閱報價
         MrWangConnection.SubscribeQuote("TXFD9");
         //產生下單物件
         Order order = new Order();
         {
             order.Symbol      = "TXFD9";
             order.Side        = SideEnum.Buy;
             order.Price       = 10700;
             order.Qty         = 1;
             order.OrderType   = OrderTypeEnum.otLimit;
             order.TimeInForce = TimeInForceEnum.IOC;
         };
         MrWangConnection.SnedOrder(order);
     }
     else
     {
         //登入失敗
         Console.WriteLine($"Code:{Code} Msg:{Msg}");
     }
 }
Beispiel #5
0
        private static void BuyThreshold(double Price, Match match, int pos)
        {
            if (match.MatchPrice >= Price)
            {
                Order order = new Order()
                {
                    Symbol      = "TXFD9",
                    Side        = SideEnum.Buy,
                    Qty         = 1,
                    Price       = match.MatchPrice,
                    OrderType   = OrderTypeEnum.otMarket,
                    TimeInForce = TimeInForceEnum.IOC,
                };

                if (Position <= pos)
                {
                    Position++;
                    MrWangConnection.SnedOrder(order);
                }
            }
        }
Beispiel #6
0
 public string SendOrder(Order order)
 {
     return(MrWangConnection.SnedOrder(order));
 }
Beispiel #7
0
        /// <summary>
        /// 通知成交價
        /// </summary>
        private static void MrWangConnection_OnMatchInfo(Match match)
        {
            if (Position == 99)
            {
                return;
            }

            if (match.MatchPrice >= 10895)
            {
                Order order = new Order()
                {
                    Symbol      = "TXFD9",
                    Side        = SideEnum.Buy,
                    Qty         = 1,
                    Price       = match.MatchPrice,
                    OrderType   = OrderTypeEnum.otMarket,
                    TimeInForce = TimeInForceEnum.IOC,
                };

                if (Position <= 0)
                {
                    Position++;
                    MrWangConnection.SnedOrder(order);
                }
            }
            else if (match.MatchPrice <= 10843)
            {
                Order order = new Order()
                {
                    Symbol      = "TXFD9",
                    Side        = SideEnum.Sell,
                    Qty         = 1,
                    Price       = match.MatchPrice,
                    OrderType   = OrderTypeEnum.otMarket,
                    TimeInForce = TimeInForceEnum.IOC,
                };

                if (Position >= 0)
                {
                    Position--;
                    MrWangConnection.SnedOrder(order);
                }
            }

            if (match.Time == "13:44:00")
            {
                if (Position > 0)
                {
                    Position = 99;
                    Order order = new Order()
                    {
                        Symbol      = "TXFD9",
                        Side        = SideEnum.Sell,
                        Qty         = 1,
                        Price       = match.MatchPrice,
                        OrderType   = OrderTypeEnum.otMarket,
                        TimeInForce = TimeInForceEnum.IOC,
                    };
                    MrWangConnection.SnedOrder(order);
                }
                else if (Position < 0)
                {
                    Position = 99;

                    Order order = new Order()
                    {
                        Symbol      = "TXFD9",
                        Side        = SideEnum.Buy,
                        Qty         = 1,
                        Price       = match.MatchPrice,
                        OrderType   = OrderTypeEnum.otMarket,
                        TimeInForce = TimeInForceEnum.IOC,
                    };

                    MrWangConnection.SnedOrder(order);
                }
            }
        }
Beispiel #8
0
 private static void SendTimeCancelOrder(CanceledOrder canceledOrder)
 {
     canceledOrder.OrderBook = MrWangConnection.SnedOrder(canceledOrder);
     listTimeCancel.Add(canceledOrder);
 }
Beispiel #9
0
        /// <summary>
        /// 通知成交價
        /// </summary>
        private static void MrWangConnection_OnMatchInfo(Match match)
        {
            listAVG10Price.Add(match.MatchPrice);
            listAVG20Price.Add(match.MatchPrice);
            listAVG30Price.Add(match.MatchPrice);
            if (listAVG10Price.Count > 10)
            {
                listAVG10Price.RemoveAt(0);
            }
            if (listAVG20Price.Count > 30)
            {
                listAVG20Price.RemoveAt(0);
            }
            if (listAVG30Price.Count > 50)
            {
                listAVG30Price.RemoveAt(0);
            }

            double AVG10Price = Math.Round(listAVG10Price.Average(x => x), 0);
            double AVG20Price = Math.Round(listAVG20Price.Average(x => x), 0);
            double AVG30Price = Math.Round(listAVG30Price.Average(x => x), 0);

            if (AVG10Price > AVG20Price && AVG20Price > AVG30Price)
            {
                Console.ForegroundColor = ConsoleColor.Red;

                Order order = new Order()
                {
                    Symbol      = "TXFD9",
                    Side        = SideEnum.Buy,
                    Qty         = 1,
                    Price       = match.MatchPrice,
                    OrderType   = OrderTypeEnum.otMarket,
                    TimeInForce = TimeInForceEnum.IOC,
                };

                if (Position <= 0)
                {
                    Position++;
                    MrWangConnection.SnedOrder(order);
                }
            }
            else if (AVG10Price < AVG20Price && AVG20Price < AVG30Price)
            {
                Console.ForegroundColor = ConsoleColor.Green;

                Order order = new Order()
                {
                    Symbol      = "TXFD9",
                    Side        = SideEnum.Sell,
                    Qty         = 1,
                    Price       = match.MatchPrice,
                    OrderType   = OrderTypeEnum.otMarket,
                    TimeInForce = TimeInForceEnum.IOC,
                };

                if (Position >= 0)
                {
                    Position--;
                    MrWangConnection.SnedOrder(order);
                }
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.White;
            }

            //Console.WriteLine($"{match.Time} -> Symbol:{match.Symbol}" +
            //$" Last:{match.MatchPrice} x {match.MatchQty}" +
            //$" Volume:{match.Volume} AVG10:{AVG10Price} AVG20:{AVG20Price} AVG30:{AVG30Price}");
        }