Merge pull request #215 from HojouFotytu/develop
Binance USD market error
This commit is contained in:
commit
235dcd59e4
|
@ -20,27 +20,32 @@ namespace Core.MarketAnalyzer
|
||||||
public static double GetMainCurrencyPrice(string mainMarket, PTMagicConfiguration systemConfiguration, LogHelper log)
|
public static double GetMainCurrencyPrice(string mainMarket, PTMagicConfiguration systemConfiguration, LogHelper log)
|
||||||
{
|
{
|
||||||
double result = 0;
|
double result = 0;
|
||||||
|
if (mainMarket != "USD")
|
||||||
try
|
|
||||||
{
|
{
|
||||||
string baseUrl = "https://api.binance.us/api/v1/ticker/24hr?symbol=" + mainMarket + "USDT";
|
try
|
||||||
|
|
||||||
log.DoLogInfo("BinanceUS - Getting main market price...");
|
|
||||||
Newtonsoft.Json.Linq.JObject jsonObject = GetSimpleJsonObjectFromURL(baseUrl, log, null);
|
|
||||||
if (jsonObject != null)
|
|
||||||
{
|
{
|
||||||
log.DoLogInfo("BinanceUS - Market data received for " + mainMarket + "USDT");
|
string baseUrl = "https://api.binance.us/api/v1/ticker/24hr?symbol=" + mainMarket + "USDT";
|
||||||
|
|
||||||
result = (double)jsonObject.GetValue("lastPrice");
|
log.DoLogInfo("BinanceUS - Getting main market price...");
|
||||||
log.DoLogInfo("BinanceUS - Current price for " + mainMarket + "USDT: " + result.ToString("#,#0.00") + " USD");
|
Newtonsoft.Json.Linq.JObject jsonObject = GetSimpleJsonObjectFromURL(baseUrl, log, null);
|
||||||
|
if (jsonObject != null)
|
||||||
|
{
|
||||||
|
log.DoLogInfo("BinanceUS - Market data received for " + mainMarket + "USDT");
|
||||||
|
|
||||||
|
result = (double)jsonObject.GetValue("lastPrice");
|
||||||
|
log.DoLogInfo("BinanceUS - Current price for " + mainMarket + "USDT: " + result.ToString("#,#0.00") + " USD");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
log.DoLogCritical(ex.Message, ex);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
else
|
||||||
{
|
{
|
||||||
log.DoLogCritical(ex.Message, ex);
|
return 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<string> GetMarketData(string mainMarket, Dictionary<string, MarketInfo> marketInfos, PTMagicConfiguration systemConfiguration, LogHelper log)
|
public static List<string> GetMarketData(string mainMarket, Dictionary<string, MarketInfo> marketInfos, PTMagicConfiguration systemConfiguration, LogHelper log)
|
||||||
|
@ -58,7 +63,7 @@ namespace Core.MarketAnalyzer
|
||||||
if (jsonArray.Count > 0)
|
if (jsonArray.Count > 0)
|
||||||
{
|
{
|
||||||
double mainCurrencyPrice = 1;
|
double mainCurrencyPrice = 1;
|
||||||
if (!mainMarket.Equals("USDT", StringComparison.InvariantCultureIgnoreCase))
|
if (!mainMarket.Equals("USDT", StringComparison.InvariantCultureIgnoreCase) && !mainMarket.Equals("USD", StringComparison.InvariantCultureIgnoreCase))
|
||||||
{
|
{
|
||||||
mainCurrencyPrice = BinanceUS.GetMainCurrencyPrice(mainMarket, systemConfiguration, log);
|
mainCurrencyPrice = BinanceUS.GetMainCurrencyPrice(mainMarket, systemConfiguration, log);
|
||||||
}
|
}
|
||||||
|
@ -238,40 +243,45 @@ namespace Core.MarketAnalyzer
|
||||||
}
|
}
|
||||||
|
|
||||||
bool go = true;
|
bool go = true;
|
||||||
while (ticksFetched < ticksNeeded && go)
|
if (!(marketName == "USDUSDT"))
|
||||||
{
|
{
|
||||||
baseUrl = "https://api.binance.us/api/v1/klines?interval=1m&symbol=" + marketName + "&endTime=" + endTime.ToString() + "&limit=" + ticksLimit.ToString();
|
while (ticksFetched < ticksNeeded && go)
|
||||||
|
|
||||||
log.DoLogDebug("BinanceUS - Getting " + ticksLimit.ToString() + " ticks for '" + marketName + "'...");
|
|
||||||
Newtonsoft.Json.Linq.JArray jsonArray = GetSimpleJsonArrayFromURL(baseUrl, log);
|
|
||||||
if (jsonArray.Count > 0)
|
|
||||||
{
|
{
|
||||||
log.DoLogDebug("BinanceUS - " + jsonArray.Count.ToString() + " ticks received.");
|
|
||||||
|
|
||||||
foreach (Newtonsoft.Json.Linq.JArray marketTick in jsonArray)
|
baseUrl = "https://api.binance.us/api/v1/klines?interval=1m&symbol=" + marketName + "&endTime=" + endTime.ToString() + "&limit=" + ticksLimit.ToString();
|
||||||
|
|
||||||
|
log.DoLogDebug("BinanceUS - Getting " + ticksLimit.ToString() + " ticks for '" + marketName + "'...");
|
||||||
|
Newtonsoft.Json.Linq.JArray jsonArray = GetSimpleJsonArrayFromURL(baseUrl, log);
|
||||||
|
if (jsonArray.Count > 0)
|
||||||
{
|
{
|
||||||
|
log.DoLogDebug("BinanceUS - " + jsonArray.Count.ToString() + " ticks received.");
|
||||||
|
|
||||||
MarketTick tick = new MarketTick();
|
foreach (Newtonsoft.Json.Linq.JArray marketTick in jsonArray)
|
||||||
tick.Price = (double)marketTick[4];
|
{
|
||||||
tick.Volume24h = (double)marketTick[7];
|
|
||||||
tick.Time = Constants.Epoch.AddMilliseconds((Int64)marketTick[0]);
|
|
||||||
|
|
||||||
result.Add(tick);
|
MarketTick tick = new MarketTick();
|
||||||
|
tick.Price = (double)marketTick[4];
|
||||||
|
tick.Volume24h = (double)marketTick[7];
|
||||||
|
tick.Time = Constants.Epoch.AddMilliseconds((Int64)marketTick[0]);
|
||||||
|
|
||||||
|
result.Add(tick);
|
||||||
|
}
|
||||||
|
|
||||||
|
ticksFetched = ticksFetched + jsonArray.Count;
|
||||||
|
endTime = endTime - ticksLimit * 60 * 1000;
|
||||||
|
if (ticksNeeded - ticksFetched < ticksLimit)
|
||||||
|
{
|
||||||
|
ticksLimit = ticksNeeded - ticksFetched;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
ticksFetched = ticksFetched + jsonArray.Count;
|
|
||||||
endTime = endTime - ticksLimit * 60 * 1000;
|
|
||||||
if (ticksNeeded - ticksFetched < ticksLimit)
|
|
||||||
{
|
{
|
||||||
ticksLimit = ticksNeeded - ticksFetched;
|
log.DoLogDebug("BinanceUS - No ticks received.");
|
||||||
|
go = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
log.DoLogDebug("BinanceUS - No ticks received.");
|
|
||||||
go = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (WebException ex)
|
catch (WebException ex)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue