private void ShowChartClick(object sender, RoutedEventArgs e) { var security = SelectedSecurity; CandleSeries series; if (IsRealTime.IsChecked == true) { var type = CandleType.GetSelectedValue <CandleTypes>().Value; switch (type) { case CandleTypes.TimeFrame: series = new CandleSeries(typeof(TimeFrameCandle), security, TimeFrame.Value.Value.TimeOfDay); break; case CandleTypes.Tick: series = new CandleSeries(typeof(TickCandle), security, VolumeCtrl.Text.To <int>()); break; case CandleTypes.Volume: series = new CandleSeries(typeof(VolumeCandle), security, VolumeCtrl.Text.To <decimal>()); break; case CandleTypes.Range: series = new CandleSeries(typeof(RangeCandle), security, PriceRange.Value); break; default: throw new ArgumentOutOfRangeException(); } } else { var timeFrame = (TimeSpan)HistoryInterval.SelectedItem; series = new CandleSeries(typeof(TimeFrameCandle), security, timeFrame); } _chartWindows.SafeAdd(series, key => { var wnd = new ChartWindow { Title = "{0} {1} {2}".Put(security.Code, series.CandleType.Name.Replace("Candle", string.Empty), series.Arg) }; wnd.MakeHideable(); var area = new ChartArea(); wnd.Chart.Areas.Add(area); var candlesElem = new ChartCandleElement(); area.Elements.Add(candlesElem); series.ProcessCandle += candle => wnd.Chart.Draw(candlesElem, candle); return(wnd); }).Show(); _candleManager.Start(series, (DateTime)From.Value, (DateTime)To.Value); }
/// <summary> /// [Public API]指定された年(UTC)のローソク足データを返します。 /// </summary> /// <param name="pair">通貨ペア</param> /// <param name="type">ローソク足の期間</param> /// <param name="query">クエリ</param> /// <returns>ローソク足データ</returns> /// <exception cref="BitbankDotNetException">APIリクエストでエラーが発生しました。</exception> async Task <Ohlcv[]> GetCandlesticksAsync(CurrencyPair pair, CandleType type, string query) { var path = CandlestickPath + type.GetEnumMemberValue() + $"/{query}"; var result = await PublicApiGetAsync <CandlestickList>(path, pair).ConfigureAwait(false); return(result.Candlesticks[0].Ohlcv); }
private void PostInit() { var accessKey = Program.Accesskey; var secretEky = Program.Secretkey; ApiData = new ApiData(accessKey, secretEky); React = new React(accessKey, secretEky); AlgorithmList = BotSetting.AlgorithmList; CandleTypeList = BotSetting.CandleTypeList; CoinList = BotSetting.CoinList; Algorithm = AlgorithmList.Where(x => x.Id == Settings.Default.algorithm).FirstOrDefault(); CandleType = CandleTypeList.Where(x => x.Minute == Settings.Default.candleType).FirstOrDefault(); Coin = CoinList.Where(x => x.Ticker.Equals(Settings.Default.coin)).FirstOrDefault(); algorithmBindingSource.DataSource = AlgorithmList; candleTypeBindingSource.DataSource = CandleTypeList; coinBindingSource.DataSource = CoinList; Algorithm = BotSetting.AlgorithmList.Where(x => x.Id == Settings.Default.algorithm).FirstOrDefault(); CandleType = new CandleType(Settings.Default.candleType); Coin = BotSetting.CoinList.Where(x => x.Ticker.Equals(Settings.Default.coin)).FirstOrDefault(); FeeRate = Settings.Default.feeRate; TradeRate = Settings.Default.tradeRate; Interval = Convert.ToInt32(Settings.Default.interval); TriggerRate = Settings.Default.triggerRate; CandleCount = Convert.ToInt32(Settings.Default.candleCount); }
/// <summary> /// <see cref="GetCandlesticks(string, CandleType, DateTime, DateTime)"/> /// </summary> public async Task <IList <Candle> > GetCandlesticksAsync(string symbol, CandleType type, DateTime start, DateTime end) { var param = new Dictionary <string, object>(); param["symbol"] = symbol; param["startTime"] = start.ToUniversalTime().ToString("yyyy-MM-dd'T'HH:mm:ss.fff'Z'"); param["endTime"] = end.ToUniversalTime().ToString("yyyy-MM-dd'T'HH:mm:ss.fff'Z'"); param["start"] = "0"; param["count"] = "750"; param["binSize"] = type == CandleType.OneMinute ? "1m" : type == CandleType.FiveMinutes ? "5m" : type == CandleType.OneHour ? "1h" : type == CandleType.OneDay ? "1d" : throw new BitmexUnexpectedArgument(); string apiUrl = "/trade/bucketed"; string response = await request.Query("GET", apiUrl, param, true).ConfigureAwait(false); if (string.IsNullOrEmpty(response)) { throw new BitmexNoResponse(string.Format("Request to {0} returned empty", apiUrl)); } JToken jsonResponse = JsonConvert.DeserializeObject <JToken>(response); ValidateResponse(apiUrl, jsonResponse); IList <Candle> candles = new List <Candle>(); JArray jArray = jsonResponse as JArray; if (jArray.Count == 0) { return(candles); // did not return any candle } try { foreach (var jToken in jArray) { var candle = new Candle(); candle.Symbol = jToken["symbol"].Value <string>(); candle.Timestamp = DateTime.SpecifyKind(jToken["timestamp"].Value <DateTime>(), DateTimeKind.Utc); candle.Open = jToken["open"].Value <double>(); candle.High = jToken["high"].Value <double>(); candle.Low = jToken["low"].Value <double>(); candle.Close = jToken["close"].Value <double>(); candle.Volume = jToken["volume"].Value <double>(); candle.Type = type; candles.Add(candle); } } catch { throw new BitmexResponseParseError(string.Format("Response of {0} couldn't be parsed as expected", apiUrl)); } return(candles); }
private async Task <(bool, Candle)> HandleAsync(string assetPairId, DateTime time, double price, CandleType candleType) { var candle = _candles[candleType]; if (candle == null) { candle = await _candlesService.GetLastAsync(assetPairId, candleType); } var trimmedTime = time.Trim(candleType); if (candle == null || candle.Time != trimmedTime) { candle = new Candle(trimmedTime, candleType, assetPairId, price); _candles[candleType] = candle; return(true, candle); } candle.Update(price); _candles[candleType] = candle; return(false, candle); }
private void Bot_Load(object sender, EventArgs e) { Algorithm = BotSetting.AlgorithmList.Where(x => x.Id == Settings.Default.algorithm).FirstOrDefault(); CandleType = new CandleType(Settings.Default.candleType); Coin = BotSetting.CoinList.Where(x => x.Ticker.Equals(Settings.Default.coin)).FirstOrDefault(); FeeRate = Settings.Default.feeRate; TradeRate = Settings.Default.tradeRate; Interval = Convert.ToInt32(Settings.Default.interval); TriggerRate = Settings.Default.triggerRate; CandleCount = Convert.ToInt32(Settings.Default.candleCount); //cmbAlgorithm.SelectedItem = Algorithm; //cmbCandle.SelectedItem = CandleType; //txtFee.Text = FeeRate.ToString(); //txtTradeRate.Text = TradeRate.ToString(); //cmbCoin.SelectedItem = Coin; //txtInterval.Text = Interval.ToString(); //txtTriggerRate.Text = TriggerRate.ToString(); //txtCandleCount.Text = CandleCount.ToString(); cmbAlgorithm.SelectedItem = Algorithm; cmbCandle.SelectedItem = CandleType; cmbCoin.SelectedItem = Coin; txtFee.Text = FeeRate.ToString(); txtTradeRate.Text = TradeRate.ToString(); txtInterval.Text = Interval.ToString(); txtTriggerRate.Text = TriggerRate.ToString(); txtCandleCount.Text = CandleCount.ToString(); }
private void OnCandleReceived(Candle candle, CandleType type) { CandleReceived?.Invoke(this, new CandleReceivedArgs() { Candle = candle, Type = type }); }
private void ProcessTimerTick(ElapsedEventArgs e, CandleType candleType) { RestClient client = new RestClient(); List <Candle> candles = new List <Candle>(); RestRequest request = new RestRequest("https://kite.zerodha.com/oms/instruments/historical/11984386/5minute?user_id=ZW2177&oi=1&from=2020-12-01&to=2020-12-01&ciqrandom=1606573753955", Method.GET, DataFormat.Json); request.AddHeader("authorization", Token); dynamic result = JsonConvert.DeserializeObject(client.Execute(request).Content); if (result.status == "error" && result.error_type == "TokenException") { Logger.Log("Token Expired"); return; } foreach (dynamic candle in result.data.candles) { candles.Add(new Candle() { TimeStamp = candle[0], Open = candle[1], Close = candle[4], High = candle[2], Low = candle[3], Volume = candle[5], CandleVolume = candle[5], Instrument = 11984386, }); } OnCandleReceived(candles.Last(), CandleType.FiveMinute); }
/// <summary> /// Save settings. /// </summary> /// <param name="storage">Settings storage.</param> public void Save(SettingsStorage storage) { if (Security != null) { storage.SetValue(nameof(SecurityId), Security.Id); } if (CandleType != null) { storage.SetValue(nameof(CandleType), CandleType.GetTypeName(false)); } if (Arg != null) { storage.SetValue(nameof(Arg), Arg); } storage.SetValue(nameof(From), From); storage.SetValue(nameof(To), To); if (WorkingTime != null) { storage.SetValue(nameof(WorkingTime), WorkingTime); } storage.SetValue(nameof(IsCalcVolumeProfile), IsCalcVolumeProfile); }
private void ReadSettings(bool bindControl = true) { Algorithm = BotSetting.AlgorithmList.Where(x => x.Id == Settings.Default.algorithm).First(); CandleType = new CandleType(Settings.Default.candleType); FeeRate = Settings.Default.fee; TradeRate = Settings.Default.tradeRate; Coin = BotSetting.CoinList.Where(x => x.Ticker.Equals(Settings.Default.coin)).FirstOrDefault(); Interval = Convert.ToInt32(Settings.Default.interval); Rate = Convert.ToDouble(Settings.Default.rate); CandleCount = Convert.ToInt32(Settings.Default.candleCount); ProfitRate = Settings.Default.profit; if (bindControl) { cmbAlgorithm.SelectedItem = Algorithm; cmbCandle.SelectedItem = CandleType; txtFee.Text = FeeRate.ToString(); txtTradeRate.Text = TradeRate.ToString(); cmbCoin.SelectedItem = Coin; txtInterval.Text = Interval.ToString(); txtRate.Text = Rate.ToString(); txtCandleCount.Text = CandleCount.ToString(); txtProfit.Text = ProfitRate.ToString(); } }
public Task <IReadOnlyList <Candle> > GetAsync(string assetPairId, CandleType candleType, DateTime startDate, DateTime endDate) { var candles = _candlesCache.GetAsync(assetPairId, candleType, startDate, endDate); return(Task.FromResult(candles)); }
public static List <Candle> ConvertCandleToCandle(List <Candle> candles, CandleType type) { var result = new List <Candle>(); DateTime currentCandleTime = CandleHelper.GetCandleTime(candles[0].CandleTime, candles[0].TradingDay, type); var currentCandle = new List <Candle>() { candles[0] }; for (int i = 1; i < candles.Count; i++) { Candle item = candles[i]; DateTime newCandleTime = CandleHelper.GetCandleTime(item.CandleTime, item.TradingDay, type); if (newCandleTime != currentCandleTime) { Candle newCandle = CombineCandle(currentCandle, currentCandleTime); result.Add(newCandle); currentCandleTime = newCandleTime; currentCandle.Clear(); currentCandle.Add(item); } currentCandle.Add(item); } result.Add(CombineCandle(currentCandle, currentCandleTime)); return(result); }
private void CandleTypesSelectionChanged(object sender, SelectionChangedEventArgs e) { var type = CandleType.GetSelectedValue <CandleTypes>().Value; TimeFrame.SetVisibility(type == CandleTypes.TimeFrame); PriceRange.SetVisibility(type == CandleTypes.Range); VolumeCtrl.SetVisibility(type == CandleTypes.Tick || type == CandleTypes.Volume); }
public void CandleSymbolPeriodTest(string symbolString, double expectedValue, CandleType expectedType) { var symbol = CandleSymbol.ValueOf(symbolString); Assert.AreEqual(symbolString, symbol.ToString()); Assert.AreEqual(expectedValue, symbol.PeriodValue, Delta); Assert.AreEqual(expectedType.Id, symbol.PeriodId); }
public static DateTime Trim(this DateTime value, CandleType candleType) { return(candleType switch { CandleType.Minute => TrimToMinutes(value), CandleType.Hour => TrimToHours(value), CandleType.Day => TrimToDays(value), CandleType.Month => TrimToMonths(value), _ => throw new InvalidEnumArgumentException() });
public Candle(DateTime time, CandleType type, string assetPairId, double price) { Time = time; Type = type; AssetPairId = assetPairId; Open = price; Close = price; High = price; Low = price; }
public CandleType GetOrCreateCandleType(int?CandleTypeID) { CandleType item = this.CandleType.FirstOrDefault(x => x.CandleTypeID == CandleTypeID); if (item == null) { item = new CandleType(); this.CandleType.AddObject(item); } return(item); }
public MainWindow() { InitializeComponent(); CandleType.SetDataSource <CandleTypes>(); CandleType.SetSelectedValue <CandleTypes>(CandleTypes.TimeFrame); TimeFrame.Value = new DateTime(TimeSpan.FromMinutes(5).Ticks); // попробовать сразу найти месторасположение Quik по запущенному процессу Path.Text = QuikTerminal.GetDefaultPath(); }
private void ReadSettings() { Algorithm = BotSetting.AlgorithmList.Where(x => x.Id == Settings.Default.algorithm).First(); CandleType = new CandleType(Settings.Default.candleType); Fee = Settings.Default.fee; TradeRate = Settings.Default.tradeRate; Coin = BotSetting.CoinList.Where(x => x.Ticker.Equals(Settings.Default.coin)).FirstOrDefault(); Interval = Convert.ToInt32(Settings.Default.interval); Rate = Convert.ToDouble(Settings.Default.rate); CandleCount = Convert.ToInt32(Settings.Default.candleCount); }
public CandleType GetOrCreateCandleType(int?CandleTypeID) { if (CandleTypeID.GetValueOrDefault(0) > 0) { return(this.CandleType.FirstOrDefault(x => x.CandleTypeID == CandleTypeID)); } var newItem = new CandleType(); this.CandleType.AddObject(newItem); return(newItem); }
public static List<Candle> GetCandles(string instrumentID, CandleType type, DateTime fromTradingDay) { List<Candle> minuteCandles = CandleDAL.Get(instrumentID, fromTradingDay); if (type == CandleType.Minute) { return minuteCandles; } else { return CandleHelper.ConvertCandleToCandle(minuteCandles, type); } }
private void Bot_Load(object sender, EventArgs e) { Algorithm = BotSetting.AlgorithmList.Where(x => x.Id == Settings.Default.algorithm).First(); CandleType = new CandleType(Settings.Default.candleType); Fee = Settings.Default.fee; TradeRate = Settings.Default.tradeRate //Algorithm = cmbAlgorithm.SelectedIndex; //var currPrice = ApiData.getCandle<List<Candle>>(CoinName, CandleType, 1).First().Close; //var orderChance = GetOrderChance(ApiData, CoinName, currPrice); }
public static List <Candle> GetCandles(string instrumentID, CandleType type, DateTime fromTradingDay) { List <Candle> minuteCandles = CandleDAL.Get(instrumentID, fromTradingDay); if (type == CandleType.Minute) { return(minuteCandles); } else { return(CandleHelper.ConvertCandleToCandle(minuteCandles, type)); } }
public async Task<IActionResult> GetAsync(string assetPairId, CandleType candleType, DateTime startDate, DateTime endDate) { if (string.IsNullOrWhiteSpace(assetPairId)) return NotFound(); var candles = await _candlesService.GetAsync(assetPairId, Enum.Parse<Domain.Entities.CandleType>(candleType.ToString()), startDate, endDate); var model = _mapper.Map<List<CandleModel>>(candles); return Ok(model); }
public MainWindow() { InitializeComponent(); CandleType.SetDataSource <CandleTypes>(); CandleType.SetSelectedValue <CandleTypes>(CandleTypes.TimeFrame); TimeFrame.Value = new DateTime(TimeSpan.FromMinutes(5).Ticks); HistoryInterval.ItemsSource = SmartComTimeFrames.AllTimeFrames; HistoryInterval.SelectedIndex = 2; From.Value = DateTime.Today - TimeSpan.FromDays(7); To.Value = DateTime.Now; Security.ItemsSource = _securitiesSource; }
/// <summary> /// Save settings. /// </summary> /// <param name="storage">Settings storage.</param> public void Save(SettingsStorage storage) { if (Security != null) { storage.SetValue("SecurityId", Security.Id); } storage.SetValue("CandleType", CandleType.GetTypeName(false)); storage.SetValue("Arg", Arg); storage.SetValue("From", From); storage.SetValue("To", To); storage.SetValue("WorkingTime", WorkingTime); storage.SetValue("IsCalcVolumeProfile", IsCalcVolumeProfile); }
private void Bot_Load(object sender, EventArgs e) { Algorithm = BotSetting.AlgorithmList.Where(x => x.Id == Settings.Default.algorithm).First(); CandleType = new CandleType(Settings.Default.candleType); Fee = Settings.Default.fee; TradeRate = Settings.Default.tradeRate; Coin = BotSetting.CoinList.Where(x => x.Ticker.Equals(Settings.Default.coin)).FirstOrDefault(); Interval = Convert.ToInt32(Settings.Default.interval); TriggerRate = //Algorithm = cmbAlgorithm.SelectedIndex; //var currPrice = ApiData.getCandle<List<Candle>>(CoinName, CandleType, 1).First().Close; //var orderChance = GetOrderChance(ApiData, CoinName, currPrice); }
private static async Task LoadInterval(CandleType candle, string source, CandlesPersistentAzureStorage storage, string symbol, int digits, bool isRevert) { Console.WriteLine(); Console.WriteLine($"----- {candle.ToString()} --------"); var interval = ""; switch (candle) { case CandleType.Minute: interval = "1m"; break; case CandleType.Hour: interval = "1h"; break; case CandleType.Day: interval = "1d"; break; case CandleType.Month: interval = "1M"; break; } var data = await GetCandles(source, 1000, interval, 0, isRevert, digits); var count = 0; //while (data.Any() && count < 45000) while (data.Any() && count < 3000) { Console.Write($"Read {data.Count} items from Binance ... "); await storage.BulkSave(symbol, true, digits, candle, data); await storage.BulkSave(symbol, false, digits, candle, data); Console.WriteLine($"Save {data.Count} items"); var lastTime = data.Min(e => e.DateTime).UnixTime(); count += data.Count; data = await GetCandles(source, 1000, interval, lastTime - 1, isRevert, digits); } }
public static DateTime GetCandleTime(DateTime time, DateTime tradingDay, CandleType type) { switch (type) { case CandleType.Minute: return new DateTime(time.Year, time.Month, time.Day, time.Hour, time.Minute, 0); case CandleType.Hour: return new DateTime(time.Year, time.Month, time.Day, time.Hour, 0, 0); case CandleType.Day: return tradingDay; case CandleType.Week: return tradingDay.AddDays(-(int)tradingDay.DayOfWeek); case CandleType.Month: return new DateTime(tradingDay.Year, tradingDay.Month, 1); } return time; }
private static int GetMinutesToTrack(CandleType candleType) { int backTrackMinutes = -1; if (candleType == CandleType.Minute) { backTrackMinutes = -1; } else if (candleType == CandleType.ThreeMinute) { backTrackMinutes = -3; } else if (candleType == CandleType.FiveMinute) { backTrackMinutes = -5; } return(backTrackMinutes); }
public DateTime SelectFrame(DateTime dt, CandleType candle) { switch (candle) { case CandleType.Minute: return(new DateTime(dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, 0)); case CandleType.Hour: return(new DateTime(dt.Year, dt.Month, dt.Day, dt.Hour, 0, 0)); case CandleType.Day: return(new DateTime(dt.Year, dt.Month, dt.Day, 0, 0, 0)); case CandleType.Month: return(new DateTime(dt.Year, dt.Month, 1, 0, 0, 0)); } throw new Exception($"Unknown candle type {candle}"); }
public Bot() { InitializeComponent(); cmbAlgorithm.DataSource = new BindingSource(BotSetting.AlgorithmList, null); cmbAlgorithm.ValueMember = "Key"; cmbAlgorithm.DisplayMember = "Value"; cmbAlgorithm.SelectedIndex = Settings.Default.algorithm; var algIdx = cmbAlgorithm.SelectedIndex; var idx = (algIdx > 0) ? algIdx : Convert.ToInt32(txtMinute.Text); CandleType = new CandleType(Settings.Default.candleType); cmbCoin.DataSource = new BindingSource(BotSetting.Coins, null); cmbCoin.ValueMember = "Ticker"; cmbCoin.DisplayMember = "CoinName"; cmbCoin.SelectedValue = Settings.Default.coin; CoinName = ((Coin)cmbCoin.SelectedItem).Ticker; }
public static List<Candle> ConvertCandleToCandle(List<Candle> candles, CandleType type) { var result = new List<Candle>(); DateTime currentCandleTime = CandleHelper.GetCandleTime(candles[0].CandleTime, candles[0].TradingDay, type); var currentCandle = new List<Candle>() { candles[0] }; for (int i = 1; i < candles.Count; i++) { Candle item = candles[i]; DateTime newCandleTime = CandleHelper.GetCandleTime(item.CandleTime, item.TradingDay, type); if (newCandleTime != currentCandleTime) { Candle newCandle = CombineCandle(currentCandle, currentCandleTime); result.Add(newCandle); currentCandleTime = newCandleTime; currentCandle.Clear(); currentCandle.Add(item); } currentCandle.Add(item); } result.Add(CombineCandle(currentCandle, currentCandleTime)); return result; }
public CandleBuilder(Candle lastData, CandleType type) { this.LastData = lastData; this.type = type; }