Tucsky / aggr-server

Cryptocurrency trades aggregator (server side)
166 stars 76 forks source link

400 Bad Request from influx fetch function #11

Closed quadragen closed 1 year ago

quadragen commented 1 year ago

A 400 Bad Request error occurred: overflowed duration. The SELECT query, in the WHERE clause, appends 'ms' to the end of both the "from" and "to" values. However, when viewing the data in influxdb using influxdb-cli, the "time" values do not include 'ms' at the end. I see values like 1671323630000000000. When I try to use the SELECT query in influx.js fetch function, I get the same "overflowed duration" error when it tries to use the value 1671323630000000000ms, but I do not get this error when I remove the 'ms'.

I must be overlooking something, but I am not understanding why the ms is in the SELECT query. More broadly, when I am running Aggr-server locally, I cannot find a working API_URL value for Aggr. It is suggested to use http://localhost:3001/historical/{from}/{to}{timeframe}/{market}, but I do not understand what I am supposed to put in for these values. I can workout timeframes and markets, but the "from" and "to" values are confusing me. I have tried a few different ones, but I don't understand why I am hard-coding the from and to values here. It seems to me that a better API_URL would be http://localhost:3001/ or http://localhost:3001/historical.

Thank you for any clarity you can provide.

Tucsky commented 1 year ago

Yes influx uses nanosecond precision internaly, divide it by 1000000 for ms... Not sure how you got err ? Make sure the client still query using ms precision Also params interpolation was removed from the frontend urls so http://localhost:3001/ is indeed the correct value 👍🏼

quadragen commented 1 year ago

Thank you, that clarified quite a bit. I was getting the error "too many bars" or "output not specified". I specify this API_URL in .env.local, and I set a breakpoint in aggr-server and launch it with debugging on, but aggr never triggers the breakpoint on aggr-server, and the historical candles do not populate on a chart refresh. This suggest to me that Aggr is not attempting to pull the historical data from the specified API_URL. I can trigger the breakpoint manually by accessing the url directly from another tab.

quadragen commented 1 year ago

What I am attempting to do is to trigger a chart refresh automatically on an hourly cycle as a stopgap workaround to this websocket restriction. The Binance RESTful API still works in USA, so an alternative solution would be to poll this every 1 second or so instead of subscribing to the websocket.

Tucsky commented 1 year ago

hmm I see why not set up a proxy ws server ?

simply host this ws server in a authorized country https://gist.github.com/Tucsky/91a9ed6bc6bb436ccf0c3e97b66c43eb and edit the client so that it connect to your server (ex here localhost:3000) instead of connecting to binance directly

ws://localhost:3000?url=wss://stream.binance.com:9443/ws
image
Tucsky commented 1 year ago

I can add an option in the client UI to specify a binance proxy server url Do you know if binance send something that says the connection couldn't establish because of origin of country ? If the client can detect that... then it could connect through the proxy immediately

I've been able to test it from US. So everytime an exchange close connection with 451 status code, aggr will prompt user to enter a proxy url / use the one already set

quadragen commented 1 year ago

Yes it does.  I’ll send you the error message soon.  I believe it sends status code 400 as well.

Tucsky commented 1 year ago

I implemented the solution here, where it shows a popup when a the websocket throw an error, any error because the front end can't even retrieve the status code (451) It works well but it's kind of a pain to setup, I mean you have to host a whole node server to make it to work, 99% won't do that Still better than polling their rest api every sec lmao Maybe there is a easier solution involving nginx reverse proxy with dynamic url but I haven't tested

quadragen commented 1 year ago

Great!  I will test this out and setup a node server in one of the working countries.  I think they said Japan, UK, and Italy are all working still.

quadragen commented 1 year ago

Cool it works. Any plans to merge this into production on v3.aggr.trade? I don't mind hosting the chart myself but I've had some issues getting the historical candles working with aggr-server.

Tucsky commented 1 year ago

You can test it here https://tucsky.github.io/aggr/ I included that change in a bigger update and still have to test further before deploy on main domain -

The nodejs script might be buggy tho because it doesn't keep track of everyones subscriptions, so everyone connected to that proxy url is getting everyone else market data -_- Works for individual usage tho Also it doesn't apply any delay to the messages sent to the exchanges and Binance will close the connection if too much message are sent too fast for exemple... more work are needed on that

quadragen commented 1 year ago

I’m hosting the chart and the proxy just for myself.

quadragen commented 1 year ago

It works perfectly. Thank you! I'm fine just using this branch on my end. I had always planned to host it myself instead of relying on your host.