Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trade safety computation #247

Open
victor-ono opened this issue Jan 29, 2019 · 1 comment
Open

Trade safety computation #247

victor-ono opened this issue Jan 29, 2019 · 1 comment

Comments

@victor-ono
Copy link

Can someone please explain what this piece of code from safety.ts does? I understand that its purpose is to balance buys and sells. However I don't understand the algorithm. I tested it with the example trades from trds quoting parameter description in the wiki and got different results - Buy TS: 1.75, Sell TS: 0.75 instead of Buy TS: 2.75, Sell TS: 0:

https://jsfiddle.net/victoro/bo9k7gqz/

        // don't count good trades against safety
        while (_.size(this._buys) > 0 && _.size(this._sells) > 0) {
            var sell = _.last(this._sells);
            var buy = _.last(this._buys);
            if (sell.price >= buy.price) {

                var sellQty = sell.quantity;
                var buyQty = buy.quantity;

                buy.quantity -= sellQty;
                sell.quantity -= buyQty;

                if (buy.quantity < 1e-4) this._buys.pop();
                if (sell.quantity < 1e-4) this._sells.pop();
            }
            else {
                break;
            }
        }
@victor-ono
Copy link
Author

I think I figured it out - when this algorithm runs on every trade, i.e. every time a trade happens, and not on a collection of trades it works as expected. However, there's still an error in the wiki in trds description. In the last two rows BuyTS values should be 1.25 and 1.75, not 1.75 and 2.75:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant