0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Go言語(プログラミング)入門メモ㉕

Posted at

サードパーティパッケージを利用する

Goには様々な機能をもつ標準パッケージがあるが、開発したい機能によってはサードパーティのパッケージを活用する場合もある。
サードパーティのパッケージをインストールして使用する方法を確認する。

インストール

サードパーティが公開しているパッケージは、次のURLで検索できる。
https://pkg.go.dev/
今回はtalibという株価を分析するサードパーティパッケージをインストールしてみる。
https://pkg.go.dev/github.com/markcheno/go-talib
Goではgo getというコマンドで、サードパーティのパッケージをインストールする。
ターミナルでページに記載されているダウンロード用のコマンドを実行する。
「go get github.com/markcheno/go-talib」
image.png
また、株価などの情報をダウンロードするquoteというパッケージもインストールする。
「go get github.com/markcheno/go-quote」
image.png
talibのGitHubに掲載されているサンプルコードを実行すると、SPY(アメリカ企業500社の株価を基に算出される日本の日経225的なもの)と呼ばれる値を出力する

package main

import (
	"fmt"

	"github.com/markcheno/go-quote"
	"github.com/markcheno/go-talib"
)

func main() {
	spy, _ := quote.NewQuoteFromTiingo("spy", "2016-01-01", "2016-04-01", "取得したAPIキー")
	fmt.Print(spy.CSV())
	rsi2 := talib.Rsi(spy.Close, 2)
	fmt.Println(rsi2)
}

実行結果は以下のようになる
image.png

学習に使用した教材

・『入門】Golang基礎入門 + 各種ライブラリ + 簡単なTodoWebアプリケーション開発(Go言語)』M.A EduTech
https://www.udemy.com/course/golang-webgosql/?utm_medium=udemyads&utm_source=bene-msa&utm_campaign=responsive&utm_content=top-1&utm_term=general&msclkid=81e2f24a32cc185d275d953d60760226&couponCode=NEWYEARCAREERJP

・『シリコンバレー一流プログラマーが教える Goプロフェッショナル大全』酒井 潤 (著)
https://www.amazon.co.jp/%E3%82%B7%E3%83%AA%E3%82%B3%E3%83%B3%E3%83%90%E3%83%AC%E3%83%BC%E4%B8%80%E6%B5%81%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%9E%E3%83%BC%E3%81%8C%E6%95%99%E3%81%88%E3%82%8B-Go%E3%83%97%E3%83%AD%E3%83%95%E3%82%A7%E3%83%83%E3%82%B7%E3%83%A7%E3%83%8A%E3%83%AB%E5%A4%A7%E5%85%A8-%E9%85%92%E4%BA%95-%E6%BD%A4/dp/4046070897

0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?