示例#1
0
        internal static string CombinedBarsRangeTime(string symbol, BarPeriod barPeriod, DateTime startTime, DateTime endTime, double barCountDbl)
        {
            var isTimeZero = FdkHelper.IsTimeZero(startTime);


            BarData[] barsDataBid;
            BarData[] barsDataAsk;
            if (FdkHelper.IsTimeZero(startTime))
            {
                var barCount = (int)barCountDbl;
                if (barCount == 0)
                {
                    barCount = FdkBars.HugeCount;
                }
                barsDataAsk = CalculateBarsForSymbolArray(symbol, PriceType.Ask, endTime, barPeriod, barCount);
                barsDataBid = CalculateBarsForSymbolArray(symbol, PriceType.Bid, endTime, barPeriod, barCount);
            }
            else
            {
                barsDataAsk = CalculateBarsForSymbolArrayRangeTime(symbol, PriceType.Ask, startTime, endTime, barPeriod);
                barsDataBid = CalculateBarsForSymbolArrayRangeTime(symbol, PriceType.Bid, startTime, endTime, barPeriod);
            }
            ReversIfNeed(barsDataAsk);
            ReversIfNeed(barsDataBid);

            var barsData = FdkBarsMerger.ProcessedBarsResult(barsDataBid, barsDataAsk);
            //LogBars(barsData);
            var bars = FdkVars.RegisterVariable(barsData, "bars");

            return(bars);
        }
示例#2
0
        public static string GetLocalQuoteSnapshot(double id)
        {
            var    quotes = BuildSnapshotFromMonitor(id);
            string result = FdkVars.RegisterVariable(quotes, "localSnapshot");

            return(result);
        }
示例#3
0
        public static double[] GetBarsAskHigh(string pairBars)
        {
            var barData = FdkVars.GetValue <PairBar[]>(pairBars);

            return(FdkBars.GetBarsHigh(barData
                                       .SelectToArray(barPair => barPair.Ask.ToBarData())));
        }
示例#4
0
        /// <summary>
        /// Get quote packed
        /// </summary>
        /// <param name="symbol">Symbol to get quotes on</param>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        /// <param name="levelDbl"></param>
        /// <returns></returns>
        public static string GetQuotePacked(string symbol, DateTime startTime, DateTime endTime, double levelDbl = 2)
        {
            try
            {
                var level = (int)levelDbl;

                Log.InfoFormat("FdkLevel2.GetQuotePacked( symbol: {0}, startTime: {1}, endTime: {2}, level: {3} {4})",
                               symbol, startTime, endTime, levelDbl, startTime.Kind.ToString());


                Quote[] quotesData      = FdkQuotes.CalculateHistoryForSymbolArray(symbol, startTime, endTime, level);
                var     quoteLevel2Data = BuildQuoteMultiLevelData(quotesData, level);

                var quoteHistory = FdkVars.RegisterVariable(quoteLevel2Data, "quotesL2");
                return(quoteHistory);
            }
            catch (OutOfMemoryException ex)
            {
                Log.Error("Too large amount of data. Adjust the query");
                throw;
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                throw;
            }
            finally
            {
                GC.Collect();
            }
        }
示例#5
0
        /// <summary>
        /// Get the bar data as pairs
        /// </summary>
        /// <param name="symbol"></param>
        /// <param name="barPeriodStr"></param>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        /// <param name="barCountDbl"></param>
        /// <returns></returns>
        public static string ComputeGetPairBars(string symbol, string barPeriodStr, DateTime startTime, DateTime endTime, double barCountDbl)
        {
            try
            {
                var barPeriod = FdkHelper.GetFieldByName <BarPeriod>(barPeriodStr);
                if (barPeriod == null)
                {
                    return(String.Empty);
                }

                Log.InfoFormat("FdkBarPairs.ComputeBarPairs( symbol: {0}, barPeriod: {1}, startTime: {2}, endTime: {3}, barCount: {4})",
                               symbol, barPeriodStr, startTime, endTime, barCountDbl);

                PairBar[] barsData;
                if (FdkHelper.IsTimeZero(startTime))
                {
                    var barCount = (int)barCountDbl;
                    barsData = GetPairBarsSymbolArray(symbol, barPeriod, endTime, -barCount);
                }
                else
                {
                    barsData = GetPairBarsSymbolArrayRangeTime(symbol, barPeriod, startTime, endTime);
                }

                var bars = FdkVars.RegisterVariable(barsData, "barPairs");
                return(bars);
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                throw;
            }
        }
