단순 이관
This commit is contained in:
100
Bitget_Server/Application/Services/SettingsService.cs
Normal file
100
Bitget_Server/Application/Services/SettingsService.cs
Normal file
@@ -0,0 +1,100 @@
|
||||
using Bitget_Server.Application.Options;
|
||||
using Bitget_Server.Application.State;
|
||||
using Bitget_Server.Domain.Enums;
|
||||
using Bitget_Server.Domain.Models;
|
||||
using Bitget_Server.Infrastructure.Bitget;
|
||||
using Bitget_Server.Infrastructure.Utils;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace Bitget_Server.Application.Services;
|
||||
|
||||
/// <summary>
|
||||
/// 기존 WinForms MainForm 의 ComboBox/Setting/Selected 상태를 REST 에서 다루기 위한 서비스.
|
||||
/// </summary>
|
||||
public class SettingsService
|
||||
{
|
||||
private readonly GlobalOptions _global;
|
||||
private readonly MarketState _state;
|
||||
private readonly BitgetClient _client;
|
||||
private readonly BitgetOptions _bitgetOptions;
|
||||
private readonly ILogger<SettingsService> _logger;
|
||||
|
||||
public SettingsService(
|
||||
GlobalOptions global,
|
||||
MarketState state,
|
||||
BitgetClient client,
|
||||
IOptions<BitgetOptions> bitgetOptions,
|
||||
ILogger<SettingsService> logger)
|
||||
{
|
||||
_global = global;
|
||||
_state = state;
|
||||
_client = client;
|
||||
_bitgetOptions = bitgetOptions.Value;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
// ===== 캔들 간격 설정 =====
|
||||
public int GetCandleIntervalMinutes() => _global.CandleIntervalMinutes;
|
||||
|
||||
public void SetCandleIntervalMinutes(int minutes)
|
||||
{
|
||||
if (!Enum.IsDefined(typeof(MCandleTimeType), minutes))
|
||||
throw new ArgumentException($"유효하지 않은 캔들 간격: {minutes}");
|
||||
|
||||
_global.CandleIntervalMinutes = minutes;
|
||||
_global.Save();
|
||||
}
|
||||
|
||||
public IEnumerable<object> ListCandleIntervals() =>
|
||||
Enum.GetValues(typeof(MCandleTimeType))
|
||||
.Cast<MCandleTimeType>()
|
||||
.Select(t => new
|
||||
{
|
||||
Name = t.ToString(),
|
||||
Description = Convertor.GetEnumDescription(t),
|
||||
Minutes = (int)t
|
||||
});
|
||||
|
||||
// ===== 선택 코인 =====
|
||||
public string GetSelectedCoin() => _global.SelectedCoin;
|
||||
|
||||
public void SetSelectedCoin(string marketName)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(marketName))
|
||||
throw new ArgumentException("코인 심볼이 비어있습니다.");
|
||||
|
||||
_global.SelectedCoin = marketName;
|
||||
_global.Save();
|
||||
}
|
||||
|
||||
// ===== 코인 목록 조회 =====
|
||||
public async Task<IEnumerable<MarketInfo>> GetCoinsAsync(CancellationToken ct = default)
|
||||
{
|
||||
// BitgetClient.Parse 가 _state.marketInfoList 에 기록한 값을 반환
|
||||
var result = await _client.SendWebServerAsync(
|
||||
ExchangeWebReqType.BitgetMarket_Future,
|
||||
ct: ct).ConfigureAwait(false);
|
||||
|
||||
if (result is List<MarketInfo> list) return list;
|
||||
|
||||
lock (_state.SyncRoot) return _state.marketInfoList.ToList();
|
||||
}
|
||||
|
||||
// ===== 레버리지 / 주문수량 / Selected API =====
|
||||
public double GetLeverage() => _global.Leverage;
|
||||
public double GetOrderAmount() => _global.OrderAmount;
|
||||
|
||||
public void SetLeverage(double v) { _global.Leverage = v; _global.Save(); }
|
||||
public void SetOrderAmount(double v) { _global.OrderAmount = v; _global.Save(); }
|
||||
|
||||
public int? GetSelectedApiId() => _global.SelectAPI?.Id;
|
||||
|
||||
public void SetSelectedApiId(int id)
|
||||
{
|
||||
var api = _bitgetOptions.ApiKeys.FirstOrDefault(k => k.Id == id)
|
||||
?? throw new KeyNotFoundException($"Bitget:ApiKeys 에 Id={id} 없음");
|
||||
|
||||
_global.SelectAPI = api;
|
||||
_global.Save();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user