概要
- 【目的】手軽にテクニカル分析したい
- - 環境
- Windows10
- VSCode
- Node v8.11.3
- 参考
Sample axios,tulind
Bitmexから1分足を取得してSMAを得る
- BITMEX API doc
- https://www.bitmex.com/api/explorer/#!/Trade/Trade_getBucketed
const axios =require('axios')
var tulind = require('tulind')
const test = async ()=>{
const res = await axios.get('https://testnet.bitmex.com/api/v1/trade/bucketed'
+'?symbol=XBTUSD' + '&binSize=1m&partial=true&count=10&reverse=true')
const close = res.data.map(v => v['close'])
const sma = await tulind.indicators.sma.indicator([close], [3])
console.log(close)
console.log(sma)
}
test()
output
//close
[ 7338.5, 7338.5, 7338.5, 7338.5, 7339, 7339, 7338, 7341, 7341, 7345.5 ]
//sma
[ [ 7338.5,
7338.5,
7338.666666666666,
7338.833333333333,
7338.666666666666,
7339.333333333333,
7340,
7342.5 ] ]
コンソール上にチャートを表示(asciichart)
const axios =require('axios')
var tulind = require('tulind')
var asciichart = require ('asciichart')
const test = async ()=>{
const res = await axios.get('https://testnet.bitmex.com/api/v1/trade/bucketed'
+'?symbol=XBTUSD' + '&binSize=1m&partial=true&count=50&reverse=true')
const close = res.data.map(v => v['close'])
const sma = await tulind.indicators.sma.indicator([close], [10])
console.log(asciichart.plot(sma[0],{ height: 10 }))
}
test()
output
7343.65 ┤ ╭─╮
7342.00 ┤ ╭──╯ ╰╮
7340.35 ┤ ╭──╯ ╰───╮
7338.70 ┤ ╭────╯ ╰╮
7337.05 ┤ ╭────────╯ ╰
7335.40 ┤ ╭──╯
7333.75 ┤ ╭╯
7332.10 ┤ ╭─╯
7330.45 ┤ ╭─╯
7328.80 ┤ ╭─╯
7327.15 ┼─╯