public string GenerateOutput(MarketPrice marketPrice, List <EmployeeShare> employeeShares, List <EmployeeBonus> employeeBonuses, List <EmployeeSale> sales)
        {
            var mergedEmployeeShares = from e in employeeShares
                                       group e by new { e.EmployeeId }
            into g
                select new
            {
                Id          = g.Key.EmployeeId,
                TotalVetted = g.Sum(p => p.CalculateGains(marketPrice, employeeBonuses.FirstOrDefault(x => x.EmployeeId == g.Key.EmployeeId), sales.Where(x => x.EmployeeId == g.Key.EmployeeId).Sum(x => x.Quantity))),
                SalesTotal  = sales.FirstOrDefault(x => x.EmployeeId == g.Key.EmployeeId) == null ? 0.00M :
                              sales.Sum(x => x.CalculateSale(employeeShares.Where(y => y.EmployeeId == g.Key.EmployeeId).ToList(),
                                                             employeeBonuses.Where(z => z.EmployeeId == g.Key.EmployeeId).ToList()))
            };

            var output = new StringBuilder();

            foreach (var employeeShare in mergedEmployeeShares)
            {
                output.Append(employeeShare.Id);
                output.Append(",");
                output.Append(employeeShare.TotalVetted);
                output.Append(",");
                output.Append(employeeShare.SalesTotal);
                output.Append(Environment.NewLine);
            }

            return(output.ToString());
        }
示例#2
0
        public bool Insert(MarketPrice actualPrice)
        {
            var uow = new UnitOfWork(DbContext);
            var rs  = uow.MarketPriceRepository.Insert(actualPrice);

            return(rs);
        }
示例#3
0
        public async Task <MarketPricesResult> GetPriceAsync(PublicPricesContext context)
        {
            var api      = ApiProvider.GetApi(context);
            var currency = context.Pair.Asset1.ToRemoteCode(this);

            var r = await api.GetTickerAsync(currency).ConfigureAwait(false);

            CheckResponseErrors(r);

            var krwAsset = Asset.Krw;

            if (!context.Pair.Asset2.Equals(krwAsset))
            {
                throw new NoAssetPairException(context.Pair, this);
            }

            var data = r.data;

            var latestPrice = new MarketPrice(Network, context.Pair, r.data.sell_price)
            {
                //TODO: HH: Are you sure 'sell_price' == Lowest Ask -> I don't think it does. Leave null if not
                PriceStatistics = new PriceStatistics(Network, context.Pair.Asset2, data.sell_price, data.buy_price, data.min_price, data.max_price),
                Volume          = new NetworkPairVolume(Network, context.Pair, data.volume_1day)
            };

            return(new MarketPricesResult(latestPrice));
        }
示例#4
0
        public async Task <MarketPrices> GetPriceAsync(PublicPricesContext context)
        {
            var api = ApiProvider.GetApi(context);

            var pairCode = context.Pair.ToTicker(this);

            var rRaw = await api.GetTickerAsync(pairCode).ConfigureAwait(false);

            CheckResponseErrors(rRaw);

            var r = rRaw.GetContent();

            if (!r.last.HasValue)
            {
                throw new AssetPairNotSupportedException(context.Pair, this);
            }

            var price = new MarketPrice(Network, context.Pair, r.last.Value)
            {
                PriceStatistics = new PriceStatistics(Network, context.Pair.Asset2, r.ask, r.bid, r.low, r.high),
                Volume          = new NetworkPairVolume(Network, context.Pair, r.volume, r.volumeQuote)
            };

            return(new MarketPrices(price));
        }
示例#5
0
文件: Market.cs 项目: sxtgyrq/VRPGame
        internal void Update(MarketPrice sa)
        {
            switch (sa.sellType)
            {
            case "mile":
            {
                this.mile_Price = sa.price;
                LogClass.Class1.Add($"收到{sa.sellType}市场价:{sa.price}");
                this._priceChanged(sa.sellType, this.mile_Price.Value);
            }; break;

            case "business":
            {
                this.business_Price = sa.price;
                LogClass.Class1.Add($"收到{sa.sellType}市场价:{sa.price}");
                this._priceChanged(sa.sellType, this.business_Price.Value);
            }; break;

            case "volume":
            {
                this.volume_Price = sa.price;
                LogClass.Class1.Add($"收到{sa.sellType}市场价:{sa.price}");
                this._priceChanged(sa.sellType, this.volume_Price.Value);
            }; break;

            case "speed":
            {
                this.speed_Price = sa.price;
                LogClass.Class1.Add($"收到{sa.sellType}市场价:{sa.price}");
                this._priceChanged(sa.sellType, this.speed_Price.Value);
            }; break;
            }
            // throw new NotImplementedException();
        }
示例#6
0
        public async Task <MarketPrices> GetPricingAsync(PublicPricesContext context)
        {
            var api = ApiProvider.GetApi(context);

            var pairCode = context.Pair.ToTicker(this, "").ToLower();
            var r        = await api.GetTickerAsync(pairCode).ConfigureAwait(false);

            var baseVolumes = r.volume
                              .Where(x => x.Key.ToLower().Equals(context.Pair.Asset1.ToRemoteCode(this).ToLower()))
                              .Select(x => x.Value).ToArray();

            var quoteVolumes = r.volume
                               .Where(x => x.Key.ToLower().Equals(context.Pair.Asset2.ToRemoteCode(this).ToLower()))
                               .Select(x => x.Value).ToArray();

            var price = new MarketPrice(Network, context.Pair, r.last)
            {
                PriceStatistics = new PriceStatistics(Network, context.Pair.Asset2, r.ask, r.bid, null, null),
                Volume          = new NetworkPairVolume(Network, context.Pair,
                                                        baseVolumes.Any() ? baseVolumes.First() : (decimal?)null,
                                                        quoteVolumes.Any() ? quoteVolumes.First() : (decimal?)null)
            };

            return(new MarketPrices(price));
        }
示例#7
0
        public async Task <MarketPrices> GetPriceAsync(PublicPricesContext context)
        {
            var api      = ApiProvider.GetApi(context);
            var currency = context.Pair.Asset1.ToRemoteCode(this);

            var r = await api.GetTickerAsync(currency).ConfigureAwait(false);

            CheckResponseErrors(r);

            var krwAsset = Asset.Krw;

            if (!context.Pair.Asset2.Equals(krwAsset))
            {
                throw new AssetPairNotSupportedException(context.Pair, this);
            }

            var data = r.data;

            var latestPrice = new MarketPrice(Network, context.Pair, r.data.sell_price)
            {
                PriceStatistics = new PriceStatistics(Network, context.Pair.Asset2, data.sell_price, data.buy_price, data.min_price, data.max_price),
                Volume          = new NetworkPairVolume(Network, context.Pair, data.volume_1day)
            };

            return(new MarketPrices(latestPrice));
        }
示例#8
0
        public async Task <MarketPrices> GetPricingAsync(PublicPricesContext context)
        {
            var api = ApiProvider.GetApi(context);

            var pairCode = context.Pair.ToTicker(this, "");

            try
            {
                var r = await api.GetTickerAsync(pairCode).ConfigureAwait(false);

                var price = new MarketPrice(Network, context.Pair, r.last)
                {
                    PriceStatistics = new PriceStatistics(Network, context.Pair.Asset2, r.ask, r.bid, r.low, r.high),
                    Volume          = new NetworkPairVolume(Network, context.Pair, r.volume)
                };

                return(new MarketPrices(price));
            }
            catch (ApiException ex)
            {
                if (ex.StatusCode == HttpStatusCode.NotFound)
                {
                    throw new AssetPairNotSupportedException(context.Pair, this);
                }
                throw;
            }
        }
示例#9
0
        public async Task <MarketPrices> GetPricingAsync(PublicPricesContext context)
        {
            var api      = ApiProvider.GetApi(context);
            var pairCode = context.Pair.ToTicker(this, '_').ToLower();

            try
            {
                var r = await api.GetDetailedTickerAsync(pairCode).ConfigureAwait(false);

                var sTimeStamp = r.timestamp / 1000; // r.timestamp is returned in ms.

                var price = new MarketPrice(Network, context.Pair, r.last, sTimeStamp.ToUtcDateTime())
                {
                    PriceStatistics = new PriceStatistics(Network, context.Pair.Asset2, r.ask, r.bid, r.low, r.high),
                    Volume          = new NetworkPairVolume(Network, context.Pair, r.volume)
                };

                return(new MarketPrices(price));
            }
            catch (ApiException ex)
            {
                if (ex.StatusCode == HttpStatusCode.BadRequest)
                {
                    throw new AssetPairNotSupportedException(context.Pair, this);
                }
                throw;
            }
        }
