0

My goal is basically to fetch my portfolio balance from a Crypto Exchange called Bitstamp. So far, I managed to use their public API (https://www.bitstamp.net/api/ticker/) and this works. The code I used for that is the following:

public class ConsoleApp4
{
    static void Main()
    {
        RunAsync().Wait();
    }
    static async Task RunAsync()
    {
        using (var client = new HttpClient())
        {
            client.BaseAddress = new Uri("https://www.bitstamp.net/");
            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            //HTTP GET
            HttpResponseMessage response = await client.GetAsync("api/ticker/");

            if (response.IsSuccessStatusCode)
            {
                string responseBody = await response.Content.ReadAsStringAsync();
                Console.WriteLine(responseBody);
            }
            else
            {
                Console.WriteLine ($"error: {response.StatusCode}");
            }    
            Console.ReadLine();
        }
    }
}

However, I want to try to access this API : https://www.bitstamp.net/api/v2/balance/ This one requires authentication to be added and I have no idea as to how to go about it. This is the API guide that Bitstamp gives: https://www.bitstamp.net/api/ I'm trying to use the V2 authentication, which requires me to add an API key, a signature and a nonce.

I would already be helped a lot when someone can explain to me how to properly add the authentication headers and I would (hopefully) be able to figure out the rest.

nexigen
  • 13
  • 2
  • Hello, and welcome to stack overflow. The preferred format for questions here is [one question per post](https://meta.stackexchange.com/q/222735), but you're asking multiple questions - one about bitstamp, and the side question about error codes. I'd suggest splitting your question up, but before you do, did you see [Getting Http Status code number (200, 301, 404, etc.) from HttpWebRequest and HttpWebResponse](https://stackoverflow.com/q/1330856) and [How do I get the error message from an HttpResponse object in WebAPI?](https://stackoverflow.com/q/17081564)? – dbc Jun 06 '20 at 03:42
  • Yes. I've read them. They both don't provide what I'm looking for. Within the Bitstamp API they have some unique error message handling for the specific API request. But I'll then remove that question as it's not as important. – nexigen Jun 06 '20 at 04:01
  • Dear Edney. Yes, partially. Thank you very much for that. I am now using that code, but I'm still wondering as to how and where I should call upon these methods. I'm not sure how to actually make/execute the API call while setting the methods in the correct order. I should probably make a new question for that. So far I think that you've definitely answered my question. It helped me a lot further. – nexigen Jun 06 '20 at 05:55
  • I have asked another question, for those who have the same question as I do : https://stackoverflow.com/questions/62228010/how-do-i-given-the-following-methods-send-the-request-to-the-bitstamp-api-usin – nexigen Jun 06 '20 at 06:07
  • I'm voting to reopen as the linked question doesn't specify how to set the authentication headers. I still think it's a duplicate, just not of this question. – Tom W Jun 06 '20 at 12:23
  • https://stackoverflow.com/questions/12022965/adding-http-headers-to-httpclient – Tom W Jun 06 '20 at 12:33

0 Answers0