1+ from __future__ import annotations
2+
13from asyncio import gather
24from datetime import datetime
3- from typing import Annotated , Literal , Optional
5+ from typing import Annotated , Literal
46
5- from jkit .jpep .platform_settings import PlatformSettings
7+ from jkit .jpep .rules import Rules
68from litestar import Response , Router , get
79from litestar .params import Parameter
810from msgspec import Struct , field
9- from sshared .time import get_datetime_before_now , parse_td_str
11+ from sshared .time import get_past_datetime_from_now , parse_td_str
1012from sspeedup .api .litestar import (
1113 RESPONSE_STRUCT_CONFIG ,
1214 generate_response_spec ,
2123 "1d" : "day" ,
2224}
2325
24- PLATFORM_SETTINGS = PlatformSettings ()
26+ RULES = Rules ()
2527
2628
2729class GetRulesResponse (Struct , ** RESPONSE_STRUCT_CONFIG ):
@@ -40,23 +42,23 @@ class GetRulesResponse(Struct, **RESPONSE_STRUCT_CONFIG):
4042 },
4143)
4244async def get_rules_handler () -> Response :
43- settings = await PLATFORM_SETTINGS . get_data ()
45+ rules = await RULES . get_rules ()
4446
4547 return success (
4648 data = GetRulesResponse (
47- is_open = settings .opening ,
49+ is_open = rules .opening ,
4850 # TODO
49- buy_order_minimum_price = settings . ftn_sell_trade_minimum_price ,
50- sell_order_minimum_price = settings .ftn_buy_trade_minimum_price ,
51- FTN_order_fee = settings .ftn_trade_fee ,
52- goods_order_fee = settings .goods_trade_fee ,
51+ buy_order_minimum_price = rules . ftn_buy_trade_minimum_price ,
52+ sell_order_minimum_price = rules .ftn_buy_trade_minimum_price ,
53+ FTN_order_fee = rules .ftn_trade_fee ,
54+ goods_order_fee = rules .goods_trade_fee ,
5355 )
5456 )
5557
5658
5759class GetCurrentPriceResponse (Struct , ** RESPONSE_STRUCT_CONFIG ):
58- buy_price : Optional [ float ]
59- sell_price : Optional [ float ]
60+ buy_price : float | None
61+ sell_price : float | None
6062
6163
6264@get (
@@ -81,8 +83,8 @@ async def get_current_price_handler() -> Response:
8183
8284
8385class GetCurrentAmountResponse (Struct , ** RESPONSE_STRUCT_CONFIG ):
84- buy_amount : Optional [ int ]
85- sell_amount : Optional [ int ]
86+ buy_amount : int | None
87+ sell_amount : int | None
8688
8789
8890@get (
@@ -121,14 +123,14 @@ async def get_price_history_handler(
121123 type_ : Annotated [
122124 Literal ["buy" , "sell" ], Parameter (description = "交易单类型" , query = "type" )
123125 ],
124- range : Annotated [ # noqa: A002
126+ range : Annotated [
125127 Literal ["24h" , "7d" , "15d" , "30d" ], Parameter (description = "时间范围" )
126128 ],
127129 resolution : Annotated [Literal ["5m" , "1h" , "1d" ], Parameter (description = "统计粒度" )],
128130) -> Response :
129131 history = await FTNMacketRecord .get_price_history (
130132 type = type_ .upper (), # type: ignore
131- start_time = get_datetime_before_now (parse_td_str (range )),
133+ start_time = get_past_datetime_from_now (parse_td_str (range )),
132134 resolution = RESOLUTION_MAPPING [resolution ],
133135 )
134136
@@ -154,14 +156,14 @@ async def get_amount_history_handler(
154156 type_ : Annotated [
155157 Literal ["buy" , "sell" ], Parameter (description = "交易单类型" , query = "type" )
156158 ],
157- range : Annotated [ # noqa: A002
159+ range : Annotated [
158160 Literal ["24h" , "7d" , "15d" , "30d" ], Parameter (description = "时间范围" )
159161 ],
160162 resolution : Annotated [Literal ["5m" , "1h" , "1d" ], Parameter (description = "统计粒度" )],
161163) -> Response :
162164 history = await FTNMacketRecord .get_amount_history (
163165 type = type_ .upper (), # type: ignore
164- start_time = get_datetime_before_now (parse_td_str (range )),
166+ start_time = get_past_datetime_from_now (parse_td_str (range )),
165167 resolution = RESOLUTION_MAPPING [resolution ],
166168 )
167169
0 commit comments