You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

47 lines
1.4 KiB

//
// ChartAPI.m
// HC
//
// Created by huilinLi on 2025/12/15.
//
#import "ChartAPI.h"
#import "NetworkManager.h"
#import "StockKLineModel.h" // 引入你的 Model
#import <YYModel/YYModel.h> // 使用 YYModel 进行解析
@implementation ChartAPI
+ (void)fetchKLineDataWithSymbol:(NSString *)symbol type:(NSString *)type success:(KLineDataSuccess)success failure:(APIError)failure {
// 1. 准备参数
NSDictionary *params = @{
@"symbol": symbol,
@"type": type
};
// 2. 调用 Manager 发送请求
[[NetworkManager sharedManager] GET:@"/v1/market/kline" params:params success:^(id response) {
// 3. 数据解析 (假设返回的数据结构是 { "data": [ ...list... ], "code": 0 })
if ([response isKindOfClass:[NSDictionary class]] && [response[@"code"] intValue] == 0) {
NSArray *dataArray = response[@"data"];
// 使用 YYModel 将 JSON 数组 转换为 Model 数组
NSArray *models = [NSArray yy_modelArrayWithClass:[StockKLineModel class] json:dataArray];
if (success) {
success(models);
}
} else {
if (failure) failure(@"服务器数据异常");
}
} failure:^(NSError *error) {
if (failure) {
failure(error.localizedDescription);
}
}];
}
@end