LoginSignup
1
0

More than 3 years have passed since last update.

go修行15日目 サードパーティ製パッケージを使う

Posted at

サードパーティパッケージのインストール

  • 株価分析のためのパッケージ

インストール

go get github.com/markcheno/go-talib
go get github.com/markcheno/go-quote

インストールされる場所

PS C:\Users\yuta\go\src\github.com> ls .\markcheno\


    ディレクトリ: C:\Users\yuta\go\src\github.com\markcheno  


Mode                 LastWriteTime         Length Name      
----                 -------------         ------ ----       
d-----        2020/07/03      8:45                go-talib  

サンプルコード


package main

import (
    "fmt"
    "github.com/markcheno/go-quote"
    "github.com/markcheno/go-talib"
)

func main() {
    spy, _ := quote.NewQuoteFromYahoo("spy", "2016-01-01", "2016-04-01", quote.Daily, true)
    fmt.Print(spy.CSV())
    rsi2 := talib.Rsi(spy.Close, 2)
    fmt.Println(rsi2)
}

出力

datetime,open,high,low,close,volume
2016-01-04 00:00,200.49,201.03,198.59,184.03,222353500.00
2016-01-05 00:00,201.40,201.90,200.05,184.34,110845800.00
2016-01-06 00:00,198.34,200.06,197.60,182.01,152112600.00
2016-01-07 00:00,195.33,197.44,193.59,177.64,213436100.00

パッケージ自体を呼ばせない場合

  • importしたパッケージが呼ばれないとビルド時にエラーになるため

package main

import (
    "fmt"
    "github.com/markcheno/go-quote"
    _ "github.com/markcheno/go-talib"
)

func main() {
    spy, _ := quote.NewQuoteFromYahoo("spy", "2016-01-01", "2016-04-01", quote.Daily, true)
    fmt.Print(spy.CSV())
    // rsi2 := talib.Rsi(spy.Close, 2)
    // fmt.Println(rsi2)
}

godoc

  • ローカル環境でgodocを見ることができる
  • Example関数などで自分で書いたコードをExampleとしてみることができる

インストール

go get golang.org/x/tools/cmd/godoc

利用方法

godoc -http=:6060

アクセス

image.png

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0