public bool Add(int type, int index, string code) { var cache = new ShareCacheStruct <ExchangeCode>(); int key = UniqueKey(type, index); //if (null != cache.FindKey(key)) return false; // this type has been added ExchangeCode ec = cache.FindKey(key); if (null != ec) { return(true); } else { ec = new ExchangeCode(); ec.key = key; ec.Type = (byte)type; ec.Index = index; ec.Code = code; if (ec.Type == (byte)GameConfigExchangeCode.ExchangeCodeType.ASType_NSNSDuiHuan_AnHuiTai_1 || ec.Type == (byte)GameConfigExchangeCode.ExchangeCodeType.ASType_NSNSDuiHuan_JiaRi_1) { ec.cnt = int.MaxValue; } cache.Add(ec); } return(true); }
public RunWorkerCompletedEventArgs(bool cancelled, Exception error, ExchangeCode result, object userState) { Cancelled = cancelled; Error = error; Result = result; UserState = userState; }
public async Task <ActionResult> ExchangeCodeForAccessToken([FromBody] ExchangeCode body) { var uid = User.FindFirstValue(ClaimTypes.NameIdentifier); var user = await db.Users.SingleOrDefaultAsync(u => u.Uid == uid); if (user == null) { return(NotFound("User not found")); } var data = new Dictionary <string, string> { { "grant_type", "authorization_code" }, { "client_id", options.ClientId }, { "client_secret", options.ClientSecret }, { "code", body.Code }, { "redirect_uri", body.ReturnUrl }, { "scope", "read_station" } }; using (var response = await httpClient.PostAsync("https://api.netatmo.com/oauth2/token", new FormUrlEncodedContent(data))) { response.EnsureSuccessStatusCode(); var authorization = await response.Content.ReadAsAsync <Core.DTOs.Authorization>(); user.AccessToken = authorization.AccessToken; user.RefreshToken = authorization.RefreshToken; user.ExpiresAt = DateTime.Now.AddSeconds(authorization.ExpiresIn); await db.SaveChangesAsync(); return(Accepted()); } }
protected override async Task ExecuteAsync(CancellationToken stoppingToken) { ExchangeConfig config = await _exchangeConfigProcessor.GetExchangeConfig(Exchange.Code); if (config == null) { _logger.LogError($"Config for {Exchange.Description} is not found"); return; } List <Task> tasks = new List <Task>(); if (config.IsEnabled) { foreach (var pair in config.Pairs) { if (pair.IsEnabled) { Task t = Task.Run(() => DoWork(pair, stoppingToken)); tasks.Add(t); } else { _logger.LogInformation($"Pair '{pair.Symbol}' is disabled"); } } await Task.WhenAll(tasks.ToArray()); } else { _logger.LogInformation($"Exchange '{ExchangeCode.Create(config.ExchangeCode).Description}' is disabled"); } }
private static string makeExchangeOutOfSymbol(string symbol, FinanceAPI.FinanceStrategies strategy) { string result = null; if (symbol != null) { string[] tmp = symbol.Split('.'); if (tmp.Length > 1) { ExchangeCode exch = exchanges.FirstOrDefault(x => x.YahooSuffix == tmp[1]); if (exch != null) { switch (strategy) { case FinanceAPI.FinanceStrategies.Google: result = exch.GoogleExch; break; case FinanceAPI.FinanceStrategies.Yahoo: result = exch.YahooExch; break; } } } } return(result); }
public async Task <TradingContext> Build(ExchangeCode exchangeCode, string symbol) { ITradingStrategy strategy = null; IEnumerable <ICandle> candles = null; return(await WithConnection(async (connection, transaction) => { Strategy strategyInfo = await _strategyManager.Get(exchangeCode, symbol, connection); if (!strategyInfo.IsEnabled) { return null; } Type type = Type.GetType(strategyInfo.TypeName, true, true); strategy = (ITradingStrategy)Activator.CreateInstance(type); // TODO: Add Strategy preset support //strategy.Preset = strategyInfo.Preset; candles = await _candlesManager.GetLastCandles(exchangeCode, symbol, strategy.OptimalTimeframe.Code, strategy.MinNumberOfCandles, connection, transaction); TradingContext context = new TradingContext(exchangeCode, symbol, strategy, candles); return context; })); }
public int isOk(int type, int index, string code) { var cache = new ShareCacheStruct <ExchangeCode>(); int key = UniqueKey(type, index); ExchangeCode ec = cache.FindKey(key); if (null == ec) { return(1); // not find } if (type != ec.Type) { return(2); } if (index != ec.Index) { return(3); } if (code != ec.Code) { return(4); } if (ec.cnt <= 0) { return(5); // used... } ec.ModifyLocked(() => { ec.cnt -= 1; }); return(0); }
/// <summary> /// 网络操作后台线程 /// </summary> /// <param name="completedEventHandler">完成时调用</param> /// <param name="operation">所需的操作</param> /// <param name="beSendedData">需要发送的数据</param> /// <param name="tryTimes">尝试次数</param> /// <param name="passDown">需要在完成时传给CompletedEventHandler委托的东西</param> public NetworkWorker(CompletedEventHandler completedEventHandler, ExchangeCode operation, byte[] beSendedData, object passDown) { this.beSendedData = beSendedData; this.operation = operation; this.completedEventHandler = completedEventHandler; WorkerSupportsCancellation = true; DoWork += NetworkWorker_DoWork; RunWorkerCompleted += NetworkWorker_RunWorkerCompleted; this.passDown = passDown; }
public vExchangeCode(ExchangeCode model) { this.ID = model.ID; this.Code = model.Code; this.ProductID = model.ProductID; this.ProductName = model.Product.ProductName; this.UserID = model.UserID; this.UserName = model.User.UserName; this.Time = model.Time; this.IsExchange = model.IsExchange; this.ChangeTime = model.ChangeTime; }
public static Currency getCurrencyByExchangeCode(string exchShortCut) { ExchangeCode exch = exchanges.FirstOrDefault(x => x.YahooExch == exchShortCut); var currency = new Currency(); if (exch != null) { currency = currencies.FirstOrDefault(x => x.ShortCode == exch.Currency); } return(currency); }
public async Task StopLoss(Trade trade, PairConfig config) { await WithConnection(async (connection, transaction) => { IExchangeCode exchangeCode = ExchangeCode.Create(trade.ExchangeCode); IEnumerable <Deal> deals = await _dealManager.GetOpenDeals(trade.ExchangeCode, trade.Symbol, connection, transaction); foreach (Deal deal in deals) { deal.Orders = await _orderManager.GetOrdersByDealId(deal.Id, connection, transaction) as List <Order>; if (deal.StopLoss.HasValue && trade.Price < deal.StopLoss.Value) { foreach (Order dealOrder in deal.Orders) { if (dealOrder.OrderStatusCode == OrderStatusCode.PENDING.Code || dealOrder.OrderStatusCode == OrderStatusCode.EXPIRED.Code || dealOrder.OrderStatusCode == OrderStatusCode.HOLD.Code) { await _orderManager.Delete(dealOrder.Id, connection, transaction); } else if (dealOrder.OrderStatusCode == OrderStatusCode.LISTED.Code) { dealOrder.OrderStatusCode = OrderStatusCode.CANCELED.Code; dealOrder.Updated = DateTime.UtcNow; dealOrder.UpdateRequired = true; await _orderManager.Update(dealOrder, connection, transaction); NatsClient client = _connector.Client; await client.PubAsJsonAsync(_settings.Value.OrdersQueueName, new Notification <Order>() { Code = ActionCode.UPDATED.Code, Payload = dealOrder }); } } Order order = new Order(); order.ExchangeCode = trade.ExchangeCode; order.Symbol = trade.Symbol; order.TradingModeCode = TradingModeCode.AUTO; order.FillPoliticsCode = FillPoliticsCode.GTC; order.OrderStatusCode = OrderStatusCode.PENDING; order.DealId = deal.Id; order.OrderTypeCode = OrderTypeCode.MKT; order.OrderSideCode = OrderSideCode.SELL; order.Amount = deal.Amount; order.Id = await _orderManager.Create(order, connection, transaction); } } return(Task.CompletedTask); }); }
public static Currency getCurrencyBySymbol(string symbol) { var currency = currencies[currencies.Count - 1]; var exchange = makeExchangeOutOfSymbol(symbol, FinanceAPI.FinanceStrategies.Yahoo); ExchangeCode exch = exchanges.FirstOrDefault(x => x.YahooExch == exchange); if (exch != null) { currency = currencies.FirstOrDefault(x => x.ShortCode == exch.Currency); } return(currency); }
public static ExchangeConfigModel ToModel(this ExchangeConfig entity) { ExchangeConfigModel model = new ExchangeConfigModel(); model.Id = entity.Id; model.ExchangeCodeId = entity.ExchangeCode; model.ExchangeName = ExchangeCode.Create(entity.ExchangeCode).Description; model.IsEnabled = entity.IsEnabled; model.ApiKey = entity.ApiKey; model.ApiSecret = entity.ApiSecret; model.Pairs = entity.Pairs; return(model); }
/// <summary> /// Google uses a different code for exchanges than the standard (Bloomberg, Yahoo, etc) /// </summary> /// <returns>Exchange code as string</returns> public static string transformExchangeToGoogle(string symbol, string exchange = null) { string result = null; if (!String.IsNullOrEmpty(exchange)) { ExchangeCode exch = exchanges.FirstOrDefault(x => x.YahooExch == exchange); result = (exch != null) ? exch.GoogleExch : makeExchangeOutOfSymbol(symbol, FinanceAPI.FinanceStrategies.Google); } else { result = makeExchangeOutOfSymbol(symbol, FinanceAPI.FinanceStrategies.Google); } return(result); }
public async Task <IActionResult> AssignedPairs(int id) { IEnumerable <Asset> assets = await _assetProcessor.GetAll(); IEnumerable <PairConfig> assignedPairs = await _pairConfigProcessor.GetAssigned(id); PairConfigsModel model = new PairConfigsModel(); model.ExchangeCode = id; model.ExchangeName = ExchangeCode.Create(id).Description; model.Configs = assignedPairs.ToList(); model.AllAssets = assets.Select(x => new SelectListItem(x.Name, x.Code)).ToList(); return(View(model)); }
public Etf(ExchangeCode exchangeCode, string marketCode) : base(exchangeCode, marketCode) { }
/// <summary> /// 把ExchangeCode转换成文本 /// </summary> /// <param name="exchangeCode">需要转换的ExchangeCode</param> /// <returns>转换后的文本</returns> public static string ToString(ExchangeCode exchangeCode) { return(((int)exchangeCode).ToString("0000")); }
public static Currency.CurrencyCode getCurrencyCodeByExchange(string exchShortCut) { ExchangeCode exch = exchanges.FirstOrDefault(x => x.YahooExch == exchShortCut); return((exch != null) ? exch.Currency : Currency.CurrencyCode.EUR); }
/// <summary> /// Searches the exchanges list for short code and returns full name /// </summary> public static string getExchangeFullTitle(string exchShortCut) { ExchangeCode exch = exchanges.FirstOrDefault(x => x.YahooExch == exchShortCut); return((exch != null && exch.Title.Length > 0) ? exch.Title : exchShortCut); }
/// <summary> /// 网络操作后台线程 /// </summary> /// <param name="completedEventHandler">完成时调用</param> /// <param name="operation">所需的操作</param> /// <param name="beSendedData">需要发送的数据</param> /// <param name="tryTimes">尝试次数</param> /// <param name="passDown">需要在完成时传给CompletedEventHandler委托的东西</param> public NetworkWorker(CompletedEventHandler completedEventHandler, ExchangeCode operation, string beSendedData, object passDown) : this(completedEventHandler, operation, Encoding.UTF8.GetBytes(beSendedData), passDown) { }
/// <summary> /// Returns a hash code for this instance. /// </summary> /// <returns> /// A hash code for this instance, suitable for use in hashing algorithms and data /// structures like a hash table. /// </returns> public override int GetHashCode() { return(AreaCode.GetHashCode() + ExchangeCode.GetHashCode() + SubscriberNumber.GetHashCode()); }
public Stock(ExchangeCode exchangeCode, string marketCode) : base(exchangeCode, marketCode) { }
public Equity(ExchangeCode exchangeCode, string marketCode) : base($"{exchangeCode.ToString().ToUpperInvariant()}:{marketCode}") { ExchangeCode = exchangeCode; MarketCode = marketCode ?? throw new ArgumentNullException(nameof(marketCode)); }
private async Task Process(MsgOp msg, NatsClient natsClient) { ExchangeCode code = ExchangeCode.UNKNOWN; string payload = msg.GetPayloadAsString(); Notification <Candle> response = JsonConvert.DeserializeObject <Notification <Candle> >(payload[1..]);
protected void Completed(object sender, bool cancelled = false, Exception error = null, ExchangeCode result = ExchangeCode.SUCCESSFUL, object userState = null) { if (OnWorkerCompleted == null) { return; } dispatcher.Invoke(OnWorkerCompleted, sender, new RunWorkerCompletedEventArgs(cancelled, error, result, userState)); }
/// <summary> /// Determines if two PhoneNumber objects are equal. /// </summary> /// <param name="other">The other phone number.</param> /// <returns><c>true</c> if equal, <c>false</c> otherwise.</returns> public bool Equals(PhoneNumber other) { return(AreaCode.Equals(other.AreaCode) && ExchangeCode.Equals(other.ExchangeCode) && SubscriberNumber.Equals(other.SubscriberNumber)); }
/// <summary> /// 网络操作后台线程 /// </summary> /// <param name="completedEventHandler">完成时调用</param> /// <param name="operation">所需的操作</param> /// <param name="beSendedData">需要发送的数据</param> /// <param name="tryTimes">尝试次数</param> /// <param name="passDown">需要在完成时传给CompletedEventHandler委托的东西</param> public UdpNetworkWorker(CompletedEventHandler completedEventHandler, ExchangeCode operation, byte[] beSendedData, object passDown = null) : base(completedEventHandler, operation, beSendedData, passDown) { }