98 lines
4.0 KiB
C#
98 lines
4.0 KiB
C#
|
|
using Bitget_Server.Api.Dtos;
|
||
|
|
using Bitget_Server.Application.Services;
|
||
|
|
using Bitget_Server.Application.State;
|
||
|
|
using Microsoft.AspNetCore.Mvc;
|
||
|
|
|
||
|
|
namespace Bitget_Server.Api.Controllers;
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 기존 WinForms 의 구름떼/영호 조건식 체크박스 및 신호검색 그리드를 REST 화.
|
||
|
|
/// </summary>
|
||
|
|
[ApiController]
|
||
|
|
[Route("api/signals")]
|
||
|
|
[Produces("application/json")]
|
||
|
|
public class SignalsController : ControllerBase
|
||
|
|
{
|
||
|
|
private readonly SignalProcessService _signalProcess;
|
||
|
|
private readonly MarketState _state;
|
||
|
|
|
||
|
|
public SignalsController(SignalProcessService signalProcess, MarketState state)
|
||
|
|
{
|
||
|
|
_signalProcess = signalProcess;
|
||
|
|
_state = state;
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>현재 활성화된 시그널 목록 + 카운트.</summary>
|
||
|
|
[HttpGet]
|
||
|
|
[ProducesResponseType(typeof(SignalListResponse), StatusCodes.Status200OK)]
|
||
|
|
public ActionResult<SignalListResponse> GetSignals()
|
||
|
|
{
|
||
|
|
var result = new SignalListResponse(
|
||
|
|
_signalProcess.SignalsLongUp.Select(Map),
|
||
|
|
_signalProcess.SignalsShortDown.Select(Map),
|
||
|
|
_signalProcess.SignalsLongDown.Select(Map),
|
||
|
|
_signalProcess.SignalsShortUp.Select(Map),
|
||
|
|
_signalProcess.LongCount,
|
||
|
|
_signalProcess.ShortCount);
|
||
|
|
return Ok(result);
|
||
|
|
|
||
|
|
static SignalSummaryDto Map(Domain.Models.SignalInfoData s)
|
||
|
|
=> new(s.MarketName, s.Description, s.SignalStart, s.Price, s.Rate,
|
||
|
|
s.IndicatorPrice, s.IndicatorRate, s.MCandleTimeType);
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>조건식 상태 조회.</summary>
|
||
|
|
[HttpGet("conditions")]
|
||
|
|
[ProducesResponseType(typeof(SignalConditionsDto), StatusCodes.Status200OK)]
|
||
|
|
public ActionResult<SignalConditionsDto> GetConditions()
|
||
|
|
=> Ok(new SignalConditionsDto(
|
||
|
|
_signalProcess.Checked구름떼상향돌파,
|
||
|
|
_signalProcess.Checked구름떼하향돌파,
|
||
|
|
_signalProcess.영호조건식_상향돌파,
|
||
|
|
_signalProcess.영호조건식_하향돌파));
|
||
|
|
|
||
|
|
/// <summary>조건식 상태 변경.</summary>
|
||
|
|
[HttpPut("conditions")]
|
||
|
|
[ProducesResponseType(typeof(SignalConditionsDto), StatusCodes.Status200OK)]
|
||
|
|
public ActionResult<SignalConditionsDto> UpdateConditions([FromBody] UpdateSignalConditionsRequest req)
|
||
|
|
{
|
||
|
|
_signalProcess.Checked구름떼상향돌파 = req.구름떼상향돌파;
|
||
|
|
_signalProcess.Checked구름떼하향돌파 = req.구름떼하향돌파;
|
||
|
|
_signalProcess.영호조건식_상향돌파 = req.영호조건식_상향돌파;
|
||
|
|
_signalProcess.영호조건식_하향돌파 = req.영호조건식_하향돌파;
|
||
|
|
|
||
|
|
return Ok(new SignalConditionsDto(
|
||
|
|
_signalProcess.Checked구름떼상향돌파,
|
||
|
|
_signalProcess.Checked구름떼하향돌파,
|
||
|
|
_signalProcess.영호조건식_상향돌파,
|
||
|
|
_signalProcess.영호조건식_하향돌파));
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>체크된 마켓/인터벌 목록 조회 (신호검색 대상).</summary>
|
||
|
|
[HttpGet("checked-markets")]
|
||
|
|
[ProducesResponseType(typeof(CheckedMarketsDto), StatusCodes.Status200OK)]
|
||
|
|
public ActionResult<CheckedMarketsDto> GetCheckedMarkets()
|
||
|
|
{
|
||
|
|
lock (_state.SyncRoot)
|
||
|
|
{
|
||
|
|
return Ok(new CheckedMarketsDto(
|
||
|
|
_state.CheckedMarkets.Select(m => m?.ToString() ?? string.Empty).ToList(),
|
||
|
|
_state.IntervalList.Select(i => i?.ToString() ?? string.Empty).ToList()));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>체크된 마켓/인터벌 일괄 설정.</summary>
|
||
|
|
[HttpPut("checked-markets")]
|
||
|
|
[ProducesResponseType(typeof(CheckedMarketsDto), StatusCodes.Status200OK)]
|
||
|
|
public ActionResult<CheckedMarketsDto> UpdateCheckedMarkets([FromBody] UpdateCheckedMarketsRequest req)
|
||
|
|
{
|
||
|
|
lock (_state.SyncRoot)
|
||
|
|
{
|
||
|
|
_state.CheckedMarkets = req.Markets.Cast<object>().ToList();
|
||
|
|
_state.IntervalList = req.Intervals.Cast<object>().ToList();
|
||
|
|
}
|
||
|
|
|
||
|
|
return Ok(new CheckedMarketsDto(req.Markets, req.Intervals));
|
||
|
|
}
|
||
|
|
}
|