示例#10
0
        public async Task <MarketPrices> GetPriceAsync(PublicPricesContext context)
        {
            var api      = ApiProvider.GetApi(context);
            var pairCode = context.Pair.ToTicker(this);
            var rRaw     = await api.GetMarketSummaryAsync(pairCode).ConfigureAwait(false);

            CheckResponseErrors(rRaw, context.Pair);

            var r = rRaw.GetContent();

            var e = r.result.FirstOrDefault();

            if (e == null)
            {
                throw new AssetPairNotSupportedException(context.Pair, this);
            }

            var price = new MarketPrice(Network, context.Pair.Reversed, e.Last)
            {
                PriceStatistics = new PriceStatistics(Network, context.Pair.Asset2, e.Ask, e.Bid, e.Low, e.High),
                Volume          = new NetworkPairVolume(Network, context.Pair, e.BaseVolume, e.Volume)
            };

            return(new MarketPrices(price.Reversed));
        }
示例#11
0
 public async Task <bool> Delete(MarketPrice MarketPrice)
 {
     if (await ValidateId(MarketPrice))
     {
     }
     return(MarketPrice.IsValidated);
 }
示例#12
0
        [HttpPost]// POST: /Person/Edit/5
        public ActionResult Edit(int id, MarketPrice obj)
        {
            try
            {
                using (var db = new RWBTaskEntitiesConnection())
                {
                    var price     = db.Lines.FirstOrDefault(l => l.Id == id);
                    var indicator = "UP";
                    if (price != null)
                    {
                        if (obj.Price < price.Price)
                        {
                            indicator = "DOWN";
                        }

                        price.Price = obj.Price;
                        price.Name  = obj.Name;
                        db.SaveChanges();
                    }

                    ExecuteTask(indicator, obj.Id, obj.Price);

                    return(RedirectToAction("Index"));
                }
            }
            catch
            {
                return(View());
            }
        }
示例#13
0
        private void FillList(MarketPrice market)
        {
            var listValues = new List <ItemList>();

            for (int i = 0; i < market.Values.Count; i++)
            {
                if (i == 0)
                {
                    listValues.Add(new ItemList
                    {
                        FormatedDate = market.Values[i].FormatedDate.Date.ToString(AppResources.FormatedDate),
                        UsdPrice     = String.Format("U$ {0:0.##}", market.Values[i].UsdPrice),
                        UpDown       = "ic_square"
                    });
                }
                else
                {
                    listValues.Add(new ItemList
                    {
                        FormatedDate = market.Values[i].FormatedDate.Date.ToString(AppResources.FormatedDate),
                        UsdPrice     = String.Format("U$ {0:0.##}", market.Values[i].UsdPrice),
                        UpDown       = market.Values[i].UsdPrice > market.Values[i - 1].UsdPrice ? "ic_arrow_up_thick" : "ic_arrow_down_thick"
                    });
                }
            }
            listValues.Reverse();
            ListValues = new ObservableCollection <ItemList>(listValues);
        }
示例#14
0
        public Store_MarketPriceDTO(MarketPrice MarketPrice)
        {
            this.Id = MarketPrice.Id;


            this.Name = MarketPrice.Name;

            this.Errors = MarketPrice.Errors;
        }
示例#15
0
        /// <summary>
        /// 从 ESI 获取价格数据更新本地数据库
        /// </summary>
        /// <param name="location"></param>
        private void UpdateMarketPrice(Locations location)
        {
            DCEVEDataContext dc = new DCEVEDataContext();

            MarketPrice mp;

            if (_marketPriceOfLocation == null)
            {
                // 若该字段为空则说明数据库还没有此数据, 新建一条
                mp = new MarketPrice()
                {
                    TypeID = typeID, LocationID = location.LocationID, ExpiresDateTime = DateTime.MinValue
                };
                dc.MarketPrice.InsertOnSubmit(mp);
            }
            else
            {
                // 若不为空则从新的 DataContext 获取该数据
                mp = dc.MarketPrice.Single(p => p.TypeID == typeID && p.LocationID == location.LocationID);
            }

            // 数据过期时间
            DateTime expriesDateTime = new DateTime();

            // 从 ESI 获取价格数据
            IEnumerable <ESIMarketOrder> marketOrders = ESI.GetMarketOrders(mp.TypeID, location.RegionID, ref expriesDateTime);

            // 仅获取对应位置的数据
            marketOrders = marketOrders.Where(p => p.LocationID == mp.LocationID);

            if (marketOrders.Where(p => p.IsBuyOrder).Count() == 0)
            {
                mp.MaxBuyPrice = 0;
            }
            else
            {
                mp.MaxBuyPrice = marketOrders.Where(p => p.IsBuyOrder).Max(p => p.Price);
            }

            // TODO: 当售价为 0 时, 即没有出售单时, 应该做些处理
            // 设置 PriceAsProduct 和 PriceAsMaterial 属性, 根据不同情况做不同处理
            if (marketOrders.Where(p => !p.IsBuyOrder).Count() == 0)
            {
                mp.MinSellPrice = 0;
            }
            else
            {
                mp.MinSellPrice = marketOrders.Where(p => !p.IsBuyOrder).Min(p => p.Price);
            }

            // 数据过期时间
            mp.ExpiresDateTime = expriesDateTime;

            // 更新数据库
            dc.SubmitChanges();
        }
示例#16
0
        public async Task <MarketPrice> Get(long Id)
        {
            MarketPrice MarketPrice = await UOW.MarketPriceRepository.Get(Id);

            if (MarketPrice == null)
            {
                return(null);
            }
            return(MarketPrice);
        }
示例#17
0
        private bool LoadValueData()
        {
            if (!ApiSync.HasConnection())
            {
                return(false);
            }

            Market = ApiSync.GetMarketValues();
            return(true);
        }
示例#18
0
        public async Task <MarketPrices> GetPricingAsync(PublicPricesContext context)
        {
            var api      = ApiProvider.GetApi(context);
            var pairCode = context.Pair.ToTicker(this);
            var r        = await api.GetLatestPriceAsync(pairCode).ConfigureAwait(false);

            var price = new MarketPrice(Network, context.Pair, r.data.amount);

            return(new MarketPrices(price));
        }
示例#19
0
        public bool Insert(MarketPrice marketPrice)
        {
            int rs = 0;

            DbContext.GetConnection().Execute("delete from market_price");
            DbContext.GetConnection().Execute("delete from market_values");
            rs = DbContext.GetConnection().Insert(marketPrice);
            rs = DbContext.GetConnection().InsertAll(marketPrice.Values);

            return(rs > 0 ? true : false);
        }
示例#20
0
        public LatestPriceResultMessage(MarketPrice price, Asset intermediary, MarketPrice price1, MarketPrice price2, IPublicPricingProvider provider, IPublicPricingProvider providerConvert)
        {
            UtcCreated  = price1.UtcCreated > price2.UtcCreated ? price2.UtcCreated : price1.UtcCreated;
            Provider    = provider;
            MarketPrice = price;

            MarketPrice1 = price1;
            MarketPrice2 = price2;

            AssetIntermediary  = intermediary;
            ProviderConversion = providerConvert;
        }
示例#21
0
        public async Task <MarketPricesResult> GetPricingAsync(PublicPricesContext context)
        {
            var api = ApiProvider.GetApi(context);
            var r   = await api.GetTickerAsync(context.Pair.ToTicker(this, "").ToLower()).ConfigureAwait(false);

            var price = new MarketPrice(Network, context.Pair, r.last)
            {
                PriceStatistics = new PriceStatistics(Network, context.Pair.Asset2, r.ask, r.bid, r.low, r.high),
                Volume          = new NetworkPairVolume(Network, context.Pair, r.volume)
            };

            return(new MarketPricesResult(price));
        }
示例#22
0
        public void AddNewCurrencyPrice(MarketPrice info, Market market)
        {
            cmd.Parameters.Clear();

            cmd.CommandText = "INSERT INTO [GilGames].[dbo].[Trade_Currencies_Prices] VALUES ( ?, ?, ?, ?, ?, ?, GETDATE() )";
            cmd.Parameters.AddWithValue("[MarketID]", market.ID);
            cmd.Parameters.AddWithValue("[BaseCurrency]", market.BaseCurrency);
            cmd.Parameters.AddWithValue("[Currency]", market.MarketCurrency);
            cmd.Parameters.AddWithValue("[Bid]", info.Bid);
            cmd.Parameters.AddWithValue("[Ask]", info.Ask);
            cmd.Parameters.AddWithValue("[Last]", info.Last);

            cmd.ExecuteNonQuery();
        }
示例#23
0
        public async Task <MarketPrices> GetPricingAsync(PublicPricesContext context)
        {
            var api      = ApiProvider.GetApi(context);
            var pairCode = context.Pair.ToTicker(this);

            var r = await api.GetTickerAsync(pairCode).ConfigureAwait(false);

            var price = new MarketPrice(Network, context.Pair, r.lastPrice)
            {
                PriceStatistics = new PriceStatistics(Network, context.Pair.Asset2, r.ask, r.bid, r.low24h, r.high24h),
                Volume          = new NetworkPairVolume(Network, context.Pair, r.volume24h)
            };

            return(new MarketPrices(price));
        }
示例#24
0
        public async Task <MarketPrices> GetPricingAsync(PublicPricesContext context)
        {
            var api         = ApiProvider.GetApi(context);
            var productCode = context.Pair.ToTicker(this, '_');

            var r = await api.GetTickerAsync(productCode).ConfigureAwait(false);

            var price = new MarketPrice(Network, context.Pair, r.ltp)
            {
                PriceStatistics = new PriceStatistics(Network, context.Pair.Asset2, r.best_ask, r.best_bid),
                Volume          = new NetworkPairVolume(Network, context.Pair, r.volume_by_product)
            };

            return(new MarketPrices(price));
        }
示例#25
0
        private void FillChart(MarketPrice market)
        {
            var entries = new List <Microcharts.Entry>();

            foreach (var price in market.Values)
            {
                entries.Add(new Microcharts.Entry((float)price.UsdPrice)
                {
                    Color      = SKColor.Parse("#003E06"),
                    ValueLabel = price.FormatedDate.Day == 1 ? String.Format("{0:MMM}", price.FormatedDate) : null
                });
            }
            Entries = new ObservableCollection <Microcharts.Entry>(entries);
            DrawChart();
        }
示例#26
0
        public void TestVestDateAfterMarketDate()
        {
            var marketPrice = new MarketPrice();

            marketPrice.Price           = 6.00M;
            marketPrice.MarketPriceDate = DateTime.Now;

            var employeeShare = new EmployeeShare();

            employeeShare.GrantPrice    = 5.00M;
            employeeShare.VestDate      = DateTime.Now.AddDays(1);
            employeeShare.NumberOfUnits = 1;

            Assert.IsTrue(employeeShare.CalculateGains(marketPrice) == 0.00M);
        }
示例#27
0
        public void TestEmployeeShareGainLargeNumberOfShares()
        {
            var marketPrice = new MarketPrice();

            marketPrice.Price           = 6.00M;
            marketPrice.MarketPriceDate = DateTime.Now;

            var employeeShare = new EmployeeShare();

            employeeShare.GrantPrice    = 5.00M;
            employeeShare.VestDate      = DateTime.Now.AddDays(-1);
            employeeShare.NumberOfUnits = 1000;

            Assert.IsTrue(employeeShare.CalculateGains(marketPrice) == 1000.00M);
        }
示例#28
0
        public async Task <MarketPrice> Get(long Id)
        {
            MarketPrice MarketPrice = await DataContext.MarketPrice.AsNoTracking()
                                      .Where(x => x.Id == Id)
                                      .Select(x => new MarketPrice()
            {
                Id   = x.Id,
                Code = x.Code,
                Name = x.Name,
            }).FirstOrDefaultAsync();

            if (MarketPrice == null)
            {
                return(null);
            }

            return(MarketPrice);
        }
