1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
class BinanceAchat
{
private static string akey = "CLE API";
private static string skey = "SECRET API";
public static string Achat(string Montant)
{
long milliseconds = DateTimeOffset.Now.ToUnixTimeMilliseconds();
var URL = new UriBuilder("https://api.binance.com/api/v3/order");
string URLTest = "https://api.binance.com/api/v3/order";
var queryString = HttpUtility.ParseQueryString(string.Empty);
queryString["symbol"] = "SHIBUSDT";
queryString["side"] = "BUY";
queryString["type"] = "MARKET";
queryString["timeInForce"] = "GTC";
queryString["quoteQty"] = Montant;
queryString["recvWindow"] = "20000";
queryString["timestamp"] = milliseconds.ToString();
string Signature = "";
Signature = CreateSignature(queryString.ToString(), skey);
URL.Query = queryString.ToString() + "&signature=" + Signature;
var client = new WebClient();
client.Headers.Add("X-MBX-APIKEY", akey);
client.Headers.Add("Accepts", "application/json");
client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
string HtmlResult = client.UploadString(URLTest , "?" + queryString.ToString());
return HtmlResult;
}
public static string CreateSignature(string queryString, string secret)
{
byte[] keyBytes = Encoding.UTF8.GetBytes(secret);
byte[] queryStringBytes = Encoding.UTF8.GetBytes(queryString);
HMACSHA256 hmacsha256 = new HMACSHA256(keyBytes);
byte[] bytes = hmacsha256.ComputeHash(queryStringBytes);
return BitConverter.ToString(bytes).Replace("-", "").ToLower();
}
} |
Partager