JSPM

bitfinex-candle-to-record

1.0.2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q30478F
  • License ISC

Map a Bitfinex candle to a talib Record

Package Exports

  • bitfinex-candle-to-record

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (bitfinex-candle-to-record) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

bitfinex-candle-to-record Build Status npm version npm

Map a Bitfinex candle to a talib Record

Install

npm install bitfinex-candle-to-record

Use

import bitfinexCandleToRecord from 'bitfinex-candle-to-record'

const URL_BITFINEX = 'https://api.bitfinex.com/v2'

const got = require('got')
import { URLSearchParams } from 'url'
import Record from 'timeseries-record'

type Candle = number[]

async function getCandles(tradepair: string, session: string): Promise<Candle[]> {
    let candles: Candle[] = []
    try {
        const response = await got(`candles/trade:${session}:t${tradepair}/hist`,
                                   {baseUrl: URL_BITFINEX})
        candles = JSON.parse(response.body)
    } catch (error) {
        console.log('Aborting: ', error.response.body)
    }
    return candles
}

async function main() {
    try {
        const candles: Candle[] = await getCandles('BTCUSD', '1D')
        const records: Record[] = candles.map(bitfinexCandleToRecord)
        console.log('Records:\n', records)
    } catch (error) {
        console.error('Error:', error)
    }
}

main()
//=> Records:
//   [ { Time: 1547683200000,
//      Open: 3675.4,
//      High: 3725,
//      Low: 3606.2,
//      Close: 3701.7,
//      Volume: 9515.37704315 },
//    { Time: 1547510400000,
//      Open: 3749.3,
//      High: 3780.87473393,
//      Low: 3623.1,
//      Close: 3654.3,
//      Volume: 13323.05379345 },
//    { Time: 1547424000000,
//      Open: 3590.9,
//      High: 3799.4,
//      Low: 3580,
//      Close: 3749.3,
//      Volume: 14836.12276868 },
//    ... ]

Index