搜尋套件、儲存庫與 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 項

原始碼儲存庫

使用此套件的專案