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.
57 lines
2.5 KiB
57 lines
2.5 KiB
3 years ago
|
using Binance.TradeRobot.Common.DI;
|
||
|
using Binance.TradeRobot.Common.Extensions;
|
||
|
using Binance.TradeRobot.Model.Base;
|
||
|
using Binance.TradeRobot.Model.Db;
|
||
|
using Binance.TradeRobot.Model.Dto;
|
||
|
using Microsoft.Extensions.DependencyInjection;
|
||
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Text;
|
||
|
using Yitter.IdGenerator;
|
||
|
|
||
|
namespace Binance.TradeRobot.Business.Exchange
|
||
|
{
|
||
|
[BatchRegistration(ServiceLifetime.Singleton, RegistrationType.Self)]
|
||
|
public class ExchangeBusiness : BaseBusiness
|
||
|
{
|
||
|
public ExchangeBusiness(IFreeSql fsql, NLogManager logManager, IIdGenerator idGenerator) : base(fsql, logManager, idGenerator) { }
|
||
|
|
||
|
public void AddExchangeAccount(AddExchangeAccountRequest addExchangeAccountRequest)
|
||
|
{
|
||
|
if (addExchangeAccountRequest.Id == 0 || string.IsNullOrEmpty(addExchangeAccountRequest.LoginName))
|
||
|
throw new BusinessException("交易所账号参数有误");
|
||
|
if (fsql.Select<ExchangeAccount>(addExchangeAccountRequest.Id).Any())
|
||
|
throw new BusinessException("交易所账号重复");
|
||
|
|
||
|
var exchangeAccount = addExchangeAccountRequest.Map<ExchangeAccount>();
|
||
|
if (addExchangeAccountRequest.TradePolicy == Enums.TradePolicy.金字塔)
|
||
|
exchangeAccount.BusinessType = Enums.BusinessType.UPrep;
|
||
|
|
||
|
if (addExchangeAccountRequest.TradePolicy == Enums.TradePolicy.动量趋势v2)
|
||
|
exchangeAccount.BusinessType = Enums.BusinessType.Spot_Margin;
|
||
|
|
||
|
fsql.Insert(exchangeAccount).ExecuteAffrows();
|
||
|
}
|
||
|
|
||
|
public void AddExchangeAPIKey(AddExchangeAPIKeyRequest addExchangeAPIKeyRequest)
|
||
|
{
|
||
|
if (addExchangeAPIKeyRequest.AccountId == 0 ||
|
||
|
string.IsNullOrEmpty(addExchangeAPIKeyRequest.APIKey) ||
|
||
|
string.IsNullOrEmpty(addExchangeAPIKeyRequest.SecretKey))
|
||
|
throw new BusinessException("参数有误");
|
||
|
|
||
|
if (fsql.Select<ExchangeAPIKey>().Where(k => k.APIKey == addExchangeAPIKeyRequest.APIKey || k.SecretKey == addExchangeAPIKeyRequest.SecretKey).Any())
|
||
|
throw new BusinessException("重复的APIKey或SecretKey");
|
||
|
|
||
|
var exchangeAPIKey = addExchangeAPIKeyRequest.Map<ExchangeAPIKey>();
|
||
|
exchangeAPIKey.Id = idGenerator.NewLong();
|
||
|
fsql.Insert(exchangeAPIKey).ExecuteAffrows();
|
||
|
}
|
||
|
|
||
|
public IList<ExchangeAccountResponse> GetExchangeAccountList(Enums.TradePolicy tradePolicy)
|
||
|
{
|
||
|
return null;
|
||
|
}
|
||
|
}
|
||
|
}
|