LoginSignup
1
1

More than 3 years have passed since last update.

GASとスプシで仮想通貨の価格を取得&記録

Last updated at Posted at 2021-01-06

課題

仮想通貨の取引では、なんやかんやで行き当たりばっかりの取引をしがちである。
数字や理論に基づいた取引の練習がしにくい。

解決策

タイムスタンプ、取引価格をボタンクリックで取得し、その横に、自分の現在の市場に対する仮説をメモできる仕組みを作った。
これにより、これからは取引に失敗or成功しようと、その時の自分の仮説を検証でき、徐々に仮説の精度をあげる練習を継続的に行えうる。スクリーンショット 2021-01-06 10.44.14.png

デモはこちら
https://youtu.be/-6Mb4v2YSpk

使用技術

Google Apps Script
Google Spreadsheets
bifFlyer Lightning API (詳細: https://api.bitflyer.jp/

GASソースコード

GAS

function setValues() {
  const spreadsheet = SpreadsheetApp.getActive()
  const lastRow = spreadsheet.getLastRow()
  const response = JSON.parse(getResponseFromBitflyerAPI())
  setTime(spreadsheet, lastRow)
  setBTCPrice(spreadsheet, lastRow,response)
  setVolume(spreadsheet, lastRow,response)

}

function setTime(spreadsheet, lastRow) {
  const date = new Date()
  spreadsheet.getRange(`A${lastRow + 1}`).setValue(date)
}

function setBTCPrice(spreadsheet, lastRow, response) {
  const ltp = response.ltp
  spreadsheet.getRange(`B${lastRow + 1}`).setValue(ltp)
}

function setVolume(spreadsheet,lastRow,response){
  const volume= response.volume
  Logger.log(volume)
  spreadsheet.getRange(`C${lastRow + 1}`).setValue(volume)
}

function getResponseFromBitflyerAPI() {
  const getURL = 'https://api.bitflyer.jp//v1/ticker'
  const response = UrlFetchApp.fetch(getURL).getContentText()
  return response
}

解説

この記事見てる人はGASには詳しいと思われるので、詳しい説明は割愛します。
以下、端的にコメントをします:
・SpreadsheetAppのAPIの呼び出し回数を少なくする必要がある
・API利用はURLFetchAppを使い、それをJSON.parseでJavaScriptのオブジェクト形式にする
・スプレッドシート側では、時刻には表示形式を時刻に、価格には価格と明示的に設定しましょう。
→そうしなければ、BTCの価格が時刻と認識されたりして、おかしな表示になります。
・図形描画にスクリプトを割り当てればGUIで操作できる

GASで楽しい毎日を!

GASを使えば、GUIで外部サービスとGoogle Appsを連携させ便利な操作ができます。
業務効率化として使わないという選択肢はありません!
それでは、素晴らしいエンジニアライフを!後、cryptoライフを!

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