搜索插件、代码仓与 APP 分类

插件详情v1.0.14

yahoo_finance_data_reader

用于获取每日股票价格的雅虎财经数据读取器。可用于开发回测,并可获取雅虎财经上的所有历史日度数据。

AndroidiOSmacOSWindowsLinux
近 30 天下载
962
喜欢数
31
Pub 分数
160

安装插件

flutter pub add yahoo_finance_data_reader

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一个 Flutter/Dart 包,可从 Yahoo Finance 获取每日股票价格,使开发者能够访问历史市场数据,用于构建回测工具和金融分析应用。该包支持 Android、iOS、macOS、Windows 和 Linux 等多个平台,适用于跨平台开发。该包简化了与 Yahoo Finance 公开 API 的集成,可无缝获取股票及其他金融工具的全面历史价格数据。

适合场景

  • 回测交易策略
  • 构建财务仪表板
  • 分析历史股票趋势
  • 开发投资研究工具
  • 创建投资组合跟踪应用

主要特点

  • 获取每日历史股票价格
  • 支持跨平台部署
  • 用于数据检索的简单 API
  • 与雅虎财经集成
  • 启用实时和历史数据访问

适合对象

  • 金融应用开发者
  • 量化分析师
  • 交易策略构建工具
  • 数据驱动的投资工具
  • 需要市场数据的Flutter项目

使用建议

  • 依赖外部雅虎财经API的稳定性
  • 仅限每日粒度
  • 需要互联网连接
  • 可能有速率限制
  • 数据准确性取决于雅虎财经来源

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

This project started as a migration of the pandas datareader functionality to read yahoo finance stock prices. In December of 2022 yahoo started to encrypt the data in the HTML, so I needed to investigate a way of evolving the package. And then found a yfinance package that used query2 of yahoo finance API, and started to use it

https://github.com/pydata/pandas-datareader/blob/main/pandas_datareader/yahoo/daily.py

This lib have a strong advantage on backtesting strategies as it can give all the dataframe in yahoo finance, this means that can get daily data on futures like NQ=F and ES=F since 2000 and it goes as far as getting data from 1927 on the SP500 yahoo finance symbol ^GSPC

Yahoo Finance data

Features

Get daily data from yahoo finance for the entire dataframe available

Getting started

Add the dependency to your pubspec.yaml:

yahoo_finance_data_reader: ^1.0.14

Usage

YahooFinanceResponse response = await YahooFinanceDailyReader().getDailyDTOs('GOOG');

You can also provide your own Dio instance when you need custom behavior like request caching or shared interceptors:

final dio = Dio()
  ..interceptors.add(DioCacheInterceptor(options: cacheOptions));

final reader = YahooFinanceDailyReader(dio: dio);
final response = await reader.getDailyDTOs('GOOG');

Additional information

To include in your app as a widget you can start with this future builder and debug your way until your desired result

class DTOSearch extends StatefulWidget {
  const DTOSearch({super.key});

  @override
  State<DTOSearch> createState() => _DTOSearchState();
}

class _DTOSearchState extends State<DTOSearch> {
  final TextEditingController controller = TextEditingController(
    text: 'GOOG',
  );
  late Future<YahooFinanceResponse> future;

  @override
  void initState() {
    super.initState();
    load();
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        const Text('Ticker from yahoo finance'),
        TextField(
          controller: controller,
        ),
        MaterialButton(
          onPressed: load,
          child: Text('Load'),
          color: Theme.of(context).primaryColor,
        ),
        Expanded(
          child: FutureBuilder(
            future: future,
            builder: (BuildContext context,
                AsyncSnapshot<YahooFinanceResponse> snapshot) {
              if (snapshot.connectionState == ConnectionState.done) {
                if (snapshot.data == null) {
                  return Text('No data');
                }

                YahooFinanceResponse response = snapshot.data!;
                return ListView.builder(
                    itemCount: response.candlesData.length,
                    itemBuilder: (BuildContext context, int index) {
                      YahooFinanceCandleData candle =
                      response.candlesData[index];

                      return _CandleCard(candle);
                    });
              } else {
                return const Center(
                  child: SizedBox(
                    height: 50,
                    width: 50,
                    child: CircularProgressIndicator(),
                  ),
                );
              }
            },
          ),
        ),
      ],
    );
  }

  void load() {
    future = YahooFinanceDailyReader().getDailyDTOs(controller.text);
    setState(() {});
  }
}

class _CandleCard extends StatelessWidget {
  final YahooFinanceCandleData candle;
  const _CandleCard(this.candle);

  @override
  Widget build(BuildContext context) {
    final String date = candle.date.toIso8601String().split('T').first;

    return Card(
      child: Container(
        margin: const EdgeInsets.all(10),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
              children: [
                Text(date),
              ],
            ),
            const SizedBox(
              height: 10,
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
              children: [
                Text('open: ${candle.open.toStringAsFixed(2)}'),
                Text('close: ${candle.close.toStringAsFixed(2)}'),
              ],
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
              children: [
                Text('low: ${candle.low.toStringAsFixed(2)}'),
                Text('high: ${candle.high.toStringAsFixed(2)}'),
              ],
            ),
          ],
        ),
      ),
    );
  }
}

Like us on pub.dev

Package url: https://pub.dev/packages/yahoo_finance_data_reader

Instruction to publish the package to pub.dev

dart pub publish

所属分类

依赖

依赖清单 5 项

源码仓库

使用此插件的项目