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.5 KiB
47 lines
1.5 KiB
3 years ago
|
using Binance.Net.Clients;
|
||
|
using Binance.Net.Objects;
|
||
|
using CryptoExchange.Net.Authentication;
|
||
|
using Microsoft.Extensions.Caching.Memory;
|
||
|
using System;
|
||
|
using Yitter.IdGenerator;
|
||
3 years ago
|
|
||
|
namespace Binance.TradeRobot.Business
|
||
3 years ago
|
{
|
||
|
public class BaseBusiness
|
||
|
{
|
||
|
protected IFreeSql fsql;
|
||
|
protected NLogManager logManager;
|
||
3 years ago
|
protected IIdGenerator idGenerator;
|
||
3 years ago
|
protected IMemoryCache memoryCache;
|
||
|
private TimeSpan expirationTimeSpan;
|
||
|
|
||
|
|
||
|
public BaseBusiness(IFreeSql fsql, NLogManager logManager, IIdGenerator idGenerator, IMemoryCache memoryCache)
|
||
3 years ago
|
{
|
||
|
this.fsql = fsql;
|
||
|
this.logManager = logManager;
|
||
3 years ago
|
this.idGenerator = idGenerator;
|
||
3 years ago
|
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;
|
||
3 years ago
|
}
|
||
|
}
|
||
|
}
|