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

  1. //
  2. // ChartAPI.m
  3. // HC
  4. //
  5. // Created by huilinLi on 2025/12/15.
  6. //
  7. #import "ChartAPI.h"
  8. #import "NetworkManager.h"
  9. #import "StockKLineModel.h" // 引入你的 Model
  10. #import <YYModel/YYModel.h> // 使用 YYModel 进行解析
  11. @implementation ChartAPI
  12. + (void)fetchKLineDataWithSymbol:(NSString *)symbol type:(NSString *)type success:(KLineDataSuccess)success failure:(APIError)failure {
  13. // 1. 准备参数
  14. NSDictionary *params = @{
  15. @"symbol": symbol,
  16. @"type": type
  17. };
  18. // 2. 调用 Manager 发送请求
  19. [[NetworkManager sharedManager] GET:@"/v1/market/kline" params:params success:^(id response) {
  20. // 3. 数据解析 (假设返回的数据结构是 { "data": [ ...list... ], "code": 0 })
  21. if ([response isKindOfClass:[NSDictionary class]] && [response[@"code"] intValue] == 0) {
  22. NSArray *dataArray = response[@"data"];
  23. // 使用 YYModelJSON 数组 转换为 Model 数组
  24. NSArray *models = [NSArray yy_modelArrayWithClass:[StockKLineModel class] json:dataArray];
  25. if (success) {
  26. success(models);
  27. }
  28. } else {
  29. if (failure) failure(@"服务器数据异常");
  30. }
  31. } failure:^(NSError *error) {
  32. if (failure) {
  33. failure(error.localizedDescription);
  34. }
  35. }];
  36. }
  37. @end