You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.6 KiB
47 lines
1.6 KiB
using Binance.Net.Clients;
|
|
using Binance.Net.Objects;
|
|
using CryptoExchange.Net.Authentication;
|
|
using Microsoft.Extensions.Caching.Memory;
|
|
using System;
|
|
using Yitter.IdGenerator;
|
|
|
|
namespace Binance.TradeRobot.Business
|
|
{
|
|
public class BaseBusiness
|
|
{
|
|
protected IFreeSql fsql;
|
|
protected NLogManager logManager;
|
|
protected IIdGenerator idGenerator;
|
|
protected IMemoryCache memoryCache;
|
|
private TimeSpan expirationTimeSpan;
|
|
|
|
|
|
public BaseBusiness(IFreeSql fsql, NLogManager logManager, IIdGenerator idGenerator, IMemoryCache memoryCache)
|
|
{
|
|
this.fsql = fsql;
|
|
this.logManager = logManager;
|
|
this.idGenerator = idGenerator;
|
|
this.memoryCache = memoryCache;
|
|
expirationTimeSpan = TimeSpan.FromDays(1);
|
|
}
|
|
|
|
protected BinanceClient GetBinanceClient(string apiKey, string secret)
|
|
{
|
|
if (!memoryCache.TryGetValue(apiKey, out BinanceClient binanceClient))
|
|
{
|
|
var apiClientOption = new BinanceApiClientOptions()
|
|
{
|
|
BaseAddress = "https://fapi.binance.com",
|
|
ApiCredentials = new ApiCredentials(apiKey, secret)
|
|
};
|
|
binanceClient = new BinanceClient(new BinanceClientOptions()
|
|
{
|
|
UsdFuturesApiOptions = apiClientOption,
|
|
SpotApiOptions = apiClientOption
|
|
});
|
|
memoryCache.Set(apiKey, binanceClient, expirationTimeSpan);
|
|
}
|
|
return binanceClient;
|
|
}
|
|
}
|
|
}
|
|
|