Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Runtime.CompilerServices;
- namespace TradingAPI
- {
- class TradeAPI
- {
- static void Main()
- {
- string input;
- APICalls calls = new APICalls();
- TradeAPI main = new TradeAPI();
- input = calls.GetSpecificBalance("btcusd");
- Console.WriteLine(input);
- Console.ReadLine();
- }
- }
- }
- using System;
- using RestSharp;
- using System.Collections.Generic;
- using System.Text;
- namespace TradingAPI
- {
- class APICalls
- {
- Authentication auth = new Authentication();
- Credentials c = new Credentials();
- #region || BITSTAMP API CALLS ||
- public string GetSpecificBalance(string pair1pair2)
- {
- c.SetResourceURL($"api/v2/balance/{pair1pair2}/");
- RestRequest request = new RestRequest($"api/v2/balance/{pair1pair2}/", Method.POST);
- var response = auth.BitstampAuthentication(request);
- Console.WriteLine(c.BIT_ResourceURL);
- return response;
- }
- #endregion
- }
- }
- using System;
- using RestSharp;
- using System.Collections.Generic;
- using System.Text;
- namespace TradingAPI
- {
- class Authentication
- {
- readonly Encryption e = new Encryption();
- readonly Credentials c = new Credentials();
- #region || BITSTAMP API AUTHENTICATION ||
- public string BitstampAuthentication(RestRequest restRequest)
- {
- var signature = e.GetBitstampSignature(c.Nonce, c.BIT_Key, c.BIT_Secret, c.Timestamp, c.BIT_noSSLBaseURL, c.BIT_ResourceURL);
- restRequest.AddHeader("X-Auth", $"BITSTAMP {c.BIT_Key}");
- restRequest.AddHeader("X-Auth-Signature", signature);
- restRequest.AddHeader("X-Auth-Nonce", c.Nonce.ToString()); ;
- restRequest.AddHeader("X-Auth-Timestamp", c.Timestamp.ToString()); ;
- restRequest.AddHeader("X-Auth-Version", c.BIT_Version);
- RestClient client = new RestClient(c.BIT_BaseURL);
- IRestResponse response = client.Execute(restRequest);
- return response.Content;
- }
- #endregion
- }
- }
- using System;
- using System.Security.Cryptography;
- using System.Text;
- namespace TradingAPI
- {
- class Encryption
- {
- #region || HMAC ENCRYPTION ||
- public byte[] SignHMACSHA256(String key, byte[] data)
- {
- HMACSHA256 hashMaker = new HMACSHA256(Encoding.ASCII.GetBytes(key));
- return hashMaker.ComputeHash(data);
- }
- private byte[] StringToByteArray(string str)
- {
- return System.Text.Encoding.ASCII.GetBytes(str);
- }
- private string ByteArrayToString(byte[] hash)
- {
- return BitConverter.ToString(hash).Replace("-", "").ToLower();
- }
- #endregion
- #region || BITSTAMP SIGNATURE ENCRYPTION ||
- public string GetBitstampSignature(Guid nonce, string key, string secret, long timer, string baseURL, string resURL)
- {
- string msg = $"BITSTAMP {key}POST{baseURL}{resURL}{nonce}{timer}v2";
- Console.WriteLine(msg);
- return ByteArrayToString(SignHMACSHA256(secret, StringToByteArray(msg))).ToUpper();
- }
- #endregion
- }
- }
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Runtime.CompilerServices;
- using System.Text;
- using System.Threading;
- namespace TradingAPI
- {
- class Credentials
- {
- #region || GENERAL CREDENTIALS ||
- public long Timestamp { get; } = (long)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalMilliseconds);
- public Guid Nonce { get; } = Guid.NewGuid();
- #endregion
- #region || BITSTAMP CREDENTIALS ||
- public string BIT_Key { get; } = "x";
- public string BIT_Secret { get; } = "x";
- public string BIT_BaseURL { get; } = "https://www.bitstamp.net/";
- public string BIT_noSSLBaseURL { get; } = "www.bitstamp.net/";
- public string BIT_ResourceURL;
- public string BIT_Version { get; set; } = "v2";
- #endregion
- public void SetResourceURL(string resourceURL)
- {
- BIT_ResourceURL = resourceURL;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement