Nondeterministic Palindrome Machine

    bitfinex-candle-to-record
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.2 • Public • Published

    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


    Install

    npm i bitfinex-candle-to-record

    DownloadsWeekly Downloads

    5

    Version

    1.0.2

    License

    ISC

    Unpacked Size

    5.23 kB

    Total Files

    4

    Last publish

    Collaborators

    • hamroctopus