Skip to content

Instantly share code, notes, and snippets.

@coreylschneider
Created December 24, 2020 17:55
Show Gist options
  • Save coreylschneider/578e343f7acddd399aab87e20a1f8661 to your computer and use it in GitHub Desktop.
Save coreylschneider/578e343f7acddd399aab87e20a1f8661 to your computer and use it in GitHub Desktop.
using CoinbasePro;
using CoinbasePro.Network.Authentication;
using CryptoKlepto.CoinBaseProAPI;
using CryptoKlepto.CoinBaseProAPI.Models;
using CryptoKlepto.CoinBaseProAPI.Results;
using CryptoKlepto.CoinBaseProAPI.Services;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System;
using System.Collections.Generic;
using System.Text;
namespace CryptoKlepto.WPF.HostBuilders
{
public static class AddFinanceAPIHostBuilderExtensions
{
public static IHostBuilder AddFinanceAPI(this IHostBuilder host)
{
host.ConfigureServices((context, services) =>
{
var apiKey = context.Configuration.GetValue<string>("CoinbaseApiKey");
// SANDBOX:
var passphrase = context.Configuration.GetValue<string>("CoinbasePassPhrase");
var secret = context.Configuration.GetValue<string>("CoinbaseSecretKey");
var publickey = context.Configuration.GetValue<string>("CoinbasePublicKey");
var authenticator = new Authenticator(publickey, secret, passphrase);
var coinbaseProClient = new CoinbaseProClient(authenticator, true);
//var res = coinbaseProClient.AccountsService.GetAllAccountsAsync().GetAwaiter().GetResult();
//services.AddScoped<CoinBaseProAPIHttpClient>(c => new CoinBaseProAPIHttpClient(coinbaseProClient, new CoinBaseProApiKey(apiKey)));
//services.AddTransient<CoinBaseProAPIHttpClient>(c => new CoinBaseProAPIHttpClient(coinbaseProClient, new CoinBaseProApiKey(apiKey)));
services.AddSingleton(new CoinBaseProAPIHttpClient(coinbaseProClient, new CoinBaseProApiKey(apiKey)));
//services.AddHttpClient<CoinBaseProAPIHttpClient>(c =>
//{
// c.BaseAddress = new Uri("https://financialmodelingprep.com/api/v3/");
//});
});
return host;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment