public static ReturnDataArray getDataArray(string coin, string timeGraph, string limit = "1000") { System.Threading.Thread.Sleep(6000); ReturnDataArray returnDataArray = new ReturnDataArray(); String jsonAsString = Http.get("https://api.binance.com/api/v1/klines?symbol=" + coin + "&interval=" + timeGraph + "&limit=" + limit); Newtonsoft.Json.Linq.JContainer json = (Newtonsoft.Json.Linq.JContainer)JsonConvert.DeserializeObject(jsonAsString); returnDataArray.arrayPriceClose = new double[json.Count]; returnDataArray.arrayPriceHigh = new double[json.Count]; returnDataArray.arrayPriceLow = new double[json.Count]; returnDataArray.arrayPriceOpen = new double[json.Count]; returnDataArray.arrayVolume = new double[json.Count]; returnDataArray.arrayDate = new double[json.Count]; returnDataArray.arrayQuoteVolume = new double[json.Count]; int i = 0; foreach (JContainer element in json.Children()) { returnDataArray.arrayPriceClose[i] = double.Parse(element[4].ToString()); returnDataArray.arrayPriceHigh[i] = double.Parse(element[2].ToString()); returnDataArray.arrayPriceLow[i] = double.Parse(element[3].ToString()); returnDataArray.arrayPriceOpen[i] = double.Parse(element[1].ToString()); returnDataArray.arrayVolume[i] = double.Parse(element[5].ToString()); returnDataArray.arrayQuoteVolume[i] = double.Parse(element[7].ToString()); returnDataArray.arrayDate[i] = double.Parse(element[6].ToString()); i++; } return(returnDataArray); }
/// <summary> /// NEEDS PROPER REFACTORING /// </summary> /// <param name="urlToGet"></param> /// <param name="trackToGetId"></param> /// <param name="userId"></param> /// <param name="trackTitle"></param> /// <param name="resolveURLJson"></param> private static void DownloadSet(string urlToGet, ref string trackToGetId, ref string userId, ref string trackTitle, ref dynamic resolveURLJson) { resolveURLJson = SendAPIRequest(_api.MakeCallResolveURL(urlToGet)); trackToGetId = resolveURLJson["id"]; string setName = resolveURLJson["user"]["username"] + " - " + resolveURLJson["title"]; userId = resolveURLJson["user_id"]; //trackTitle = resolveURLJson["title"]; Newtonsoft.Json.Linq.JContainer tracklist = resolveURLJson["tracks"]; List <Track> tracks = new List <Track>(); foreach (var t in tracklist.Children()) { if (t["kind"].ToString() != "track") { ops.Log(String.Format("{0} : \n", "Found something other than a track!"), ConsoleColor.Red); ops.Log(String.Format("{0}", t.ToString()), ConsoleColor.Magenta); continue; } Track newTrack = JsonPopulatorService.GetTrackFromJToken(t); tracks.Add(newTrack); } PreviewSet(urlToGet); string theResult = ""; foreach (Track t in tracks) { try { theResult += GrabTrackById(t.Id, setName) + "\n\n"; } catch (Exception ex) { ExceptionThrown(ex, new EventArgs()); } } Console.WriteLine(theResult); //try //{ //} //catch (Exception ex) //{ // Console.WriteLine(trackToGetId.ToString() + " " + ex.Message); //} //finally //{ // Console.WriteLine(trackToGetId.ToString() + " finished."); //} }
static int Children(IntPtr L) { try { ToLua.CheckArgsCount(L, 1); Newtonsoft.Json.Linq.JContainer obj = (Newtonsoft.Json.Linq.JContainer)ToLua.CheckObject <Newtonsoft.Json.Linq.JContainer>(L, 1); Newtonsoft.Json.Linq.JEnumerable <Newtonsoft.Json.Linq.JToken> o = obj.Children(); ToLua.PushValue(L, o); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
/// <summary> /// NEEDS PROPER REFACTORING /// returns the list of track URIs /// </summary> /// <param name="urlToGet"></param> /// <param name="trackToGetId"></param> /// <param name="userId"></param> /// <param name="trackTitle"></param> /// <param name="resolveURLJson"></param> private static List <string> PreviewSet(string urlToGet) { dynamic resolveURLJson = SendAPIRequest(_api.MakeCallResolveURL(urlToGet)); string trackToGetId = resolveURLJson["id"]; string setName = resolveURLJson["user"]["username"] + " - " + resolveURLJson["title"]; string userId = resolveURLJson["user_id"]; //trackTitle = resolveURLJson["title"]; Newtonsoft.Json.Linq.JContainer tracklist = resolveURLJson["tracks"]; List <Track> tracks = new List <Track>(); double playlistSize = 0; foreach (var t in tracklist.Children()) { if (t["kind"].ToString() != "track") { ops.Log(String.Format("{0} : \n", "Found something other than a track!"), ConsoleColor.Red); ops.Log(String.Format("{0}", t.ToString()), ConsoleColor.Magenta); continue; } Track newTrack = JsonPopulatorService.GetTrackFromJToken(t); tracks.Add(newTrack); } playlistSize = tracks.Sum(x => x.GetSizeInMegabytes()); ops.Log(String.Format("{0} ", setName), ConsoleColor.Green); ops.Log(String.Format("In this set listing there are {0} track(s):", tracks.Count), ConsoleColor.White); ops.Log(String.Format("Est. Total playlist size: "), ConsoleColor.White); ops.Log(String.Format("{0:N1}MB", playlistSize), ConsoleColor.Cyan); ops.LogLines(tracks.Select(t => t.ToString()).ToArray()); //tracks.ForEach(x => GetSongInfo(x.Uri)); return(tracks.Select(x => x.Uri).ToList()); }
internal static JToken GetIndex(JContainer c, object o) { return(c.Children().ElementAt((int)o)); }
public static ReturnDataArray getDataArray(string coin, string timeGraph) { int i = 0; try { ReturnDataArray returnDataArray = new ReturnDataArray(); String jsonAsStringRSI = ""; if (source == "CACHE") { DateTime begin = DateTime.Parse("2018-01-01"); if (!System.IO.File.Exists(Program.location + @"\cache\" + coin + timeGraph + ".txt")) { System.IO.StreamWriter w = new System.IO.StreamWriter(Program.location + @"\cache\" + coin + timeGraph + ".txt", true); while (begin != DateTime.Parse("2018-12-29")) { jsonAsStringRSI = Http.get("https://api.binance.com/api/v1/klines?symbol=" + coin + "&interval=" + timeGraph + "&startTime=" + DatetimeToUnix(DateTime.Parse(begin.ToString("yyyy-MM-dd") + " 00:00:00")) + "&endTime=" + DatetimeToUnix(DateTime.Parse(begin.ToString("yyyy-MM-dd") + " 12:59:59")), false).Replace("[[", "[").Replace("]]", "]") + ","; jsonAsStringRSI += Http.get("https://api.binance.com/api/v1/klines?symbol=" + coin + "&interval=" + timeGraph + "&startTime=" + DatetimeToUnix(DateTime.Parse(begin.ToString("yyyy-MM-dd") + " 13:00:00")) + "&endTime=" + DatetimeToUnix(DateTime.Parse(begin.ToString("yyyy-MM-dd") + " 23:59:59")), false).Replace("[[", "[").Replace("]]", "]") + ","; w.Write(jsonAsStringRSI); begin = begin.AddDays(1); System.Threading.Thread.Sleep(1000); } w.Close(); w.Dispose(); jsonAsStringRSI = "[" + System.IO.File.ReadAllText(Program.location + @"\cache\" + coin + timeGraph + ".txt") + "]"; jsonAsStringRSI = jsonAsStringRSI.Substring(0, jsonAsStringRSI.Length - 1); System.IO.File.Delete(Program.location + @"\cache\" + coin + timeGraph + ".txt"); w = new System.IO.StreamWriter(Program.location + @"\cache\" + coin + timeGraph + ".txt", true); w.Write(jsonAsStringRSI); w.Close(); w.Dispose(); } jsonAsStringRSI = System.IO.File.ReadAllText(Program.location + @"\cache\" + coin + timeGraph + ".txt"); } else { jsonAsStringRSI = Http.get("https://api.binance.com/api/v1/klines?symbol=" + coin + "&interval=" + timeGraph + "&limit=1000", true); } Newtonsoft.Json.Linq.JContainer jsonRSI = (Newtonsoft.Json.Linq.JContainer)JsonConvert.DeserializeObject(jsonAsStringRSI); i = 0; foreach (JContainer element in jsonRSI.Children()) { i++; } returnDataArray.arrayPriceClose = new double[i]; returnDataArray.arrayPriceHigh = new double[i]; returnDataArray.arrayPriceLow = new double[i]; returnDataArray.arrayPriceOpen = new double[i]; returnDataArray.arrayVolume = new double[i]; returnDataArray.arrayDate = new double[i]; returnDataArray.arrayQuoteVolume = new double[i]; i = 0; foreach (JContainer element in jsonRSI.Children()) { returnDataArray.arrayPriceClose[i] = double.Parse(element[4].ToString().Replace(".", ",")); returnDataArray.arrayPriceHigh[i] = double.Parse(element[2].ToString().Replace(".", ",")); returnDataArray.arrayPriceLow[i] = double.Parse(element[3].ToString().Replace(".", ",")); returnDataArray.arrayPriceOpen[i] = double.Parse(element[1].ToString().Replace(".", ",")); returnDataArray.arrayVolume[i] = double.Parse(element[5].ToString().Replace(".", ",")); returnDataArray.arrayQuoteVolume[i] = double.Parse(element[7].ToString().Replace(".", ",")); returnDataArray.arrayDate[i] = double.Parse(element[6].ToString().Replace(".", ",")); i++; } return(returnDataArray); } catch (Exception ex) { return(null); } }
public static void Main(string[] args) { Logger.log("# Money Machine version 0.2 #"); while (true) { String jsonAsString = Http.get("https://poloniex.com/public?command=returnTicker"); Newtonsoft.Json.Linq.JContainer jcontainer = (Newtonsoft.Json.Linq.JContainer)JsonConvert.DeserializeObject(jsonAsString); foreach (JContainer element in jcontainer.Children()) { String coin = element.ToString().Split(':')[0].ToString(); if (coin.IndexOf("BTC") >= 0) { Newtonsoft.Json.Linq.JContainer detailsContainer = (Newtonsoft.Json.Linq.JContainer)JsonConvert.DeserializeObject("{" + element.ToString().Split('{')[1]); decimal last = decimal.Parse(detailsContainer["last"].ToString().Replace(".", ",")); decimal high24hr = decimal.Parse(detailsContainer["high24hr"].ToString().Replace(".", ",")); if (last >= high24hr) { Logger.log(element.ToString()); } } } Logger.log("Sleep 1s"); System.Threading.Thread.Sleep(200); } while (true) { ReturnTicker returnTicker = ReturnTicker.Create(Http.get("https://poloniex.com/public?command=returnTicker")); Logger.log("[SELL] Highest Bid: " + returnTicker.BTC_ETH.highestBid); Logger.log("[BUY] Lowest Ask : " + returnTicker.BTC_ETH.lowestAsk); Logger.log("Base volume: " + returnTicker.BTC_ETH.baseVolume); Logger.log("High 24h: " + returnTicker.BTC_ETH.high24hr); Logger.log("ID: " + returnTicker.BTC_ETH.id); Logger.log("Frozen: " + returnTicker.BTC_ETH.isFrozen); Logger.log("Last: " + returnTicker.BTC_ETH.last); Logger.log("Low 24h: " + returnTicker.BTC_ETH.low24hr); Logger.log("Percent Change: " + returnTicker.BTC_ETH.percentChange); Logger.log("Quote volume: " + returnTicker.BTC_ETH.quoteVolume); Logger.log(""); Logger.log("Sleep 1s"); System.Threading.Thread.Sleep(1000); } // while(true) // { // // ReturnBalances returnBalances = ReturnBalances.Create(Http.post("https://poloniex.com/tradingApi","command=returnBalances")); // // Logger.log("## Balance ##"); // Logger.log("My balance BTC: " + returnBalances.BTC); // Logger.log("My balance LTC: " + returnBalances.LTC); // Logger.log(""); // // Logger.log("## Ticker BTC/LTC ##"); // ReturnTicker returnTicker = ReturnTicker.Create(Http.get("https://poloniex.com/public?command=returnTicker")); // Logger.log("[SELL] Highest Bid: " + returnTicker.BTC_LTC.highestBid); // Logger.log("[BUY] Lowest Ask : " + returnTicker.BTC_LTC.lowestAsk); // Logger.log("Base volume: " + returnTicker.BTC_LTC.baseVolume); // Logger.log("High 24h: " + returnTicker.BTC_LTC.high24hr); // Logger.log("ID: " + returnTicker.BTC_LTC.id); // Logger.log("Frozen: " + returnTicker.BTC_LTC.isFrozen); // Logger.log("Last: " + returnTicker.BTC_LTC.last); // Logger.log("Low 24h: " + returnTicker.BTC_LTC.low24hr); // Logger.log("Percent Change: " + returnTicker.BTC_LTC.percentChange); // Logger.log("Quote volume: " + returnTicker.BTC_LTC.quoteVolume); // Logger.log(""); // // if(double.Parse(returnBalances.LTC.Replace(".",",")) <= 0.01) // { // Logger.log("Lets buy LTC..."); // Logger.log("Lower value in 24h " + returnTicker.BTC_LTC.low24hr); // Logger.log("Try buy fast..."); // // MyOperation myOperation = new MyOperation(); // myOperation.typeOrder = "buy"; // myOperation.amount = "0.01"; // myOperation.currencyPair = "BTC_LTC"; // myOperation.rate = returnTicker.BTC_LTC.low24hr; // myOperation.date = DateTime.Now; // // ReturnOperation returnOperation = ReturnOperation.Create(Http.post("https://poloniex.com/tradingApi","command="+myOperation.typeOrder+"¤cyPair="+myOperation.currencyPair+"&amount="+myOperation.amount+"&rate=" + myOperation.rate)); // // myOperation.orderNumber = returnOperation.orderNumber.ToString(); // Database.SerializeObject(myOperation); // // } // else // { // // List<ReturnOpenOrders> orders = ReturnOpenOrders.Create(Http.post("https://poloniex.com/tradingApi","command=returnOpenOrders¤cyPair=BTC_LTC")); // // if(orders.Count <= 0 ) // { // MyOperation myOperation = Database.DeSerializeObject<MyOperation>(); // // Logger.log("Lets sell LTC..."); // Logger.log("Lower value in 24h " + returnTicker.BTC_LTC.high24hr); // Logger.log("Try sell fast..."); // // Logger.log("[buy ] " + myOperation.rate); // Logger.log("[sell] " + myOperation.rateSell(returnTicker).ToString()); // Logger.log("[prof] " + myOperation.profit(returnTicker).ToString()); // // ReturnOperation returnOperation = ReturnOperation.Create(Http.post("https://poloniex.com/tradingApi","command=sell¤cyPair=BTC_LTC&amount=0.01&rate=" + myOperation.rateSell(returnTicker).ToString())); // } // else // { // Logger.log("Wait order sell..."); // Logger.log("rate order: " + orders[0].rate.ToString()); // } // // //List<ReturnHistory> history = ReturnHistory.Create(Http.post("https://poloniex.com/tradingApi","command=returnOrderTrades&orderNumber=" + returnOperation.orderNumber)); // // } // // // // // Logger.log("Sleep 1s"); // System.Threading.Thread.Sleep(100000000); // } }