示例#6
0
        public static DateTime[] GetBarsAskFrom(string pairBars)
        {
            var barData = FdkVars.GetValue <PairBar[]>(pairBars);

            return(barData
                   .Select(barPair => ValidTimeFromTwoTimes(TimeFrom(barPair.Bid), TimeFrom(barPair.Ask)))
                   .ToArray());
        }
示例#7
0
        public static string GetTradeTransactionReportAll()
        {
            var tradeRecordsStream = Trade.Server.GetTradeTransactionReports(TimeDirection.Forward, false, null, null)
                                     .ToArray().ToList();
            var tradeRecordList = tradeRecordsStream.ToArray();

            var varName = FdkVars.RegisterVariable(tradeRecordList, "tradeReports");

            return(varName);
        }
示例#8
0
        public static string ComputeBarsRangeTime(string symbol, string priceTypeStr, string barPeriodStr,
                                                  DateTime startTime, DateTime endTime, double barCountDbl)
        {
            Stopwatch stopWatch = Stopwatch.StartNew();

            try
            {
                var barPeriod = FdkHelper.GetFieldByName <BarPeriod>(barPeriodStr);
                if (barPeriod == null)
                {
                    return(string.Empty);
                }

                if (priceTypeStr == "BidAsk")
                {
                    return(CombinedBarsRangeTime(symbol, barPeriod, startTime, endTime, barCountDbl));
                }

                var priceType = FdkHelper.ParseEnumStr <PriceType>(priceTypeStr);
                if (priceType == null)
                {
                    return(string.Empty);
                }

                Log.InfoFormat("FdkBars.ComputeBarsRangeTime( symbol: {0}, barPeriod: {1}, startTime: {2}, endTime: {3}, barCount: {4} priceType: {5})",
                               symbol, barPeriodStr, startTime, endTime, barCountDbl, priceType);

                BarData[] barsData;
                if (FdkHelper.IsTimeZero(startTime))
                {
                    var barCount = (int)barCountDbl;
                    if (barCount == 0)
                    {
                        barCount = HugeCount;
                    }
                    barsData = CalculateBarsForSymbolArray(symbol, priceType.Value, endTime, barPeriod, barCount);
                }
                else
                {
                    barsData = CalculateBarsForSymbolArrayRangeTime(symbol, priceType.Value, startTime, endTime, barPeriod);
                }

                Log.InfoFormat("Elapsed time: {0} ms for {1} items", stopWatch.ElapsedMilliseconds, barsData.Length);

                var bars = FdkVars.RegisterVariable(barsData, "bars");
                return(bars);
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                throw;
            }
        }
示例#9
0
文件: FdkBars.cs 项目: ihalankou/rFdk
        public static string ComputeGetPairBarsRange(string symbol, string barPeriodStr, DateTime startTime, DateTime endTime)
        {
            var barPeriod = FdkHelper.GetFieldByName <BarPeriod>(barPeriodStr);

            if (barPeriod == null)
            {
                return(string.Empty);
            }
            var barsData = FdkBarPairs.GetPairBarsSymbolArrayRangeTime(symbol, barPeriod, startTime, endTime);
            var bars     = FdkVars.RegisterVariable(barsData, "barPairs");

            return(bars);
        }
示例#10
0
 public static string GetSessionInfo()
 {
     try
     {
         var sessionInfo = Feed.Server.GetSessionInfo();
         var result      = FdkVars.RegisterVariable(sessionInfo, "SessionInfo");
         return(result);
     }
     catch (Exception ex)
     {
         Log.Error(ex);
         throw;
     }
 }
示例#11
0
 public static string SnapshotMonitoredSymbol(double id)
 {
     try
     {
         var quotes        = BuildSnapshotFromMonitor(id);
         var resultVarName = FdkVars.RegisterVariable(quotes, "rt_quotes_snapshot");
         return(resultVarName);
     }
     catch (Exception ex)
     {
         Log.Error(ex);
         throw;
     }
 }
示例#12
0
 public static string GetSymbolInfos()
 {
     try
     {
         var symbolInfos = Symbols;
         var varName     = FdkVars.RegisterVariable(symbolInfos, "symbolsInfo");
         return(varName);
     }
     catch (Exception ex)
     {
         Log.Error(ex);
         throw;
     }
 }
示例#13
0
        public static string GetCurrencyInfos()
        {
            try
            {
                var symbolInfos = FdkHelper.Wrapper.ConnectLogic.Feed.Cache.Currencies;
                var varName     = FdkVars.RegisterVariable(symbolInfos, "currencyInfo");
                return(varName);
            }
            catch (Exception ex)
            {
                Log.Error(ex);

                throw;
            }
        }
示例#14
0
        public static string GetTradeHistory()
        {
            try
            {
                TradeRecord[] tradeRecords = Trade.Server.GetTradeRecords()
                                             .ToArray();

                var varName = FdkVars.RegisterVariable(tradeRecords, "trades");
                return(varName);
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                throw;
            }
        }
示例#15
0
        public static string ComputeQuoteHistory(string symbol, DateTime startTime, DateTime endTime, double depthDbl)
        {
            try
            {
                var depth = (int)depthDbl;
                Log.InfoFormat("FdkQuotes.ComputeQuoteHistory( symbol: {0}, startTime: {1}, endTime: {2}, level: {3})",
                               symbol, startTime, endTime, depthDbl);

                var quotesData   = CalculateHistoryForSymbolArray(symbol, startTime, endTime, depth);
                var quoteHistory = FdkVars.RegisterVariable(quotesData, "quotes");
                return(quoteHistory);
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                throw;
            }
        }
示例#16
0
        public static string GetTradeTransactionReport(DateTime from, DateTime to)
        {
            try
            {
                Log.InfoFormat("FdkTradeReports.GetTradeTransactionReport( from: {0}, to: {1}",
                               from, to);

                var tradeRecordsStream = Trade.Server.GetTradeTransactionReports(TimeDirection.Forward, false, from, to)
                                         .ToArray().ToList();
                var tradeRecordList = tradeRecordsStream.ToArray();

                var varName = FdkVars.RegisterVariable(tradeRecordList, "tradeReports");
                return(varName);
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                throw;
            }
        }
示例#17
0
        /// <summary>
        /// Get quote packed
        /// </summary>
        /// <param name="symbol">Symbol to get quotes on</param>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        /// <param name="levelDbl"></param>
        /// <returns></returns>
        public static string GetQuotePacked(string symbol, DateTime startTime, DateTime endTime, double levelDbl = 2)
        {
            try
            {
                var level = (int)levelDbl;

                Log.InfoFormat("FdkLevel2.GetQuotePacked( symbol: {0}, startTime: {1}, endTime: {2}, level: {3})",
                               symbol, startTime, endTime, levelDbl);

                Quote[] quotesData      = FdkQuotes.CalculateHistoryForSymbolArray(symbol, startTime, endTime, level);
                var     quoteLevel2Data = BuildQuoteMultiLevelData(quotesData, level);

                var quoteHistory = FdkVars.RegisterVariable(quoteLevel2Data, "quotesL2");
                return(quoteHistory);
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                throw;
            }
        }
示例#18
0
文件: FdkBars.cs 项目: ihalankou/rFdk
        public static string ComputeBarsRangeTime(string symbol, string priceTypeStr, string barPeriodStr,
                                                  DateTime startTime, DateTime endTime, double barCountDbl)
        {
            try
            {
                var barPeriod = FdkHelper.GetFieldByName <BarPeriod>(barPeriodStr);
                if (barPeriod == null)
                {
                    return(string.Empty);
                }

                var priceType = FdkHelper.ParseEnumStr <PriceType>(priceTypeStr);
                if (priceType == null)
                {
                    return(string.Empty);
                }

                Log.InfoFormat("FdkBars.ComputeBarsRangeTime( symbol: {0}, barPeriod: {1}, startTime: {2}, endTime: {3}, barCount: {4})",
                               symbol, barPeriodStr, startTime, endTime, barCountDbl);

                Bar[] barsData;
                if (FdkHelper.IsTimeZero(startTime))
                {
                    var barCount = (int)barCountDbl;
                    barsData = CalculateBarsForSymbolArray(symbol, priceType.Value, endTime, barPeriod, barCount);
                }
                else
                {
                    barsData = CalculateBarsForSymbolArrayRangeTime(symbol, priceType.Value, startTime, endTime, barPeriod);
                }

                var bars = FdkVars.RegisterVariable(barsData, "bars");
                return(bars);
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                throw;
            }
        }
示例#19
0
        public static string GetTradeRecords(DateTime startTime, DateTime endTime)
        {
            try
            {
                var           allTrades    = Trade.Server.GetTradeRecords();
                TradeRecord[] tradeRecords = allTrades
                                             .Where(trade => OpenTradeTypes.Contains(trade.Type))
                                             .Where(tr => tr.Created != null && (tr.Created >= startTime && tr.Created <= endTime))
                                             .ToArray();

                Log.InfoFormat("FdkTrade.GetTradeRecords( start: {0}, end: {1}",
                               startTime, endTime);

                var varName = FdkVars.RegisterVariable(tradeRecords, "trades");
                return(varName);
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                throw;
            }
        }
示例#20
0
        public static double[] QuotesSpread(string bars)
        {
            var quotes = FdkVars.GetValue <Quote[]>(bars);

            return(QuoteArraySpread(quotes));
        }
示例#21
0
        public static DateTime[] QuoteRealTimeReceivingTime(string snapshotName)
        {
            var quotes = FdkVars.GetValue <FdkRealTimeQuote[]>(snapshotName);

            return(quotes.SelectToArray(bid => bid.ReceivingTime.AddUtc()));
        }
示例#22
0
        public static double[] QuoteRealTimeAskVolume(string snapshotName)
        {
            var quotes = FdkVars.GetValue <FdkRealTimeQuote[]>(snapshotName);

            return(quotes.SelectToArray(bid => bid.AskVolume));
        }
示例#23
0
        public static double[] GetBarsBidClose(string pairBars)
        {
            var barData = FdkVars.GetValue <PairBar[]>(pairBars);

            return(FdkBars.GetBarsClose(barData.SelectToArray(barPair => barPair.Bid)));
        }
示例#24
0
        public static DateTime[] GetBarsBidTo(string pairBars)
        {
            var barData = FdkVars.GetValue <PairBar[]>(pairBars);

            return(FdkBars.GetBarsTo(barData.SelectToArray(barPair => barPair.Bid)));
        }
示例#25
0
        public static double[] GetCurrencySortOrder(string currencyInfo)
        {
            var currencyInfos = FdkVars.GetValue <CurrencyInfo[]>(currencyInfo);

            return(currencyInfos.SelectToArray(b => (double)b.SortOrder));
        }
示例#26
0
        public static double[] GetCurrencyPrecision(string currencyInfo)
        {
            var currencyInfos = FdkVars.GetValue <CurrencyInfo[]>(currencyInfo);

            return(currencyInfos.SelectToArray(b => (double)b.Precision));
        }
示例#27
0
        public static string[] GetCurrencyName(string currencyInfo)
        {
            var currencyInfos = FdkVars.GetValue <CurrencyInfo[]>(currencyInfo);

            return(currencyInfos.SelectToArray(b => b.Name));
        }
示例#28
0
        public static string[] GetCurrencyDescription(string currencyInfo)
        {
            var currencyInfos = FdkVars.GetValue <CurrencyInfo[]>(currencyInfo);

            return(currencyInfos.SelectToArray(b => b.Description));
        }
示例#29
0
        public static DateTime[] QuotesCreatingTime(string bars)
        {
            var quotes = FdkVars.GetValue <Quote[]>(bars);

            return(QuoteArrayCreateTime(quotes));
        }
示例#30
0
        public static double[] GetBarsAskVolume(string pairBars)
        {
            var barData = FdkVars.GetValue <PairBar[]>(pairBars);

            return(FdkBars.GetBarsVolume(barData.SelectToArray(barPair => barPair.Ask)));
        }