Пример #1
0
        public void SetAssetQuoteRaw(AssetId32Bits p_assetId, string p_dailyNavStr)
        {
            string redisKey        = p_assetId.ToString() + ".brotli"; // // key: "9:1.brotli"
            var    outputCsvBrotli = Utils.Str2BrotliBin(p_dailyNavStr);

            m_redisDb.HashSet("assetQuoteRaw", redisKey, RedisValue.CreateFrom(new System.IO.MemoryStream(outputCsvBrotli)));
        }
Пример #2
0
        public Asset(AssetId32Bits assetId, string symbol, string name, string shortName, CurrencyId currency)
        {
            AssetId   = assetId;
            Symbol    = symbol;
            Name      = name;
            ShortName = shortName;
            Currency  = currency;

            SqTicker = AssetHelper.gAssetTypeCode[AssetId.AssetTypeID] + "/" + Symbol;
        }
Пример #3
0
        public BrokerNav(AssetId32Bits assetId, string symbol, string name, string shortName, CurrencyId currency, User user, DateTime histStartDate, List <BrokerNav> aggregateNavChildren)
            : base(assetId, symbol, name, shortName, currency)
        {
            User = user;
            ExpectedHistoryStartDateLoc = histStartDate;
            AggregateNavChildren        = aggregateNavChildren;

            if (GatewayExtensions.NavSymbol2GatewayId.TryGetValue(Symbol, out GatewayId gatewayId))
            {
                GatewayId = gatewayId;
            }
        }
Пример #4
0
        public string?GetAssetQuoteRaw(AssetId32Bits p_assetId)
        {
            string redisKey = p_assetId.ToString() + ".brotli"; // // key: "9:1.brotli"

            byte[] dailyNavBrotli = m_redisDb.HashGet("assetQuoteRaw", redisKey);
            if (dailyNavBrotli == null)
            {
                return(null);
            }
            var dailyNavStr = Utils.BrotliBin2Str(dailyNavBrotli);  // "D/C" for Date/Closes: "D/C,20090102/16461,20090105/16827,..."

            return(dailyNavStr);
        }
Пример #5
0
        public KeyValuePair <DateOnly, double>[] GetAssetBrokerNavDeposit(AssetId32Bits p_assetId)
        {
            string redisKey = p_assetId.ToString() + ".brotli"; // key: "9:1.brotli"

            byte[] dailyDepositBrotli = m_redisDb.HashGet("assetBrokerNavDeposit", redisKey);
            var    dailyDepositStr    = Utils.BrotliBin2Str(dailyDepositBrotli); // 479 byte text data from 179 byte brotli data, starts with FormatString: "20090310/1903,20100305/2043,..."

            KeyValuePair <DateOnly, double>[] deposits = dailyDepositStr.Split(',', StringSplitOptions.RemoveEmptyEntries).Select(r =>
            {
                // format: "20200323/-1000000"
                var depositsDays = r.Split('/', StringSplitOptions.RemoveEmptyEntries);
                DateTime date    = Utils.FastParseYYYYMMDD(new StringSegment(r, 0, 8));
                double deposit   = Double.Parse(new StringSegment(r, 9, r.Length - 9));
                return(new KeyValuePair <DateOnly, double>(new DateOnly(date), deposit));
            }).ToArray();
            return(deposits);
        }
Пример #6
0
        private static void UpdateAssetInDb(UpdateNavsParam p_updateParam, AssetId32Bits p_assetId, double p_todayNav)
        {
            var dailyNavStr = p_updateParam.Db !.GetAssetQuoteRaw(p_assetId); // "D/C" for Date/Closes: "D/C,20090102/16461,20090105/16827,..."

            int    iFirstComma  = dailyNavStr !.IndexOf(',');
            string formatString = dailyNavStr.Substring(0, iFirstComma);  // "D/C" for Date/Closes

            if (formatString != "D/C")
            {
                return;
            }

            int nearestIntValue = (int)Math.Round(p_todayNav, MidpointRounding.AwayFromZero); // 0.5 is rounded to 1, -0.5 is rounded to -1. Good.

            // var dailyNavStrSplit = dailyNavStr.Substring(iFirstComma + 1, dailyNavStr.Length - (iFirstComma + 1)).Split(',', StringSplitOptions.RemoveEmptyEntries);
            // DateOnly[] dates = dailyNavStrSplit.Select(r => new DateOnly(Int32.Parse(r.Substring(0, 4)), Int32.Parse(r.Substring(4, 2)), Int32.Parse(r.Substring(6, 2)))).ToArray();
            // double[] unadjustedClosesNav = dailyNavStrSplit.Select(r => Double.Parse(r.Substring(9))).ToArray();
            //unadjustedClosesNav[dates.Length - 1] = todayNav;   // update the last item.
            int      iLastComma = dailyNavStr.LastIndexOf(',');
            string   lastRecord = dailyNavStr.Substring(iLastComma + 1);
            DateTime lastDate   = Utils.FastParseYYYYMMDD(lastRecord.Substring(0, 8));

            DateTime todayEt            = Utils.ConvertTimeFromUtcToEt(DateTime.UtcNow).Date;
            int      lengthToUseFromOld = dailyNavStr.Length;

            if (lastDate == todayEt)  // if updater runs twice a day, last item is the today already. Remove the last item from the old string.
            {
                lengthToUseFromOld = iLastComma;
            }

            // dailyNavStr = dailyNavStr.Substring(0, lengthToUseFromOld);
            var    useFromOldSg   = new StringSegment(dailyNavStr, 0, lengthToUseFromOld);               // StringSegment doesn't duplicate the long string
            string newDailyNavStr = useFromOldSg + $",{todayEt.ToString("yyyyMMdd")}/{nearestIntValue}"; // append last record at end

            p_updateParam.Db !.SetAssetQuoteRaw(p_assetId, newDailyNavStr);
        }