public void TestGetReceiveAddress() { var coinbaseClient = new CoinbaseClient(Settings.Default.ApiKey, new ApiKeyAuthenticator()); var response = coinbaseClient.GetReceiveAddress().Result; Assert.IsFalse(String.IsNullOrWhiteSpace(response.Address)); }
public void BeforeEachTest() { client = new CoinbaseClient(new OAuthConfig() { AccessToken = "zzz" }); }
private async Task <TPaginated> GetPageUncheckedAsync(int index) { lock (PageCache) { if (index < PageCache.Count && PageCache[index] != null) { return(PageCache[index]); } } var newParameters = Parameters != null ? new HttpValueCollection(Parameters) : new HttpValueCollection(); newParameters.SetPage(index + 1); newParameters.SetLimit(ResultsPerPage); var page = await CoinbaseClient.GetAsync <TPaginated>(Endpoint, newParameters, Converters).ConfigureAwait(false); if (page.CurrentPage <= page.NumPages) { Contract.Assert(index == (page.CurrentPage - 1)); lock (PageCache) { while (index >= PageCache.Count) { PageCache.Add(null); } PageCache[index] = page; } } return(page); }
public void TestInvalidBuyParameters() { try { CoinbaseClient.GetBitcoinBuyPrice(-1).Wait(); Assert.Fail("Should not be able to pass negative bitcoin quantity"); } catch (Exception exception) { if (exception is ArgumentOutOfRangeException) { return; } var aggregateException = exception as AggregateException; if (aggregateException != null) { if (aggregateException.InnerExceptions != null) { if (aggregateException.InnerExceptions.All(e => e is ArgumentOutOfRangeException)) { return; } } } throw; } }
public void TestGetBalance() { var coinbaseClient = new CoinbaseClient(Settings.Default.ApiKey, new ApiKeyAuthenticator()); var balance = coinbaseClient.GetBalance().Result; Assert.IsFalse(String.IsNullOrWhiteSpace(balance.Currency)); }
public void GetAddressesAssociatedWithAccount() { var client = new CoinbaseClient(Settings.Default.ApiKey, new ApiKeyAuthenticator()); var accountAddresses = client.GetAccountAddresses().Result; Assert.IsNotNull(accountAddresses); Assert.IsTrue(accountAddresses.AccountAddresses.Any()); }
public CoinbaseConnector(IConfiguration configuration) { var apiKey = configuration.GetValue <string>(SettingKeys.CoinbaseApiKey); var apiSecret = configuration.GetValue <string>(SettingKeys.CoinbaseApiSecret); _coinbaseClient = new CoinbaseClient(new ApiKeyConfig { ApiKey = apiKey, ApiSecret = apiSecret }); }
public async Task can_get_auths() { client = new CoinbaseClient(new OAuthConfig { AccessToken = secrets.OAuthCode }); var r = await client.Users.GetAuthInfoAsync(); r.Dump(); }
public void TestSellBitcoin() { var quantity = 0.0m; var coinbaseClient = new CoinbaseClient(Settings.Default.ApiKey, new ApiKeyAuthenticator()); var response = coinbaseClient.SellBitcoin(quantity).Result; Assert.IsTrue(response.Errors.Any()); }
internal AsyncCoinbasePageList(CoinbaseClient client, string endpoint, int?resultsPerPage, HttpValueCollection parameters, JsonConverter[] converters) { CoinbaseClient = client; Endpoint = endpoint; ResultsPerPage = resultsPerPage; Parameters = parameters; Converters = converters; PageCache = new List <TPaginated>(); }
public void TestGetBuyPrice() { var prices = CoinbaseClient.GetBitcoinBuyPrice().Result; // Assert that currencies are returned from service. // We can't go on price values since fees can be waived, negated, etc. Assert.IsTrue(prices.Fees.Any()); Assert.IsFalse(String.IsNullOrWhiteSpace(prices.Subtotal.Currency)); Assert.IsFalse(String.IsNullOrWhiteSpace(prices.TotalAmount.Currency)); }
public void TestPurchaseBitcoin() { // Intentional to ensure that we are getting a properly formatted // response back from the request. var quantity = 0.0m; var coinbaseClient = new CoinbaseClient(Settings.Default.ApiKey, new ApiKeyAuthenticator()); var response = coinbaseClient.PurchaseBitcoin(quantity).Result; Assert.IsTrue(response.Errors.Any()); }
public async Task run_expired_token() { this.client = new CoinbaseClient(new OAuthConfig { AccessToken = secrets.OAuthAccessToken, RefreshToken = secrets.OAuthRefreshToken }) .WithAutomaticOAuthTokenRefresh(secrets.OAuthClientId, secrets.OAuthClientSecret); var authInfo = await this.client.Users.GetAuthInfoAsync(); authInfo.Dump(); }
public GetFromAPI() { //initia the basic this.apiKeyValue = new ApiKeyValues(); //initia the Coinbase API with a API-key and a API-secret key this.client = new CoinbaseClient(new ApiKeyConfig { ApiKey = apiKeyValue.GetApiKey(), ApiSecret = apiKeyValue.GetApiSecret() }); this.source = new CancellationTokenSource(); this.token = source.Token; }
public void TestGenerateReceiveAddress() { // TODO: Re-enable for testing. // Disabled to avoid creating so many keys // because I love testing. //return; var callbackUrl = "http://www.google.com"; var coinbaseClient = new CoinbaseClient(Settings.Default.ApiKey, new ApiKeyAuthenticator()); var response = coinbaseClient.GetNewReceiveAddress(callbackUrl).Result; Assert.AreEqual(callbackUrl, response.CallbackUrl); Assert.IsFalse(String.IsNullOrWhiteSpace(response.Address)); }
public void DisposeClientTwice() { var coinbaseClient = new CoinbaseClient("APIKEY", new ApiKeyAuthenticator()); coinbaseClient.Dispose(); try { coinbaseClient.Dispose(); } catch (ObjectDisposedException) { return; } Assert.Fail("Object disposed of multiple times."); }
static async Task Main(string[] args) { Console.WriteLine("Hello World!"); var client = new CoinbaseClient(); var create = new CreateTransaction { Amount = 1.0m, Currency = "BTC" }; var response = await client .WithHeader(TwoFactorToken, "ffff") .Transactions.SendMoneyAsync("accountId", create); if (!response.HasError()) { // transaction is okay! } }
/// <summary> /// Setup the CoinbaseClient to use automatic token refresh. /// </summary> /// <param name="clientId">The OAuth Application Client ID</param> /// <param name="clientSecret">The OAuth Application Secret</param> /// <param name="onRefresh">Callback function to invoke when the OAuth token is refreshed.</param> public static CoinbaseClient WithAutomaticOAuthTokenRefresh(this CoinbaseClient client, string clientId, string clientSecret, Func <OAuthResponse, Task> onRefresh = null) { if (client.Config is OAuthConfig config) { } else { throw new InvalidOperationException($"Client must be using an {nameof(OAuthConfig)}"); } async Task TokenExpiredErrorHandler(FlurlCall call) { var exception = call.Exception; if (exception is FlurlHttpException ex) { var errorResponse = await ex.GetResponseJsonAsync <JsonResponse>().ConfigureAwait(false); if (errorResponse.Errors.Any(x => x.Id == ExpiredToken)) { var refreshResponse = await OAuthHelper.RenewAccessAsync(config.RefreshToken, clientId, clientSecret).ConfigureAwait(false); config.AccessToken = refreshResponse.AccessToken; config.RefreshToken = refreshResponse.RefreshToken; if (onRefresh is null) { } else { await onRefresh(refreshResponse).ConfigureAwait(false); } call.Response = await call.Request.SendAsync(call.Request.Verb, call.HttpRequestMessage.Content).ConfigureAwait(false); call.ExceptionHandled = true; } } } client.Configure(s => s.OnErrorAsync = TokenExpiredErrorHandler); return(client); }
public void BeforeEachTest() { client = new CoinbaseClient(new OAuthConfig { AccessToken = OauthKey }); }
public UserTests() { client = new CoinbaseClient(new ApiKeyConfig { ApiKey = secrets.ApiKey, ApiSecret = secrets.ApiSecret }); }
public void BeforeEachTest() { client = new CoinbaseClient(new ApiKeyConfig { ApiKey = "", ApiSecret = "" }); }
public void CreateClientWithApiKey() { var coinbaseClient = new CoinbaseClient("APIKEY", new ApiKeyAuthenticator()); }
protected override void DisposeManagedResources() { CoinbaseClient.Dispose(true); }
public void DisposeClientOnce() { var coinbaseClient = new CoinbaseClient("APIKEY", new ApiKeyAuthenticator()); coinbaseClient.Dispose(); }
public void TestGetSpotRate() { var spotRate = CoinbaseClient.GetSpotPrice().Result; Assert.IsFalse(String.IsNullOrWhiteSpace(spotRate.Price.Currency)); }
public CoinbaseService() { _coinbaseClient = new CoinbaseClient(); }
public void BeforeEachTest() { client = new CoinbaseClient(); }