示例#29
0
        private void TestVolumesRelationWithinPricing(MarketPrice firstPrice, bool?firstVolumeBaseBiggerThanQuote)
        {
            if (!firstVolumeBaseBiggerThanQuote.HasValue)
            {
                Assert.Fail("Relation of base and quote volumes is not set even though provider returned them within pricing request");
            }

            Assert.IsTrue(firstPrice.Volume.Volume24Base.ToDecimal(null) != firstPrice.Volume.Volume24Quote.ToDecimal(null), "Base and quote volumes are same (within pricing)");

            if (firstVolumeBaseBiggerThanQuote.Value)
            {
                Assert.IsTrue(firstPrice.Volume.Volume24Base.ToDecimal(null) > firstPrice.Volume.Volume24Quote.ToDecimal(null), "Quote volume is bigger than base (within pricing)");
            }
            else
            {
                Assert.IsTrue(firstPrice.Volume.Volume24Base.ToDecimal(null) < firstPrice.Volume.Volume24Quote.ToDecimal(null), "Base volume is bigger than quote (within pricing)");
            }
        }
示例#30
0
        public void TestOutputGeneration()
        {
            var marketPrice = new MarketPrice();

            marketPrice.Price           = 6.00M;
            marketPrice.MarketPriceDate = DateTime.Now;

            var anEmployee = new EmployeeShare();

            anEmployee.EmployeeId    = "1";
            anEmployee.GrantPrice    = 5.00M;
            anEmployee.NumberOfUnits = 100;
            anEmployee.VestDate      = DateTime.Now.AddDays(-10);

            var anEmployee1 = new EmployeeShare();

            anEmployee1.EmployeeId    = "1";
            anEmployee1.GrantPrice    = 5.00M;
            anEmployee1.NumberOfUnits = 100;
            anEmployee1.VestDate      = DateTime.Now.AddDays(-10);

            var anEmployee2 = new EmployeeShare();

            anEmployee2.EmployeeId    = "2";
            anEmployee2.GrantPrice    = 5.00M;
            anEmployee2.NumberOfUnits = 100;
            anEmployee2.VestDate      = DateTime.Now.AddDays(-10);

            var employeeList = new List <EmployeeShare>();

            employeeList.Add(anEmployee);
            employeeList.Add(anEmployee1);
            employeeList.Add(anEmployee2);

            var outputRenderer = new OutputRendererService();

            var bonuses = new List <EmployeeBonus>();

            var result = outputRenderer.GenerateOutput(marketPrice, employeeList, bonuses, new List <EmployeeSale>());

            var resultCount = result.Split('\n').Length;

            Assert.IsTrue(resultCount == 3); // there is an extra line at the end, this is fine... 3 == 2, etc.
        }
 private void Client_OnMarketDataIncrementalRefresh(MarketPrice obj)
 {
     AddItem(obj.ToString());
 }
 private void Client_OnMarketDataSnapshotFullRefresh(MarketPrice obj)
 {
     AddItem(obj.ToString());
 }
        public void OnMessage(MarketDataIncrementalRefresh message, SessionID session)
        {
            var noMdEntries = message.NoMDEntries;
            var listOfMdEntries = noMdEntries.getValue();
            //message.GetGroup(1, noMdEntries);
            var group = new MarketDataIncrementalRefresh.NoMDEntriesGroup();

            Group gr = message.GetGroup(1, group);

            string sym = message.MDReqID.getValue();

            var price = new MarketPrice();

            for (int i = 1; i <= listOfMdEntries; i++)
            {
                group = (MarketDataIncrementalRefresh.NoMDEntriesGroup)message.GetGroup(i, group);

                price.Symbol = group.Symbol.getValue();

                MDEntryType mdentrytype = group.MDEntryType;

                if (mdentrytype.getValue() == '0') //bid
                {
                    decimal px = group.MDEntryPx.getValue();
                    price.Bid = px;
                }
                else if (mdentrytype.getValue() == '1') //offer
                {
                    decimal px = group.MDEntryPx.getValue();
                    price.Offer = px;
                }

                price.TimeStamp = group.MDEntryTime.ToString();
            }

            if (OnMarketDataIncrementalRefresh != null)
            {
                OnMarketDataIncrementalRefresh(price);
            }
        }