dougdellolio / coinbasepro-csharp

The unofficial .NET/C# client library for the Coinbase Pro/GDAX API
MIT License
192 stars 90 forks source link

Account Service Async? #268

Closed steevehuin closed 3 years ago

steevehuin commented 3 years ago

Hi there,

I'm new to this project and have successfully downloaded/compiled the CoinbasePro project; and have tried to follow a simple example:

` //create an authenticator with your apiKey, apiSecret and passphrase var authenticator = new Authenticator("...", "...", "...");

        //create the CoinbasePro client
        var coinbaseProClient = new CoinbasePro.CoinbaseProClient(authenticator);

        //use one of the services 
        var allAccounts = await coinbaseProClient.AccountsService.GetAllAccountsAsync();

`

For some reasons, Visual Studio 2019 is failing at compile indicating that it's not possible to use await on the GetAllAccountsAsync() call. Any reasons why that's the case?

Error CS4033 The 'await' operator can only be used within an async method. Consider marking this method with the 'async' modifier and changing its return type to 'Task'. CoinbaseAutomate C:\Users\steeve.huin\OneDrive - Irdeto B.V\Documents\Development\coinbasepro-csharp-master\CoinbaseAutomate\Program.cs 41 Active

Thanks Steeve

dougdellolio commented 3 years ago

hi @steevehuin you would have to use the await inside of an async method.

If you didn't want to do that, you could just call .Result where it would block until the task is completed as such:

var allAccounts = coinbaseProClient.AccountsService.GetAllAccountsAsync().Result;

or you could even mark your main method async and do something like this:

public static async Task Main(string[] args)
{
   .....
   var allAccounts = await coinbaseProClient.AccountsService.GetAllAccountsAsync();
}

i'd recommend reading some more on the topic here: https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/async/