Ejemplo n.º 1
0
        public double startTrade()
        {
            if (recordList == null)
            {
                recordList = new List <OriginalRecord>();
            }
            RecordScanner.setRecordList(recordList);

            if (this.coreMethod.Equals(Core_Method_1))
            {
                return(coreLogic());
            }
            else
            {
                throw new Exception("沒有設定Core Method!!");
            }
        }
Ejemplo n.º 2
0
        private Boolean dealSellOrBuy(OriginalRecord record, DateTime tradeDateTime)//決定買或賣的方向,回傳値代表計算成功或是失敗
        {
            try
            {
                sellOrBuyCheckPeriod = new int[checkCount];

                int baseTimePeriod = 5;

                int[] basePrice = new int[checkCount];

                minuteBeforeTradeTime = new DateTime[checkCount];

                int[] direction = new int[checkCount];


                for (int i = 0; i < checkCount; i++)
                {
                    direction[i] = -1;

                    sellOrBuyCheckPeriod[i] = baseTimePeriod;

                    baseTimePeriod += 5;

                    minuteBeforeTradeTime[i] = tradeDateTime.AddSeconds(0 - sellOrBuyCheckPeriod[i]);

                    debugMsg("minuteBeforeTradeTime[" + i + "]:" + minuteBeforeTradeTime[i]);
                }

                for (int i = 0; i < checkCount; i++)
                {
                    try
                    {
                        befofeRecord = RecordScanner.getRecordMinuteBeforeOrAfter(minuteBeforeTradeTime[i]);//XX鐘前的交易紀錄

                        if (befofeRecord == null)
                        {
                            return(false);
                        }
                        basePrice[i] = befofeRecord.TradePrice;//交易基準

                        debugMsg("basePrice:" + i + ":" + basePrice[i]);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("掃描失敗:" + e.Message + "---" + e.StackTrace + "---" + e.Source);
                    }
                }//end for

                for (int i = 0; i < checkCount; i++)
                {
                    if (record.TradePrice > basePrice[i])//目前交易金額大於XX分鐘前的交易金額
                    {
                        direction[i] = TradeType.BUY.GetHashCode();
                    }
                    else if (record.TradePrice < basePrice[i])//目前交易金額小於XX分鐘前的交易金額
                    {
                        direction[i] = TradeType.SELL.GetHashCode();
                    }

                    //if (i == 0)
                    //{
                    //    if (record.TradePrice > basePrice[i])//目前交易金額大於XX分鐘前的交易金額
                    //    {
                    //        direction[i] = TradeType.BUY.GetHashCode();
                    //    }
                    //    else if (record.TradePrice < basePrice[i])//目前交易金額小於XX分鐘前的交易金額
                    //    {
                    //        direction[i] = TradeType.SELL.GetHashCode();
                    //    }
                    //}
                    //else
                    //{
                    //    if (basePrice[i - 1] > basePrice[i])//目前交易金額大於XX分鐘前的交易金額
                    //    {
                    //        direction[i] = TradeType.BUY.GetHashCode();
                    //    }
                    //    else if (basePrice[i - 1] < basePrice[i])//目前交易金額小於XX分鐘前的交易金額
                    //    {
                    //        direction[i] = TradeType.SELL.GetHashCode();
                    //    }
                    //}
                }

                for (int i = checkCount - 1; i > 0; i--)
                {
                    if (direction[i] != direction[i - 1])
                    {
                        return(false);
                    }
                }

                if (direction[0] == -1)//五個時間的價位都一樣
                {
                    return(false);
                }

                nowTradeType = direction[0];

                for (int i = 0; i < checkCount; i++)
                {
                    debugMsg("direction[" + i + "]:" + direction[i]);
                }

                debugMsg("nowTradeType : " + nowTradeType);

                return(true);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Source);
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
            }

            return(false);
        }