/// <summary> /// Gets the crypto currency. /// </summary> /// <param name="tickername">The ticker name.</param> /// <param name="commodity"></param> /// <param name="exchangeModel">The exchangeModel.</param> /// <param name="details">The details.</param> /// <returns></returns> private SecurityBase GetCryptoCurrency(string tickername, string commodity, ExchangeModel exchangeModel, SecurityDetails details) { //Get all tickers associated to this crypto currency from config, for this broker model var configured = Config.SecurityConfig.Where(x => String.Equals(x.Ticker, tickername, StringComparison.CurrentCultureIgnoreCase) && String.Equals(x.Exchange, exchangeModel.Name, StringComparison.CurrentCultureIgnoreCase) && x.Brokers.Select(b => b.ToLower()).Contains(_brokerModel.BrokerType.ToString().ToLower())) .ToArray(); //Check if we have items if (!configured.Any()) { return(new UnknownSecurity(tickername)); } //Get shortest path for this currency for the account currency var found = configured.FirstOrDefault(x => String.Equals(x.Currency, _accountcurrency.ToString(), StringComparison.CurrentCultureIgnoreCase)) ?? configured.FirstOrDefault(); //Return what we have if (found != null) { var basecurrency = (CurrencyType)Enum.Parse(typeof(CurrencyType), found.Currency); return(new CryptoSecurity(new TickerSymbol(tickername, commodity, basecurrency), exchangeModel, details, _currency)); } else { return(new UnknownSecurity(tickername)); } }
/// <summary> /// 发送消息到消息队列 /// </summary> /// <param name="conn">连接地址</param> /// <param name="queueName">队列名称</param> /// <param name="msg">发送的消息</param> /// <param name="exchangeModel">交换机实体</param> /// <returns></returns> public bool sendMsg(IConnection conn, string queueName, string msg, ExchangeModel exchangeModel) { bool sflag = true; try { //var channel = conn.CreateModel(); using (var channel = conn.CreateModel()) { //1交换机,交换机类型 channel.ExchangeDeclare(exchangeModel.ExchangeName, exchangeModel.ExchangeType); //队列名称,是否持久化,独占的队列,不使用时是否自动删除, channel.QueueDeclare(queueName, exchangeModel.Durable, false, false, null); //转换成byte数组 var sendBytes = Encoding.UTF8.GetBytes(msg); //设置持久化参数 var properties = channel.CreateBasicProperties(); properties.DeliveryMode = 2;//1表示不持久,2表示持久化 if (!exchangeModel.Durable) { properties = null; } //发送消息:交换机名称,路由,持久化参数,消息内容 channel.BasicPublish(exchangeModel.ExchangeName, exchangeModel.RouteKey[0], properties, sendBytes); } } catch (Exception) { sflag = true; throw; } return(sflag); }
/// <summary> /// Rebalances the specified securities. /// </summary> /// <param name="securities">The securities.</param> /// <param name="exchange">Associated exchange information</param> private void Rebalance(Security[] securities, ExchangeModel exchange) { //Check if we have securities if (securities.Length == 0) { return; } //Check if we are supposed to rebalance based on the parameter supplied DateTime utcnow = exchange.UtcTime.Date; if (utcnow < _lastRebalance[exchange.Name].Date.AddDays(RebalanceDays)) { return; } //Rebalance (using market orders) foreach (var security in securities.Where(x => !Position[x].IsFlat)) { //We can send order size zero as the order quantity method process the quantity anyways SubmitOrderTicket(MarketOnOpenOrder(security, 0m, "Rebalancing")); Info($"Rebalanced security {security.Ticker.Name} for exchange {exchange.Name} on local date and time {exchange.LocalTime}"); } //Set last rebalance _lastRebalance[exchange.Name] = utcnow; }
public async Task <IActionResult> Execute([FromBody] ExchangeModel request) { string merchantId = this.GetUserMerchantId(); try { var clientRequest = Mapper.Map <ExchangeRequest>(request, opt => opt.Items["MerchantId"] = merchantId); ExchangeClientResponse response = await _payInternalClient.ExchangeAsync(clientRequest); return(Ok(Mapper.Map <ExchangeResponse>(response))); } catch (DefaultErrorResponseException e) when(e.StatusCode == HttpStatusCode.BadRequest) { var apiException = e.InnerException as ApiException; if (apiException?.StatusCode == HttpStatusCode.BadRequest) { return(BadRequest(apiException.GetContentAs <ErrorResponse>())); } _log.Error(e, null, $"request:{request.ToJson()}"); return(BadRequest(ErrorResponse.Create(e.Message))); } }
public async Task <JsonResult> Post(string countryCode, string paymentMethod, string currency, decimal gain, bool isColombia) { var buySP = BuyAdServices.buyAdsAboutAmount(countryCode, paymentMethod, currency, countryCode == "PE" && currency == "USD" ? 2 : 10); Decimal sellVe = 1; byte[] test = null; if (HttpContext.Session.TryGetValue("SellVeDecimal", out test)) { sellVe = decimal.Parse(HttpContext.Session.GetString("SellVeDecimal")); } else { var result = await SellAdServices.SellAdsAboutAmount("VE", "", 2); sellVe = result[0]; } var rate = decimal.Round((sellVe / buySP), 4); var model = new ExchangeModel() { rateFormat = isColombia ? decimal.Round(buySP / sellVe, 2).ToString() : (rate).ToString("C3", CultureInfo.CreateSpecificCulture("es-VE")), rateValue = (isColombia ? buySP / sellVe : rate), rateValueGain = isColombia ? (rate) + gain : (rate) - gain, rateFormatGain = isColombia ? decimal.Round((buySP / sellVe) + gain, 2).ToString() : ((rate) - gain).ToString("C3", CultureInfo.CreateSpecificCulture("es-VE")) }; return(Json(model)); }
public void UpdateCandles(List <Candle> c, CandlePeriod p, string symbol) { ExchangeModel toUpdate = models.FirstOrDefault(x => x.Symbol.Value.symbol == symbol); if (p == CandlePeriod.M1) { this.UpdateCandles_M1(c, toUpdate); } else if (p == CandlePeriod.M5) { this.UpdateCandles_M5(c, toUpdate); } else if (p == CandlePeriod.M30) { this.UpdateCandles_M30(c, toUpdate); } else if (p == CandlePeriod.H1) { this.UpdateCandles_H1(c, toUpdate); } else if (p == CandlePeriod.H4) { this.UpdateCandles_H4(c, toUpdate); } else if (p == CandlePeriod.D1) { this.UpdateCandles_D1(c, toUpdate); } else if (p == CandlePeriod.W1) { this.UpdateCandles_W1(c, toUpdate); } }
public async Task <IActionResult> Index() { var deserializedEUR = new Root(); var deserializedUSD = new Root(); deserializedEUR = await EService.GetExchange("eur"); deserializedUSD = await EService.GetExchange("usd"); var model = new ExchangeModel { effectiveDateUSD = deserializedUSD.rates[0].effectiveDate, midUSD = deserializedUSD.rates[0].mid, effectiveDateUSD1 = deserializedUSD.rates[1].effectiveDate, midUSD1 = deserializedUSD.rates[1].mid, changeUSD = EService.GetChange(deserializedUSD.rates[0].mid, deserializedUSD.rates[1].mid), effectiveDateEUR = deserializedUSD.rates[0].effectiveDate, midEUR = deserializedEUR.rates[0].mid, effectiveDateEUR1 = deserializedUSD.rates[1].effectiveDate, midEUR1 = deserializedEUR.rates[1].mid, changeEUR = EService.GetChange(deserializedEUR.rates[0].mid, deserializedEUR.rates[1].mid), }; return(View(model)); }
public ActionResult DeleteConfirmed(int SteelMarkId, int SteelFIId, int UnitId) { ExchangeModel exchangemodel = _context.ExchangeModel.Where(p => p.SteelFIId == SteelFIId && p.SteelMarkId == SteelMarkId && p.UnitId == UnitId).FirstOrDefault(); _context.ExchangeModel.Remove(exchangemodel); _context.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Index() { var model = new ExchangeModel(); model.CurrencyCodes = ExchangeRateManager.GetRateCodes(); return(PartialView(model)); }
public IActionResult Index() { var exchangeModel = new ExchangeModel(); ViewBag.Currencies = new SelectList(_apiRepository.GetCurrencies()); return(View(exchangeModel)); }
public void UpdateOwnTardes(List <Trade> trades, string symbol) { ExchangeModel toUpdate = models.FirstOrDefault(x => x.Symbol.Value.symbol == symbol); foreach (Trade t in trades) { this.UpdateOwnTrade(t, toUpdate); } }
private void UpdateTrade(string symbol, Trade tradeModel, ExchangeModel toUpdate) { Trade tradeToUpdate = toUpdate.Trades.Value.FirstOrDefault(x => x.Id == tradeModel.Id); if (tradeToUpdate == null) { toUpdate.Trades.Add(tradeModel); } }
protected void CreateExchangeDeclare(IModel channelModel, ExchangeModel exchangeModel) { channelModel.ExchangeDeclare( exchangeModel.ExchangeName, exchangeModel.ExchangeType.ToString().ToLower(), exchangeModel.Durable, exchangeModel.AutoDelete, exchangeModel.Arguments); }
/// <summary> /// Last trading day of each month /// </summary> /// <param name="exchangeModel">The exchangeModel.</param> /// <returns></returns> public DateComposite EndOfMonth(ExchangeModel exchangeModel) => new DateFunc(x => { //Derive the next date var derived = x.ConvertTo(TimeZone.Utc, exchangeModel.TimeZone).AddMonths(2).DoWhile(n => n.AddDays(-1), i => !exchangeModel.IsOpenOnDate(i) && x.Month != i.Month + 1); //return return(derived.ConvertTo(exchangeModel.TimeZone, TimeZone.Utc)); }, "End-Of-Every-Month");
public ActionResult Details(int SteelMarkId, int SteelFIId, int UnitId) { ExchangeModel exchangemodel = _context.ExchangeModel.Where(p => p.SteelFIId == SteelFIId && p.SteelMarkId == SteelMarkId && p.UnitId == UnitId).FirstOrDefault(); if (exchangemodel == null) { return(HttpNotFound()); } return(View(exchangemodel)); }
public void Add (ExchangeModel exchange) { if (exchange == null) { throw new ArgumentNullException(nameof(exchange)); } exchangeSet.Add(exchange); }
public void ExchangeModel_Maps_Json_Data() { string testString = "{\"base\":\"USD\",\"date\":\"2019-02-15\",\"rates\":{\"EUR\":0.8880994671}}"; ExchangeModel exchangeModel = JsonConvert.DeserializeObject <ExchangeModel>(testString); Assert.AreEqual(CurrencyType.USD, exchangeModel.Base); Assert.AreEqual(new System.DateTime(2019, 2, 15), exchangeModel.Date); Assert.IsTrue(exchangeModel.Rates.ContainsKey(CurrencyType.EUR.ToString())); Assert.AreEqual(0.8880994671, exchangeModel.Rates[CurrencyType.EUR.ToString()]); }
public async Task <IActionResult> GetDemoRate([FromQuery] string from) //([FromBody] ExchangeModel exchangeData) { var exchangeData = new ExchangeModel { FromCurr = from, ToCurr = "USD" }; var dbData = _databaseServices.GetDemoData(exchangeData); var kek = _dataServices.formatData(dbData); return(new JsonResult(kek)); }
private void UpdateOwnTrade(Trade t, ExchangeModel toUpdate) { if (toUpdate != null) { Trade toUpdateTrade = toUpdate.MyTrades.Value.FirstOrDefault(x => x.Id == t.Id && x.Side == t.Side && x.Exchange == t.Exchange); if (toUpdateTrade == null && t.TimeStamp > toUpdate.StartTime) { toUpdate.MyTrades.Add((Trade)t.Clone()); } } }
/// <summary> /// First moment after the markets are opened /// </summary> /// <param name="exchangeModel">The exchangeModel.</param> /// <param name="afteropen">Time delay after market open.</param> /// <returns></returns> public TimeComposite AfterMarketOpen(ExchangeModel exchangeModel, TimeSpan afteropen) => new TimeFunc(x => { //Get the correct timezone for this exchange (input is utc) x = x.ConvertTo(TimeZone.Utc, exchangeModel.TimeZone); //Derive next date var derived = exchangeModel.NextMarketOpen(x).Add(afteropen); //return return(derived.ConvertTo(exchangeModel.TimeZone, TimeZone.Utc)); }, $"After-Market-Open-{exchangeModel.Name}-{afteropen}");
/// <summary> /// Last trading day of each week /// </summary> /// <param name="exchangeModel">The exchangeModel.</param> /// <returns></returns> public DateComposite EndOfWeek(ExchangeModel exchangeModel) => new DateFunc(x => { //Get the correct timezone for this exchange (input is utc) x = x.ConvertTo(TimeZone.Utc, exchangeModel.TimeZone); //Derive next date var derived = x.AddDays(7 - ((int)x.DayOfWeek + 1 > 0 ? (int)x.DayOfWeek + 2 : 0)) .DoWhile(n => n.AddDays(-1), n => !exchangeModel.IsOpenOnDate(n)); //return return(derived.ConvertTo(exchangeModel.TimeZone, TimeZone.Utc)); }, "End-Of-Week");
public string GetMsg(string queueName) { ExchangeModel exchangeModel = new ExchangeModel(); exchangeModel.ExchangeName = "ClentName"; exchangeModel.ExchangeType = ExchangeType.Direct; //添加多个路由规则 exchangeModel.RouteKey = new List <string>(); exchangeModel.RouteKey.Add("ClentRoute.info"); exchangeModel.RouteKey.Add("ClentRoute.error"); //exchangeModel.RouteKey = "ClentRoute"; return(rabbitHelper.ConsumMsg(connection, queueName, exchangeModel)); }
public void UpdateSymbol(Symbol s, string symbol) { ExchangeModel toUpdate = models.FirstOrDefault(x => x.Symbol.Value.symbol == symbol); if (toUpdate != null) { toUpdate.Symbol.Update(s); } else { this.models.Add(new ExchangeModel(this.Exchange, s)); } }
public ActionResult Edit(ExchangeModel exchangemodel) { if (ModelState.IsValid) { _context.Entry(exchangemodel).State = EntityState.Modified; _context.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.SteelFIId = new SelectList(_context.SteelFIModel, "SteelFIId", "Code", exchangemodel.SteelFIId); ViewBag.SteelMarkId = new SelectList(_context.SteelMarkModel, "SteelMarkId", "Code", exchangemodel.SteelMarkId); ViewBag.UnitId = new SelectList(_context.UnitModel.Where(p => p.UnitId == 4), "UnitId", "UnitName", exchangemodel.UnitId); return(View(exchangemodel)); }
public void UpdateOrders(List <Order> orderModels, string symbol) { ExchangeModel toUpdate = models.FirstOrDefault(x => x.Symbol.Value.symbol == symbol); if (orderModels != null && orderModels.Any()) { foreach (Order order in orderModels) { this.UpdateOrder(order, toUpdate); this.CheckSymbolOrderFills(order, toUpdate); } } }
/// <summary> /// On the first trading day of the specified month /// </summary> /// <param name="exchangeModel">The exchangeModel.</param> /// <param name="month">The month.</param> /// <returns></returns> public DateComposite StartOfMonth(ExchangeModel exchangeModel, int month) => new DateFunc(x => { //Get the correct timezone for this exchange (input is utc) x = x.ConvertTo(TimeZone.Utc, exchangeModel.TimeZone); //Derive next date var derived = new DateTime(x.Month >= month ? x.Year + 1 : x.Year, 1, 1) .DoWhile(n => n.AddDays(1), i => !exchangeModel.IsOpenOnDate(i) && i.Month != month); //return return(derived.ConvertTo(exchangeModel.TimeZone, TimeZone.Utc)); }, $"Start-Of-{month}-Month");
/// <summary> /// On the first trading day of the week /// </summary> /// <param name="exchangeModel">The exchangeModel.</param> /// <returns></returns> public DateComposite StartOfWeek(ExchangeModel exchangeModel) => new DateFunc(x => { //Get the correct timezone for this exchange (input is utc) x = x.ConvertTo(TimeZone.Utc, exchangeModel.TimeZone); //Derive next date var derived = x.AddDays(7).AddDays(DayOfWeek.Monday - x.DayOfWeek) .DoWhile(n => n.AddDays(1), n => !exchangeModel.IsOpenOnDate(n)); //return return(derived.ConvertTo(exchangeModel.TimeZone, TimeZone.Utc)); }, "Start-Of-Every-Week");
public ActionResult Edit(int SteelMarkId, int SteelFIId, int UnitId) { ExchangeModel exchangemodel = _context.ExchangeModel.Where(p => p.SteelFIId == SteelFIId && p.SteelMarkId == SteelMarkId && p.UnitId == UnitId).FirstOrDefault(); if (exchangemodel == null) { return(HttpNotFound()); } ViewBag.SteelFIId = new SelectList(_context.SteelFIModel, "SteelFIId", "Code", exchangemodel.SteelFIId); ViewBag.SteelMarkId = new SelectList(_context.SteelMarkModel, "SteelMarkId", "Code", exchangemodel.SteelMarkId); ViewBag.UnitId = new SelectList(_context.UnitModel.Where(p => p.UnitId == 4), "UnitId", "UnitName", exchangemodel.UnitId); return(View(exchangemodel)); }
/// <summary> /// Before the next market close /// </summary> /// <param name="exchangeModel">The exchangeModel.</param> /// <param name="beforeclose">Time before the market closes.</param> /// <returns></returns> public TimeComposite BeforeMarketClose(ExchangeModel exchangeModel, TimeSpan beforeclose) => new TimeFunc(x => { //Get the correct timezone for this exchange (input is utc) x = x.ConvertTo(TimeZone.Utc, exchangeModel.TimeZone); //Derive next date var derived = exchangeModel.NextMarketClose(x.ConvertTo(TimeZone.Utc, exchangeModel.TimeZone)) .Add(-beforeclose); //return return(derived.ConvertTo(exchangeModel.TimeZone, TimeZone.Utc)); }, $"Before-Market-Close-{exchangeModel.Name}-{beforeclose}");
/// <summary> /// Base implementation for a security object /// </summary> /// <param name="ticker"></param> /// <param name="exchangeModel"></param> /// <param name="details"></param> /// <param name="type"></param> /// <param name="conversion"></param> protected SecurityBase(TickerSymbol ticker, ExchangeModel exchangeModel, SecurityDetails details, SecurityType type, Currency conversion) { //Set references _currencyConversion = conversion; Exchange = exchangeModel; BaseCurrency = ticker.Currency; Details = details; Ticker = ticker; Type = type; //Defaults LastTickEventUtc = DateTime.MinValue; LastTradeEventUtc = DateTime.MinValue; }