Coder Social home page Coder Social logo

Comments (6)

 avatar commented on May 15, 2024

I have to correct myself. I made a change to the code in another place to load up to 50000 candles from the database. This caused the later update etc. to take longer, resulting in the resampling not finding an up to date database! I reset the values to the original and it now works from what I can see.

from crypto-trading-bot.

 avatar commented on May 15, 2024

Well, sorry for the back and forth. But actually it does still not work! Regularly the resampled 10m candle is just using the close price of the first 5m candle but ignores the second candle, therefore causing wrong results!

Additional Issue: When the new resampled candle is finished the ticker event is triggered before the candle is actually in the database it seems. That causes the bot to have the wrong data for the indicators (unfinished resample candle) during the first ticker event that comes up after the new candle got created.
On the second ticker event after that it is correct again then I think.
Maybe the resampling should not be async?

from crypto-trading-bot.

 avatar commented on May 15, 2024

I was able to solve the first issue (10m candles with outdated data from the previous 5m candle) by increasing the timeout in bitmex.js around line 230 to 5000 (from 1000).

                    // lets wait for settle down of database insert: per design we dont know when is was inserted to database
                    setTimeout(async () => {
                        if (resamples[symbol['symbol']] && resamples[symbol['symbol']][period] && resamples[symbol['symbol']][period].length > 0) {
                            for (let periodTo of resamples[symbol['symbol']][period]) {
                                await me.candlestickResample.resample(this.getName(), symbol['symbol'], period, periodTo, true)
                            }
                        }
                    }, 5000);

The second issue solution: As the database takes some time to update the resampled candle with the final data, there will be one ticker event/one execution after the 5m candle update where the system would use the then still unfinished candle for indicator calculations. I have set the strategy up to only use candles that are at least 35 seconds old. That way I ignore the unfinished candles (but don't have to wait 5m for the next update).

In general I would hope there should be a better solution to not use these long timeouts of 5 or 35 seconds! Especially when thinking about faster candles I would think this could maybe have a better solutions.
Any ideas about this?

Thank you!

from crypto-trading-bot.

Haehnchen avatar Haehnchen commented on May 15, 2024

sry, yes indeed it was just a quick hack; refactored it now to use Promise under the hood.

can you maybe also check also timing issues. i think is was fixed with this commit some days ago: 42bce1c

This resolved gabs issues on backtesting only Bitmex (i think this what you noticed)

from crypto-trading-bot.

 avatar commented on May 15, 2024

Thank you for your reply!
Unfortunately even with the newest commits it is not working. After a candle change it will still use the value from the previous 5m candle (technically the unfinished 10m candle). Instead it should only trigger the tick event when the 10m candle is completed I would say.
I think this happens because as soon as the timestamp from the unfinished/future 10m candle is in the present, it will take the value for the next tick, even though the candle is still not finished/waiting for the final update of data.

I like your change with the async handling a lot in the Bitmex.js. Looks much better than with the timeout! :) However, if I am not mistaken you only changed the initial loading of candles from the exchange to async. The regular "stream" of candles is still using the timeout (around line 250 in Bitmex.js). If that would be async as well, it would be lovely I think! :)

from crypto-trading-bot.

 avatar commented on May 15, 2024

Awesome! 👏

from crypto-trading-bot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.