polygon-io / tradingview-adapter

JS Library for using Polygon.io with TradingView charting.
87 stars 25 forks source link

Getting resolveSymbol to work #3

Open maxthilen opened 4 years ago

maxthilen commented 4 years ago

Not sure if Polygon changed data format since this was built but I was having some issues integrating the adapter into tradingview charts. Updating resolveSymbol as follows solved the problem for me. Figured I'd share in case anyone else is having the same problem.

    resolveSymbol( symbol, cb, cberr ){
        console.log('resolve symbol:', symbol)
        let TickerTypeMap = {
            'STOCKS': 'stock',
            'FX': 'forex',
            'CRYPTO': 'bitcoin',
        }
        axios.get(`${BASE_URL}/v2/reference/tickers?search=${symbol}&perpage=50&page=1&apiKey=${this.apikey}`).then(( data ) => {
            console.log('DATAAA', data)
            let c = Get( data, 'data.tickers[0]', {} )
            console.log('c',c)
            cb({
                name: c.name,
                ticker: c.ticker,
                type: TickerTypeMap[ c.market ] || 'stocks',
                exchange: c.primaryExch,
                minmov: 1,
                pricescale: 100,
                session:'0900-1630',
                timezone: 'America/New_York',
                has_intraday: true,
                supported_resolutions: SUPPORTED_RESOLUTIONS,
            })
        })
    }
MrKalten commented 4 years ago

Same problem here.

I found some data using this :

axios.get(${BASE_URL}/v1/meta/symbols/${symbol}/company?apiKey=${this.apikey}).then(( data ) => {

But some data are missing, like "first_intraday"

platformsfx commented 4 years ago

Same problem, We informed polygon to this error 6 months ago ! with no solution until now. @qrpike @stacho Can you please Fix this ?

maxthilen commented 4 years ago

So as far as I can tell that code snippet above solves the issue - not sure if those fields are required or if it's possible to make it work without? Separately (and forgive me if this is a noob question), the comments in this code say it only supports 1 minute polling. Looking at the chart pre-market here, it doesn't appear to be grabbing the data immediately as its streamed in. Any suggestions on what needs to be changed to get this to stream as real time as possible?

MrYutz commented 3 years ago

They are making some API changes again.

This code allows the adapter to work correctly:

axios.get(`${BASE_URL}/v1/meta/symbols/${symbol}/company?apiKey=${this.apikey}`).then(( data ) => {
            console.log('Polygon Resolve Data:', data.data)
            let c = data.data;
            let intFirst = false
            let dayFirst = false
            cb({
                name: c.name,
                ticker: c.symbol,
                type: TickerTypeMap[ c.type ] || 'stocks',
                exchange: c.exchange,
                timezone: 'America/New_York',
                first_intraday: intFirst,
                has_intraday: true,
                first_daily: dayFirst,
                has_daily: true,
                supported_resolutions: SUPPORTED_RESOLUTIONS,
            })
        })
    }