polygon-io / client-js

The official JS client library for the Polygon REST and WebSocket API.
MIT License
190 stars 59 forks source link

Getting multiple responses for conditions Polygon IO API #107

Closed pradeep9843 closed 1 year ago

pradeep9843 commented 2 years ago

Hi Team , We are trying to consume conditions polygon IO API and we are passing the expected parameters (see attached), but the request url / response parameters seems to be very different image

https://api.polygon.io/v3/reference/conditions?0=x&1=B&10=T&11=T&12=5&13=4&14=h&15=j&16=m&17=n&18=D&19=S&2=4&20=t&21=n&22=v&23=n&24=n&25=K&26=U&27=D&28=_&29=a&3=j&30=p&31=H&4=Q&5=V&6=m&7=4&8=3&9=h&apiKey=xxxxxxxxxxxxxxxx

image

Please see the expected output in the below mentioned url https://polygon.io/docs/stocks/get_v3_reference_conditions

Please find the output getting in the attached screenshot ( we are consuming the same API which was provided in the above url but the response is different)

image

Please do the needful

pradeep9843 commented 2 years ago

Team, Any update?

rexkenley commented 2 years ago

I think the issue is coming from this line image

Based on the documentation query-string stringify is supposed to image

But is not doing so based on the resulting url https://api.polygon.io/v3/reference/conditions?0=x&1=B&10=T&11=T&12=5&13=4&14=h&15=j&16=m&17=n&18=D&19=S&2=4&20=t&21=n&22=v&23=n&24=n&25=K&26=U&27=D&28=_&29=a&3=j&30=p&31=H&4=Q&5=V&6=m&7=4&8=3&9=h&apiKey=*****

timetraveler328 commented 1 year ago

@pradeep9843 I believe the issue is that the parameter passed into reference.conditions needs to be an object instead of passing individual parameters for each query element.

It should look something like await reference.conditions({ asset_class: 'stocks', data_type: 'trades', id: '123', sip: 'CTA', order: 'asc', limit: 10, sort: 'id' }) where each query element is a key to an object

You shouldn't need to pass apiKey in the query since you've initialized the client with it. We use the spread operator to combine the apiKey passed into the client with the query object before sending the request, which is why your resulting request looked strange, it was spreading the string instead of an object.

We'll add this example to our README as well. Let us know if this solves it for you.

timetraveler328 commented 1 year ago

Closing this issue as resolved by the solution above. Please feel free to create a new issue if you think there's still something here that needs addressed.