Coder Social home page Coder Social logo

twjackysu / stocklib Goto Github PK

View Code? Open in Web Editor NEW
1.0 0.0 0.0 39 KB

自製的台股類別庫,可以獲得目前上市與上櫃的代碼列表,可以獲得即時股價與歷史資訊,所有source都是來自網路,因此無法離線搜尋,必須連網,code內有使用範例

License: MIT License

C# 100.00%

stocklib's Introduction

StockLib

自製的台股類別庫,所有source都是來自網路,因此無法離線搜尋,必須連網,code內有使用範例,這是 .net core的程式,因為我有要跑在linux上的需要,若沒有 .net core sdk的請自行安裝


用法可參考我另外一個Repo: StockJob

使用DI

new ServiceCollection()
.AddTransient<IHistoryBuilder, HistoryBuilder>()
.AddTransient<IStockInfoBuilder, StockInfoBuilder>()
.AddTransient<IStockListBuilder, StockListBuilderFromWeb>()

在任何你的Class內使用

class YourClass
{
    private readonly IHistoryBuilder historyBuilder;
    private readonly StockListBuilderFromWeb stockListBuilder;
    private readonly IStockInfoBuilder stockInfoBuilder;
    public YourClass(IHistoryBuilder historyBuilder, StockListBuilderFromWeb stockListBuilder, IStockInfoBuilder stockInfoBuilder)
    {
        this.historyBuilder = historyBuilder;
        this.stockListBuilder = stockListBuilder;
        this.stockInfoBuilder = stockInfoBuilder;
    }
}

獲得目前上市與上櫃的代碼列表

//目前所有上市+上櫃公司清單
var allStockList = await stockListBuilder.GetAllStockListAsync();
//目前所有上市公司清單
var tseList = await stockListBuilder.GetTSEListAsync();
//目前所有上櫃公司清單
var otcList = await stockListBuilder.GetOTCListAsync();

使用HistoryBuilder來搜尋歷史股價資訊,一次只能查一支股票一個月的資訊(datatime的日期無視)

var tseHistory = historyBuilder.GetStockHistories("9911", new DateTime(2017, 12, 1), StockType.TSE);
var otcHistory = historyBuilder.GetStockHistories("3088", new DateTime(2017, 12, 1), StockType.OTC);

StockInfoBuilder可使用ValueTuple(StockType, StockNo)來搜尋股票資訊,可以是多個

var stockInfo = await stockInfoBuilder.GetStocksInfo((StockType.TSE, "2317"), (StockType.OTC, "5015"));

或改Dictionary可以指定日期大約只支援目前日期的前一個禮拜,太久的無法查。(太久遠的請用HistoryBuilder查)

var stockInfos = await stockInfoBuilder.GetStocksInfo(queries, new DateTime(2020, 5, 6));

兩個builder資料範圍有點不太一樣,請自行決定要使用哪個

stocklib's People

Contributors

trend-jacky-su avatar twjackysu avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.