99 lines
3.4 KiB
C#
99 lines
3.4 KiB
C#
using BinanceExchange.API.Enums;
|
|
using BinanceExchange.API.Models.Response;
|
|
using BinanceExchange.API.Models.WebSocket;
|
|
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace SignalsTest
|
|
{
|
|
public class Utils
|
|
{
|
|
public static int GetMinutesForInterval(KlineInterval interval)
|
|
|
|
{
|
|
switch (interval)
|
|
{
|
|
case KlineInterval.OneMinute:
|
|
return 1;
|
|
case KlineInterval.ThreeMinutes:
|
|
return 3;
|
|
case KlineInterval.FiveMinutes:
|
|
return 5;
|
|
case KlineInterval.FifteenMinutes:
|
|
return 15;
|
|
case KlineInterval.ThirtyMinutes:
|
|
return 30;
|
|
case KlineInterval.OneHour:
|
|
return 60;
|
|
case KlineInterval.TwoHours:
|
|
return 120;
|
|
case KlineInterval.FourHours:
|
|
return 240;
|
|
case KlineInterval.EightHours:
|
|
return 60 * 8;
|
|
case KlineInterval.TwelveHours:
|
|
return 60 * 12;
|
|
case KlineInterval.SixHours:
|
|
return 60 * 6;
|
|
case KlineInterval.OneDay:
|
|
return 60 * 24;
|
|
case KlineInterval.ThreeDays:
|
|
return 60 * 24 * 3;
|
|
case KlineInterval.OneWeek:
|
|
return 60 * 24 * 7;
|
|
|
|
default:
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
public static KlineCandleStickResponse KlineToResponse(BinanceKlineData data)
|
|
{
|
|
KlineCandleStickResponse response = new KlineCandleStickResponse();
|
|
response.Open = data.Kline.Open;
|
|
response.Close = data.Kline.Close;
|
|
response.CloseTime = data.Kline.EndTime;
|
|
response.OpenTime = data.Kline.StartTime;
|
|
response.High = data.Kline.High;
|
|
response.Low = data.Kline.Low;
|
|
response.Volume = data.Kline.Volume;
|
|
|
|
return response;
|
|
}
|
|
|
|
public static object GetPropByName(TAReport report, string propName)
|
|
{
|
|
string json = report.toJson();
|
|
Dictionary<string, string> dic = JsonConvert.DeserializeObject<Dictionary<string, string>>(json) ?? new Dictionary<string, string>();
|
|
// Console.WriteLine(dic[propName]);
|
|
return dic[propName];
|
|
}
|
|
|
|
public static List<decimal> GetAveragePoints(List<decimal> input, decimal min, decimal max){
|
|
List<decimal> processed = new List<decimal>();
|
|
List<decimal> ignoredPoints = new List<decimal>();
|
|
for(int x=0; x < input.Count; x++){
|
|
if(ignoredPoints.Contains(input[x])){continue;}//Already processed
|
|
decimal avg = input[x];
|
|
for(int y=0; y < input.Count; y++){
|
|
decimal point = input[y];
|
|
decimal diff = Math.Abs(avg-point) / (max-min);
|
|
if(diff < (decimal)0.05){
|
|
avg+=point;
|
|
avg/=2;
|
|
ignoredPoints.Add(input[y]);
|
|
}
|
|
}
|
|
|
|
processed.Add(avg);
|
|
}
|
|
|
|
return processed;
|
|
}
|
|
}
|
|
}
|