|
1 | 1 | from typing import Dict, Any, List |
| 2 | +from enum import Enum |
2 | 3 |
|
3 | 4 | from ..internal.async_client import AsyncClient |
4 | 5 |
|
5 | 6 |
|
| 7 | +class KlineType(Enum): |
| 8 | + """K-line type enumeration.""" |
| 9 | + UNKNOWN_KLINE_TYPE = 0 |
| 10 | + MINUTE_1 = 1 |
| 11 | + MINUTE_5 = 2 |
| 12 | + MINUTE_15 = 3 |
| 13 | + MINUTE_30 = 4 |
| 14 | + HOUR_1 = 11 |
| 15 | + HOUR_2 = 12 |
| 16 | + HOUR_4 = 13 |
| 17 | + HOUR_6 = 14 |
| 18 | + HOUR_8 = 15 |
| 19 | + HOUR_12 = 16 |
| 20 | + DAY_1 = 21 |
| 21 | + WEEK_1 = 31 |
| 22 | + MONTH_1 = 41 |
| 23 | + |
| 24 | + |
| 25 | +class PriceType(Enum): |
| 26 | + """Price type enumeration.""" |
| 27 | + UNKNOWN_PRICE_TYPE = 0 |
| 28 | + ORACLE_PRICE = 1 |
| 29 | + INDEX_PRICE = 2 |
| 30 | + LAST_PRICE = 3 |
| 31 | + ASK1_PRICE = 4 |
| 32 | + BID1_PRICE = 5 |
| 33 | + OPEN_INTEREST = 6 |
| 34 | + |
| 35 | + |
| 36 | + |
| 37 | + |
| 38 | + |
| 39 | + |
| 40 | + |
| 41 | + |
6 | 42 | class GetKLineParams: |
7 | 43 | """Parameters for getting K-line data.""" |
8 | 44 |
|
9 | 45 | def __init__( |
10 | 46 | self, |
11 | 47 | contract_id: str, |
12 | | - interval: str, |
13 | | - size: str = "", |
| 48 | + kline_type: KlineType, |
| 49 | + price_type: PriceType = PriceType.LAST_PRICE, |
| 50 | + size: int = 100, |
14 | 51 | offset_data: str = "", |
15 | | - filter_start_time_inclusive: int = 0, |
16 | | - filter_end_time_exclusive: int = 0 |
| 52 | + filter_begin_kline_time_inclusive: str = "", |
| 53 | + filter_end_kline_time_exclusive: str = "" |
17 | 54 | ): |
| 55 | + """ |
| 56 | + Initialize K-line parameters. |
| 57 | +
|
| 58 | + Args: |
| 59 | + contract_id: Contract ID (string) |
| 60 | + kline_type: K-line type (KlineType enum) |
| 61 | + price_type: Price type (PriceType enum, defaults to LAST_PRICE) |
| 62 | + size: Number of records to fetch (int, defaults to 100) |
| 63 | + offset_data: Pagination offset data (string) |
| 64 | + filter_begin_kline_time_inclusive: Start time filter (string timestamp) |
| 65 | + filter_end_kline_time_exclusive: End time filter (string timestamp) |
| 66 | + """ |
18 | 67 | self.contract_id = contract_id |
19 | | - self.interval = interval |
| 68 | + self.kline_type = kline_type |
| 69 | + self.price_type = price_type |
20 | 70 | self.size = size |
21 | 71 | self.offset_data = offset_data |
22 | | - self.filter_start_time_inclusive = filter_start_time_inclusive |
23 | | - self.filter_end_time_exclusive = filter_end_time_exclusive |
| 72 | + self.filter_begin_kline_time_inclusive = filter_begin_kline_time_inclusive |
| 73 | + self.filter_end_kline_time_exclusive = filter_end_kline_time_exclusive |
| 74 | + |
| 75 | + |
24 | 76 |
|
25 | 77 |
|
26 | 78 | class GetOrderBookDepthParams: |
@@ -169,26 +221,22 @@ async def get_k_line(self, params: GetKLineParams) -> Dict[str, Any]: |
169 | 221 | url = f"{self.async_client.base_url}/api/v1/public/quote/getKline" |
170 | 222 | query_params = { |
171 | 223 | "contractId": params.contract_id, |
172 | | - "interval": params.interval |
| 224 | + "klineType": params.kline_type.name, |
| 225 | + "priceType": params.price_type.name, |
| 226 | + "size": str(params.size) |
173 | 227 | } |
174 | 228 |
|
175 | | - # Add pagination parameters |
176 | | - if params.size: |
177 | | - query_params["size"] = params.size |
| 229 | + # Add optional parameters |
178 | 230 | if params.offset_data: |
179 | 231 | query_params["offsetData"] = params.offset_data |
180 | | - |
181 | | - # Add time filters |
182 | | - if params.filter_start_time_inclusive > 0: |
183 | | - query_params["filterStartTimeInclusive"] = str(params.filter_start_time_inclusive) |
184 | | - if params.filter_end_time_exclusive > 0: |
185 | | - query_params["filterEndTimeExclusive"] = str(params.filter_end_time_exclusive) |
| 232 | + if params.filter_begin_kline_time_inclusive: |
| 233 | + query_params["filterBeginKlineTimeInclusive"] = params.filter_begin_kline_time_inclusive |
| 234 | + if params.filter_end_kline_time_exclusive: |
| 235 | + query_params["filterEndKlineTimeExclusive"] = params.filter_end_kline_time_exclusive |
186 | 236 |
|
187 | 237 | # Public endpoint - use simple GET request |
188 | 238 | await self.async_client._ensure_session() |
189 | 239 |
|
190 | | - url = f"{self.async_client.base_url}/api/v1/public/quote/getKline" |
191 | | - |
192 | 240 | try: |
193 | 241 | async with self.async_client.session.get(url, params=query_params) as response: |
194 | 242 | if response.status != 200: |
|
0 commit comments