Skip to content

Instantly share code, notes, and snippets.

@fabarea
Created January 24, 2020 14:59
Show Gist options
  • Save fabarea/2f100869c34d8fe5ea1ded259f2ad5fd to your computer and use it in GitHub Desktop.
Save fabarea/2f100869c34d8fe5ea1ded259f2ad5fd to your computer and use it in GitHub Desktop.
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
namespace workspace
{
public class MM2Client
{
private static readonly HttpClient Client = new HttpClient();
private static async Task<string> ProcessRequest(string req)
{
var response = await Client.PostAsync("http://127.0.0.1:7783",
new StringContent(req, Encoding.UTF8, "application/json"));
return await response.Content.ReadAsStringAsync();
// return s;
}
public static async Task<string> ProcessElectrum(string ticker, Server[] servers)
{
var req = new ElectrumRequest
{
Coin = ticker,
Servers = servers,
Method = "electrum",
Userpass = "root"
};
return await ProcessRequest(req.ToJson());
}
public static async Task<string> ProcessBalance(string ticker)
{
var req = new ElectrumRequest
{
Coin = ticker,
Method = "my_balance",
Userpass = "root"
};
return await ProcessRequest(req.ToJson());
}
public static async Task<string> ProcessOrderBook(string baseCoin, string rel)
{
var req = new OrderBookRequest
{
Base = baseCoin,
Rel = rel,
Method = "orderbook",
Userpass = "root"
};
return await ProcessRequest(req.ToJson());
}
}
}
// <auto-generated />
//
// To parse this JSON data, add NuGet 'Newtonsoft.Json' then do:
//
// using workspace;
//
// var orderBookRequest = OrderBookRequest.FromJson(jsonString);
namespace workspace
{
using System;
using System.Collections.Generic;
using System.Globalization;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
public partial class OrderBookRequest
{
[JsonProperty("userpass")]
public string Userpass { get; set; }
[JsonProperty("method")]
public string Method { get; set; }
[JsonProperty("base")]
public string Base { get; set; }
[JsonProperty("rel")]
public string Rel { get; set; }
}
public partial class OrderBookRequest
{
public static OrderBookRequest FromJson(string json) => JsonConvert.DeserializeObject<OrderBookRequest>(json, Converter.Settings);
}
public static partial class Serialize
{
public static string ToJson(this OrderBookRequest self) => JsonConvert.SerializeObject(self, Converter.Settings);
}
}
using System;
using System.Threading.Tasks;
namespace workspace
{
class Program
{
static async Task Main(string[] args)
{
var responseBody = await MM2Client.ProcessElectrum("RICK", new Server[]
{
new Server {Url = "electrum1.cipig.net:10017"},
new Server {Url = "electrum2.cipig.net:10017"},
new Server {Url = "electrum3.cipig.net:10017"}
});
Console.WriteLine(responseBody);
responseBody = await MM2Client.ProcessElectrum("MORTY", new Server[]
{
new Server {Url = "electrum1.cipig.net:10018"},
new Server {Url = "electrum2.cipig.net:10018"},
new Server {Url = "electrum3.cipig.net:10018"}
});
Console.WriteLine(responseBody);
responseBody = await MM2Client.ProcessBalance("RICK");
Console.WriteLine(responseBody);
responseBody = await MM2Client.ProcessOrderBook("RICK", "MORTY");
Console.WriteLine(responseBody);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment