Skip to content

Commit

Permalink
Added dynamic SetApiCredentials to exchange clients
Browse files Browse the repository at this point in the history
  • Loading branch information
JKorf committed Nov 23, 2024
1 parent 6392cae commit 28553dd
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 0 deletions.
24 changes: 24 additions & 0 deletions CryptoClients.Net/CryptoClients.Net.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions CryptoClients.Net/ExchangeRestClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
using Bitfinex.Net.Objects.Options;
using Bitget.Net.Clients;
using Bitget.Net.Interfaces.Clients;
using Bitget.Net.Objects;
using Bitget.Net.Objects.Options;
using BitMart.Net.Clients;
using BitMart.Net.Interfaces.Clients;
using BitMart.Net.Objects;
using BitMart.Net.Objects.Options;
using Bybit.Net.Clients;
using Bybit.Net.Interfaces.Clients;
Expand All @@ -22,6 +24,7 @@
using CoinEx.Net.Clients;
using CoinEx.Net.Interfaces.Clients;
using CoinEx.Net.Objects.Options;
using CryptoClients.Net.Enums;
using CryptoClients.Net.Interfaces;
using CryptoClients.Net.Models;
using CryptoCom.Net.Clients;
Expand All @@ -43,12 +46,14 @@
using Kraken.Net.Objects.Options;
using Kucoin.Net.Clients;
using Kucoin.Net.Interfaces.Clients;
using Kucoin.Net.Objects;
using Kucoin.Net.Objects.Options;
using Mexc.Net.Clients;
using Mexc.Net.Interfaces.Clients;
using Mexc.Net.Objects.Options;
using OKX.Net.Clients;
using OKX.Net.Interfaces.Clients;
using OKX.Net.Objects;
using OKX.Net.Objects.Options;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -476,6 +481,31 @@ public IEnumerable<ISharedClient> GetExchangeSharedClients(string name, TradingM
return result.ToList();
}

/// <inheritdoc />
public void SetApiCredentials(string exchange, string apiKey, string apiSecret, string? apiPass = null)
{
switch (exchange)
{
case "Binance": Binance.SetApiCredentials(new ApiCredentials(apiKey, apiSecret)); break;
case "BingX": BingX.SetApiCredentials(new ApiCredentials(apiKey, apiSecret)); break;
case "Bitfinex": Bitfinex.SetApiCredentials(new ApiCredentials(apiKey, apiSecret)); break;
case "Bitget": Bitget.SetApiCredentials(new BitgetApiCredentials(apiKey, apiSecret, apiPass ?? throw new ArgumentException("ApiPass required for Bitget credentials", nameof(apiPass)))); break;
case "BitMart": BitMart.SetApiCredentials(new BitMartApiCredentials(apiKey, apiSecret, apiPass ?? throw new ArgumentException("ApiPass required for BitMart credentials", nameof(apiPass)))); break;
case "Bybit": Bybit.SetApiCredentials(new ApiCredentials(apiKey, apiSecret)); break;
case "Coinbase": Coinbase.SetApiCredentials(new ApiCredentials(apiKey, apiSecret)); break;
case "CoinEx": CoinEx.SetApiCredentials(new ApiCredentials(apiKey, apiSecret)); break;
case "CryptoCom": CryptoCom.SetApiCredentials(new ApiCredentials(apiKey, apiSecret)); break;
case "GateIo": GateIo.SetApiCredentials(new ApiCredentials(apiKey, apiSecret)); break;
case "HTX": HTX.SetApiCredentials(new ApiCredentials(apiKey, apiSecret)); break;
case "Kraken": Kraken.SetApiCredentials(new ApiCredentials(apiKey, apiSecret)); break;
case "Kucoin": Kraken.SetApiCredentials(new KucoinApiCredentials(apiKey, apiSecret, apiPass ?? throw new ArgumentException("ApiPass required for Kucoin credentials", nameof(apiPass)))); break;
case "Mexc": Kraken.SetApiCredentials(new ApiCredentials(apiKey, apiSecret)); break;
case "OKX": Kraken.SetApiCredentials(new OKXApiCredentials(apiKey, apiSecret, apiPass ?? throw new ArgumentException("ApiPass required for OKX credentials", nameof(apiPass)))); break;
case "WhiteBit": Kraken.SetApiCredentials(new ApiCredentials(apiKey, apiSecret)); break;
default: throw new ArgumentException("Exchange not recognized", nameof(exchange));
}
}

#region Get Spot Tickers

/// <inheritdoc />
Expand Down
29 changes: 29 additions & 0 deletions CryptoClients.Net/ExchangeSocketClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
using Bitfinex.Net.Objects.Options;
using Bitget.Net.Clients;
using Bitget.Net.Interfaces.Clients;
using Bitget.Net.Objects;
using Bitget.Net.Objects.Options;
using BitMart.Net.Clients;
using BitMart.Net.Interfaces.Clients;
using BitMart.Net.Objects;
using BitMart.Net.Objects.Options;
using Bybit.Net.Clients;
using Bybit.Net.Interfaces.Clients;
Expand Down Expand Up @@ -43,12 +45,14 @@
using Kraken.Net.Objects.Options;
using Kucoin.Net.Clients;
using Kucoin.Net.Interfaces.Clients;
using Kucoin.Net.Objects;
using Kucoin.Net.Objects.Options;
using Mexc.Net.Clients;
using Mexc.Net.Interfaces.Clients;
using Mexc.Net.Objects.Options;
using OKX.Net.Clients;
using OKX.Net.Interfaces.Clients;
using OKX.Net.Objects;
using OKX.Net.Objects.Options;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -369,6 +373,31 @@ public IEnumerable<ISharedClient> GetExchangeSharedClients(string name, TradingM
return result.ToList();
}

/// <inheritdoc />
public void SetApiCredentials(string exchange, string apiKey, string apiSecret, string? apiPass = null)
{
switch (exchange)
{
case "Binance": Binance.SetApiCredentials(new ApiCredentials(apiKey, apiSecret)); break;
case "BingX": BingX.SetApiCredentials(new ApiCredentials(apiKey, apiSecret)); break;
case "Bitfinex": Bitfinex.SetApiCredentials(new ApiCredentials(apiKey, apiSecret)); break;
case "Bitget": Bitget.SetApiCredentials(new BitgetApiCredentials(apiKey, apiSecret, apiPass ?? throw new ArgumentException("ApiPass required for Bitget credentials", nameof(apiPass)))); break;
case "BitMart": BitMart.SetApiCredentials(new BitMartApiCredentials(apiKey, apiSecret, apiPass ?? throw new ArgumentException("ApiPass required for BitMart credentials", nameof(apiPass)))); break;
case "Bybit": Bybit.SetApiCredentials(new ApiCredentials(apiKey, apiSecret)); break;
case "Coinbase": Coinbase.SetApiCredentials(new ApiCredentials(apiKey, apiSecret)); break;
case "CoinEx": CoinEx.SetApiCredentials(new ApiCredentials(apiKey, apiSecret)); break;
case "CryptoCom": CryptoCom.SetApiCredentials(new ApiCredentials(apiKey, apiSecret)); break;
case "GateIo": GateIo.SetApiCredentials(new ApiCredentials(apiKey, apiSecret)); break;
case "HTX": HTX.SetApiCredentials(new ApiCredentials(apiKey, apiSecret)); break;
case "Kraken": Kraken.SetApiCredentials(new ApiCredentials(apiKey, apiSecret)); break;
case "Kucoin": Kraken.SetApiCredentials(new KucoinApiCredentials(apiKey, apiSecret, apiPass ?? throw new ArgumentException("ApiPass required for Kucoin credentials", nameof(apiPass)))); break;
case "Mexc": Kraken.SetApiCredentials(new ApiCredentials(apiKey, apiSecret)); break;
case "OKX": Kraken.SetApiCredentials(new OKXApiCredentials(apiKey, apiSecret, apiPass ?? throw new ArgumentException("ApiPass required for OKX credentials", nameof(apiPass)))); break;
case "WhiteBit": Kraken.SetApiCredentials(new ApiCredentials(apiKey, apiSecret)); break;
default: throw new ArgumentException("Exchange not recognized", nameof(exchange));
}
}

#region Subscribe All Ticker

/// <inheritdoc />
Expand Down
9 changes: 9 additions & 0 deletions CryptoClients.Net/Interfaces/IExchangeRestClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,15 @@ public interface IExchangeRestClient
/// <param name="tradingMode">Filter clients by trading mode</param>
IEnumerable<ISharedClient> GetExchangeSharedClients(string exchange, TradingMode? tradingMode = null);

/// <summary>
/// Set API credentials for an exchange
/// </summary>
/// <param name="exchange">Exchange name</param>
/// <param name="apiKey">API key</param>
/// <param name="apiSecret">API secret</param>
/// <param name="apiPass">API passphrase</param>
void SetApiCredentials(string exchange, string apiKey, string apiSecret, string? apiPass = null);

/// <summary>
/// Get the <see cref="IAssetsRestClient"/> clients for all exchanges
/// </summary>
Expand Down
9 changes: 9 additions & 0 deletions CryptoClients.Net/Interfaces/IExchangeSocketClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,15 @@ public interface IExchangeSocketClient
/// </summary>
IWhiteBitSocketClient WhiteBit { get; }

/// <summary>
/// Set API credentials for an exchange
/// </summary>
/// <param name="exchange">Exchange name</param>
/// <param name="apiKey">API key</param>
/// <param name="apiSecret">API secret</param>
/// <param name="apiPass">API passphrase</param>
void SetApiCredentials(string exchange, string apiKey, string apiSecret, string? apiPass = null);

/// <summary>
/// Get all ISharedClient Socket Api interfaces supported for the specified exchange
/// </summary>
Expand Down

0 comments on commit 28553dd

Please sign in to comment.