private static string CURRENCY = "TBTC"; //user BTC for production public Hpo() { var config = new NLog.Config.LoggingConfiguration(); var logconsole = new NLog.Targets.ConsoleTarget("logconsole"); config.AddRule(LogLevel.Info, LogLevel.Fatal, logconsole); NLog.LogManager.Configuration = config; Api api = new Api(URL_ROOT, ORG_ID, API_KEY, API_SECRET); //get server time string timeResponse = api.get("/api/v2/time"); ServerTime serverTimeObject = Newtonsoft.Json.JsonConvert.DeserializeObject <ServerTime>(timeResponse); string time = serverTimeObject.serverTime; Logger.Info("server time: {}", time); //get algo settings string algosResponse = api.get("/main/api/v2/mining/algorithms"); DataSet algoObject = Newtonsoft.Json.JsonConvert.DeserializeObject <DataSet>(algosResponse); DataTable algoTable = algoObject.Tables["miningAlgorithms"]; DataRow mySettings = null; foreach (DataRow algo in algoTable.Rows) { if (algo["algorithm"].Equals(ALGORITHM)) { mySettings = algo; } } Logger.Info("algo settings: {}", mySettings["algorithm"]); //get balance string accountsResponse = api.get("/main/api/v2/accounting/accounts2", true, time); Currencies currenciesObj = Newtonsoft.Json.JsonConvert.DeserializeObject <Currencies>(accountsResponse); double myBalace = 0; foreach (Currency c in currenciesObj.currencies) { if (c.currency.Equals(CURRENCY)) { myBalace = c.available; } } Logger.Info("balance: {} {}", myBalace, CURRENCY); //create pool Dictionary <string, string> pool = new Dictionary <string, string> { { "algorithm", ALGORITHM }, { "name", "my pool " + Guid.NewGuid().ToString() }, { "username", "pool_username" }, //your pool username { "password", "x" }, //your pool password { "stratumHostname", "pool.host.name" }, //pool hostname { "stratumPort", "3456" } //pool port }; string poolResponse = api.post("/main/api/v2/pool", Newtonsoft.Json.JsonConvert.SerializeObject(pool), time, false); Pool poolObject = Newtonsoft.Json.JsonConvert.DeserializeObject <Pool>(poolResponse); string myPoolId = poolObject.id; Logger.Info("new pool id: {}", myPoolId); //create order Dictionary <string, string> order = new Dictionary <string, string> { { "algorithm", ALGORITHM }, { "amount", (string)mySettings["minimalOrderAmount"] }, { "displayMarketFactor", (string)mySettings["displayMarketFactor"] }, { "limit", (string)mySettings["minSpeedLimit"] }, // GH [minSpeedLimit-maxSpeedLimit] || 0 - unlimited speed { "market", "EU" }, { "marketFactor", (string)mySettings["marketFactor"] }, { "poolId", myPoolId }, { "price", "0.0010" }, //per BTC/GH/day { "type", "STANDARD" } }; string newOrderResponse = api.post("/main/api/v2/hashpower/order", Newtonsoft.Json.JsonConvert.SerializeObject(order), time, true); Order orderObject = Newtonsoft.Json.JsonConvert.DeserializeObject <Order>(newOrderResponse); string myOrderId = orderObject.id; Logger.Info("new order id: {}", myOrderId); //update price and limit Dictionary <string, string> updateOrder = new Dictionary <string, string> { { "displayMarketFactor", (string)mySettings["displayMarketFactor"] }, { "limit", "0.11" }, // GH [minSpeedLimit-maxSpeedLimit] || 0 - unlimited speed { "marketFactor", (string)mySettings["marketFactor"] }, { "price", "0.00123" } //per BTC/GH/day }; string updateOrderResponse = api.post("/main/api/v2/hashpower/order/" + myOrderId + "/updatePriceAndLimit", Newtonsoft.Json.JsonConvert.SerializeObject(updateOrder), time, true); Logger.Info("update order response: {}", updateOrderResponse); //delete order string deleteOrderResponse = api.delete("/main/api/v2/hashpower/order/" + myOrderId, time, true); Logger.Info("delete order response: {}", deleteOrderResponse); //delete pool string deletePoolResponse = api.delete("/main/api/v2/pool/" + myPoolId, time, true); Logger.Info("update pool response: {}", deletePoolResponse); }
private static string CURRENCY_BUY = "TLTC"; //use LTC for production public Exch() { var config = new NLog.Config.LoggingConfiguration(); var logconsole = new NLog.Targets.ConsoleTarget("logconsole"); config.AddRule(LogLevel.Info, LogLevel.Fatal, logconsole); NLog.LogManager.Configuration = config; Api api = new Api(); //get server time string timeResponse = api.get("/api/v2/time"); ServerTime serverTimeObject = Newtonsoft.Json.JsonConvert.DeserializeObject <ServerTime>(timeResponse); string time = serverTimeObject.serverTime; Logger.Info("server time: {}", time); //get algo settings string exchResponse = api.get("/exchange/api/v2/info/status"); Symbols symbolsObj = Newtonsoft.Json.JsonConvert.DeserializeObject <Symbols>(exchResponse); String mySettings = null; foreach (Symbol s in symbolsObj.symbols) { if (s.baseAsset.Equals(CURRENCY_BUY)) { mySettings = s.baseAsset; } } Logger.Info("exchange settings: {}", mySettings); //get balance string accountsResponse = api.get("/main/api/v2/accounting/accounts2", true, time); Currencies currenciesObj = Newtonsoft.Json.JsonConvert.DeserializeObject <Currencies>(accountsResponse); double myBalace = 0; foreach (Currency c in currenciesObj.currencies) { if (c.currency.Equals(CURRENCY_SELL)) { myBalace = c.available; } } Logger.Info("balance: {} {}", myBalace, CURRENCY_SELL); //get order book string orderBookResponse = api.get("/exchange/api/v2/orderbook?market=" + CURRENCY_BUY + CURRENCY_SELL + "&limit=100", true, time); OrderBooks orderBooks = Newtonsoft.Json.JsonConvert.DeserializeObject <OrderBooks>(orderBookResponse); Logger.Info("cheapest offer price: {} supply: {}", orderBooks.sell[0][0], orderBooks.sell[0][1]); double qty = 0.1 * 2; string sQty = qty.ToString("0.00000000", System.Globalization.CultureInfo.InvariantCulture); string sPrice = orderBooks.sell[0][0].ToString("0.00000000", System.Globalization.CultureInfo.InvariantCulture); //buy with limit order string url = "/exchange/api/v2/order?market=" + CURRENCY_BUY + CURRENCY_SELL + "&side=buy&type=limit&quantity=" + sQty + "&price=" + sPrice; Logger.Info("order url: {}", url); string orderCreateResponse = api.post(url, null, time, true); Logger.Info("order create: {}", orderCreateResponse); }