IUpbitClient.cs 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. namespace Application.Abstractions.Crypto;
  2. public interface IUpbitClient
  3. {
  4. // Candle (캔들)
  5. Task<IReadOnlyList<UpbitCandle>> GetSecondCandlesAsync(string market, int count, CancellationToken ct = default);
  6. Task<IReadOnlyList<UpbitCandle>> GetMinuteCandlesAsync(string market, int unit, int count, CancellationToken ct = default);
  7. Task<IReadOnlyList<UpbitCandle>> GetDayCandlesAsync(string market, int count, CancellationToken ct = default);
  8. Task<IReadOnlyList<UpbitCandle>> GetWeekCandlesAsync(string market, int count, CancellationToken ct = default);
  9. Task<IReadOnlyList<UpbitCandle>> GetMonthCandlesAsync(string market, int count, CancellationToken ct = default);
  10. Task<IReadOnlyList<UpbitCandle>> GetYearCandlesAsync(string market, int count, CancellationToken ct = default);
  11. // Market (마켓 목록)
  12. Task<IReadOnlyList<UpbitMarket>> GetMarketsAsync(CancellationToken ct = default);
  13. // Ticker (현재가 상세)
  14. Task<IReadOnlyList<UpbitTickerDetail>> GetTickersAsync(string[] markets, CancellationToken ct = default);
  15. // Trade (최근 체결 내역)
  16. Task<IReadOnlyList<UpbitTrade>> GetTradesAsync(string market, int count, CancellationToken ct = default);
  17. // Orderbook (호가 정보)
  18. Task<IReadOnlyList<UpbitOrderbook>> GetOrderbookAsync(string[] markets, CancellationToken ct = default);
  19. }
  20. /// <summary>
  21. /// WebSocket 현재가(Ticker) — SIMPLE 포맷
  22. /// https://docs.upbit.com/kr/reference/websocket-ticker
  23. /// </summary>
  24. public sealed record UpbitTicker(
  25. string Market, // 페어(거래쌍)의 코드 (ty: ticker)
  26. decimal OpeningPrice, // 시가
  27. decimal HighPrice, // 고가
  28. decimal LowPrice, // 저가
  29. decimal TradePrice, // 현재가
  30. decimal PrevClosingPrice, // 전일 종가
  31. string Change, // 전일 대비 (EVEN: 보합, RISE: 상승, FALL: 하락)
  32. decimal ChangePrice, // 전일 대비 값
  33. decimal SignedChangePrice, // 전일 대비 값 (부호 포함)
  34. decimal ChangeRate, // 전일 대비 등락율
  35. decimal SignedChangeRate, // 전일 대비 등락율 (부호 포함)
  36. decimal TradeVolume, // 가장 최근 거래량
  37. decimal AccTradeVolume, // 누적 거래량 (UTC 0시 기준)
  38. decimal AccTradeVolume24h, // 24시간 누적 거래량
  39. decimal AccTradePrice, // 누적 거래대금 (UTC 0시 기준)
  40. decimal AccTradePrice24h, // 24시간 누적 거래대금
  41. string TradeDate, // 최근 거래 일자 (UTC, yyyyMMdd)
  42. string TradeTime, // 최근 거래 시각 (UTC, HHmmss)
  43. long TradeTimestamp, // 체결 타임스탬프 (ms)
  44. string AskBid, // 매수/매도 구분 (ASK: 매도, BID: 매수)
  45. decimal AccAskVolume, // 누적 매도량
  46. decimal AccBidVolume, // 누적 매수량
  47. decimal Highest52WeekPrice, // 52주 신고가
  48. string Highest52WeekDate, // 52주 신고가 달성일 (yyyy-MM-dd)
  49. decimal Lowest52WeekPrice, // 52주 신저가
  50. string Lowest52WeekDate, // 52주 신저가 달성일 (yyyy-MM-dd)
  51. string MarketState, // 거래 상태 (PREVIEW, ACTIVE, DELISTED)
  52. string? DelistingDate, // 상장폐지일
  53. string MarketWarning, // 유의 종목 여부 (NONE, CAUTION)
  54. long Timestamp, // 타임스탬프 (ms)
  55. string StreamType // 스트림 타입 (SNAPSHOT, REALTIME)
  56. );
  57. /// <summary>
  58. /// REST/WebSocket 캔들 — 공통 + 타입별 선택 필드
  59. /// https://docs.upbit.com/kr/reference/list-candles-seconds
  60. /// https://docs.upbit.com/kr/reference/list-candles-minutes
  61. /// https://docs.upbit.com/kr/reference/list-candles-days
  62. /// https://docs.upbit.com/kr/reference/list-candles-weeks
  63. /// https://docs.upbit.com/kr/reference/list-candles-months
  64. /// https://docs.upbit.com/kr/reference/list-candles-years
  65. /// </summary>
  66. public sealed record UpbitCandle(
  67. string Market, // 페어(거래쌍)의 코드
  68. string CandleDateTimeUtc, // 캔들 기준 시각 (UTC)
  69. string CandleDateTimeKst, // 캔들 기준 시각 (KST)
  70. decimal OpeningPrice, // 시가
  71. decimal HighPrice, // 고가
  72. decimal LowPrice, // 저가
  73. decimal TradePrice, // 종가 (현재가)
  74. long Timestamp, // 마지막 틱이 저장된 시각 (ms)
  75. decimal CandleAccTradePrice, // 누적 거래 금액
  76. decimal CandleAccTradeVolume, // 누적 거래량
  77. // 분(Minutes) 캔들 전용
  78. int? Unit, // 캔들 집계 시간 단위 (분: 1, 3, 5, 10, 15, 30, 60, 240)
  79. // 일(Days) 캔들 전용
  80. decimal? PrevClosingPrice, // 전일 종가 (UTC 0시 기준)
  81. decimal? ChangePrice, // 전일 종가 대비 가격 변화
  82. decimal? ChangeRate, // 전일 종가 대비 가격 변화율
  83. decimal? ConvertedTradePrice, // 종가 환산 화폐 단위로 환산된 가격 (요청 시)
  84. // 주(Weeks), 월(Months), 연(Years) 캔들 전용
  85. string? FirstDayOfPeriod // 캔들 집계 시작일자 (yyyy-MM-dd)
  86. );
  87. /// <summary>
  88. /// 마켓 목록
  89. /// https://docs.upbit.com/kr/reference/list-trading-pairs
  90. /// </summary>
  91. public sealed record UpbitMarket(
  92. string Market, // 페어(거래쌍)의 코드
  93. string KoreanName, // 가상자산 한글명
  94. string EnglishName, // 가상자산 영문명
  95. UpbitMarketEvent MarketEvent // 종목 유의/경보 정보
  96. );
  97. /// <summary>마켓 이벤트 정보 (유의 종목)</summary>
  98. public sealed record UpbitMarketEvent(
  99. bool Warning, // 유의 종목 여부
  100. UpbitMarketCaution Caution // 주의 종목 상세
  101. );
  102. /// <summary>마켓 주의 종목 상세</summary>
  103. public sealed record UpbitMarketCaution(
  104. bool PriceFluctuations, // 가격 급등락 경보
  105. bool TradingVolumeSoaring, // 거래량 급증 경보
  106. bool DepositAmountSoaring, // 입금량 급증 경보
  107. bool GlobalPriceDifferences, // 국내외 가격 차이 경보
  108. bool ConcentrationOfSmallAccounts // 소수 계정 집중 거래 경보
  109. );
  110. /// <summary>
  111. /// REST 현재가(Ticker) 상세
  112. /// https://docs.upbit.com/kr/reference/list-tickers
  113. /// </summary>
  114. public sealed record UpbitTickerDetail(
  115. string Market, // 페어(거래쌍)의 코드
  116. string TradeDate, // 최근 거래 일자 (UTC, yyyyMMdd)
  117. string TradeTime, // 최근 거래 시각 (UTC, HHmmss)
  118. string TradeDateKst, // 최근 거래 일자 (KST, yyyyMMdd)
  119. string TradeTimeKst, // 최근 거래 시각 (KST, HHmmss)
  120. long TradeTimestamp, // 체결 타임스탬프 (ms)
  121. decimal OpeningPrice, // 시가
  122. decimal HighPrice, // 고가
  123. decimal LowPrice, // 저가
  124. decimal TradePrice, // 현재가
  125. decimal PrevClosingPrice, // 전일 종가
  126. string Change, // 전일 대비 (EVEN, RISE, FALL)
  127. decimal ChangePrice, // 전일 대비 값
  128. decimal ChangeRate, // 전일 대비 등락율
  129. decimal SignedChangePrice, // 전일 대비 값 (부호 포함)
  130. decimal SignedChangeRate, // 전일 대비 등락율 (부호 포함)
  131. decimal TradeVolume, // 가장 최근 거래량
  132. decimal AccTradePrice, // 누적 거래대금 (UTC 0시 기준)
  133. decimal AccTradePrice24h, // 24시간 누적 거래대금
  134. decimal AccTradeVolume, // 누적 거래량 (UTC 0시 기준)
  135. decimal AccTradeVolume24h, // 24시간 누적 거래량
  136. decimal Highest52WeekPrice, // 52주 신고가
  137. string Highest52WeekDate, // 52주 신고가 달성일 (yyyy-MM-dd)
  138. decimal Lowest52WeekPrice, // 52주 신저가
  139. string Lowest52WeekDate, // 52주 신저가 달성일 (yyyy-MM-dd)
  140. long Timestamp // 타임스탬프 (ms)
  141. );
  142. /// <summary>
  143. /// REST 최근 체결 내역
  144. /// https://docs.upbit.com/kr/reference/recent-trades-history
  145. /// </summary>
  146. public sealed record UpbitTrade(
  147. string Market, // 페어(거래쌍)의 코드
  148. string TradeDateUtc, // 체결 일자 (UTC)
  149. string TradeTimeUtc, // 체결 시각 (UTC)
  150. long Timestamp, // 타임스탬프 (ms)
  151. decimal TradePrice, // 체결 가격
  152. decimal TradeVolume, // 체결량
  153. decimal PrevClosingPrice, // 전일 종가
  154. decimal ChangePrice, // 전일 대비 값
  155. string AskBid, // 매수/매도 구분 (ASK: 매도, BID: 매수)
  156. long SequentialId // 체결 번호 (Unique)
  157. );
  158. /// <summary>
  159. /// REST 호가 정보
  160. /// https://docs.upbit.com/kr/reference/list-orderbooks
  161. /// </summary>
  162. public sealed record UpbitOrderbook(
  163. string Market, // 페어(거래쌍)의 코드
  164. decimal TotalAskSize, // 호가 매도 총 잔량
  165. decimal TotalBidSize, // 호가 매수 총 잔량
  166. IReadOnlyList<UpbitOrderbookUnit> OrderbookUnits, // 호가 리스트
  167. long Timestamp, // 타임스탬프 (ms)
  168. decimal Level // 호가 모아보기 단위
  169. );
  170. /// <summary>호가 단위</summary>
  171. public sealed record UpbitOrderbookUnit(
  172. decimal AskPrice, // 매도호가
  173. decimal BidPrice, // 매수호가
  174. decimal AskSize, // 매도 잔량
  175. decimal BidSize // 매수 잔량
  176. );