Socket
Socket
Sign inDemoInstall

bitfinex-candle-to-record

Package Overview
Dependencies
1
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    bitfinex-candle-to-record

Map a Bitfinex candle to a talib Record


Version published
Weekly downloads
3
Maintainers
1
Created
Weekly downloads
 

Readme

Source

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


Keywords

FAQs

Last updated on 30 Mar 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc