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

feat: next buy grid calculator #554

Merged
merged 11 commits into from
Dec 19, 2022

Conversation

rando128
Copy link
Contributor

@rando128 rando128 commented Dec 16, 2022

Description

This PR provides an enhancement to the next-buy-grid-amount feature introduced in #540 with a new grid calculator.

The calculator allows to determine the amount you would need to purchase at a specific buy trigger point and achieve break-even if the market price rebounds to a targeted percentage.

Screenshot 2022-12-11 at 15 27 38

The calculator is available from buy grid section and replaces #540 popup.

Related Issue

The enhancement was suggested by @peweb in #540 (comment)

How Has This Been Tested?

This is working on my production server.

Screenshots (if appropriate):

Screenshot 2022-12-16 at 18 55 03

Screenshot 2022-12-16 at 21 52 09

@rando128 rando128 changed the title Feat/next grid calculator Feat/next buy grid calculator Dec 16, 2022
@peweb
Copy link

peweb commented Dec 18, 2022

@chrisleekr can you please push this release? I am wating for this for a long time. Thanks!

@chrisleekr chrisleekr changed the title Feat/next buy grid calculator feat: next buy grid calculator Dec 18, 2022
@chrisleekr chrisleekr added the enhancement New feature or request label Dec 18, 2022
@chrisleekr
Copy link
Owner

chrisleekr commented Dec 18, 2022

@peweb Sorry, I've been busy recently. I just reviewed it. :)

@rando128 Thank you for your contribution.

First of all, are you using VS code? It seems auto linting is not applied when you save the file.
If you are not using VS code, please use VS code. It definitely will help to lint.

Secondly, I've fixed the missing production build code change - af3b87f

Lastly, I may not understand completely or misunderstand.

But the following scenario (this is a test server), is "Suggested breakeven amount" correct?
image

And it's showing a negative purchase amount. Is this correct too?
image

@rando128
Copy link
Contributor Author

Thx @chrisleekr for the review.

Sorry to have missed the production change (I'm running docker-compose in build mode on my production server...). Also I'll try not mess up with lint in my next submission (I'm using PyCharm).

With regards to your scenario, something is definitely wrong. I suspect this is due to your grid having a manual trade (which is indicated I believe by the grey clock icon of grid #1). My calculations don't take into this case. I'll look into how to handle it.

@chrisleekr
Copy link
Owner

All good @rando128 :)

To replicate the attached scenario:

  1. The Coin already had more than $10 to sell.
  2. Set the last buy price
  3. Execute 2nd grid and wait for the execution

And I also executed the manual trade with the suggested amount.

@rando128
Copy link
Contributor Author

@chrisleekr, I have updated the logic to account for pointless grid scenarios (where the user expects a rebound that hits the profitable sell price target).

I'll try and replicate your scenario to double-check the calculations.

@rando128
Copy link
Contributor Author

@chrisleekr, it turns out that we can't make recommendations of the next grid if we don't know all the historical price and quantity information. So I have hidden the breakeven section when a buy grid includes manual trades.

So we should now be good with my latest commit.

@chrisleekr
Copy link
Owner

chrisleekr commented Dec 19, 2022

@rando128 Thanks for your changes.

Yap, looks good.

Although I wish you could have handled the manual trade as well. I do understand the manual trade is not returning from the latest data.

Anyway, let me merge in first. 🎉

Ah, one more thing. I saw your commit message is not following the conventions I forced to follow.
https://github.com/chrisleekr/binance-trading-bot/blob/master/DEVELOPMENT.md#commit-message-conventions

How did you bypass naming convention rules? 🤣
Did you npm install? It should install git hook, though.

@chrisleekr chrisleekr merged commit 3d9bf1f into chrisleekr:master Dec 19, 2022
@rando128
Copy link
Contributor Author

@chrisleekr, I could easily support manual trades if the symbolConfiguration object would include such trades. Would it be possible for you to add manually executed orders under symbolConfiguration.buy.gridTrade[i].executedOrder but specifying symbolConfiguration.buy.gridTrade[i].executed=false to avoid side effects in the current application itself?

With regards to not respecting conventions, my PyCharm setup is definitely broken. I will move to VSC to respect the development rules 😁

@habibalkhabbaz
Copy link
Contributor

habibalkhabbaz commented Dec 20, 2022

Hello @rando128
It is an awesome feature. Thanks! 💯

I am trying to figure it out right now. However, I have this:

TFUEL Data TFUEL Calculator

I think something is wrong with the buy price 0.503 or that's correct?

@habibalkhabbaz
Copy link
Contributor

Sorry @rando128
Just ignore it. I understood it now.

@rando128
Copy link
Contributor Author

@habibalkhabbaz, I know it can be confusing at first. I originally designed the feature with absolute prices and true percentages, but I eventually decided to stick to the grid configuration principles (with multipliers) to educate users on the bot settings principles.

@peweb
Copy link

peweb commented Dec 29, 2022

@rando128
This is a neat feature but I cant get it yet.
Can you please help me understand how does it work?

image

image

Why it advices to buy higer amount if I increase the buy trigger percentage difference from last buy price?

I have
Current price: 0.3455
Last buy price: 0.4258
Suggested breakeven amount 46705.4757
What would be the breakeven amount if I set it buy at 0.32?

@rando128
Copy link
Contributor Author

Why it advices to buy higer amount if I increase the buy trigger percentage difference from last buy price?

@peweb, increasing the buy trigger percentage (from -18,73% to -28,70% in your example), means buying at a lower price. Because the last buy price is the sum(previous purchased amounts) / sum(previous purchased quantities), the lower you buy, the more funds are required to compensate the loss and achieve breakeven.

Another way to intuitively see it with the calculator graph:

  • If you make a new buy with a huge amount of money (think "$1M on the coin"), the new last buy price will become very close to the buy price, so you easily breakeven with a very small market price increase after the purchase.
  • On the opposite, if you buy with a small amount (think "$1 on the coin"), the new last buy price will stay very close to the previous last buy price, meaning the market price will have to increase at your current loss percentage to reach breakeven.

@peweb
Copy link

peweb commented Jan 15, 2023

@rando128
It's a pretty good improvement, but kind of hard to work with.

Would it be possible to add the calculated prices in USDT as well?

On the screenshot it says buy trigger precentage on last buy price 0.85 resulting in difference from current price in %, could you please add the USDT amount as well?

You can enhance the summary by adding USDT in three places, I think.

On Results - executong new grid at -15% / {USDT} from your current last buy price {USDT} with a purchase amount of 490.11 USDT , would allow you to break even if the market price rebounds 10.00% {USDT}

image

I hope this will make our calculations easier and more efficient.

Thing is, working with % is tricky (for me). When I see the chart, I might want to make a new buy at 0.35 and hope to profit at 0.39. What amount should I buy at 0.35 and what % should I enter in the pair configuration? This is how I see this improvement working for me, what about you?

@rando128
Copy link
Contributor Author

@peweb, the current UX is indeed based on % to be aligned with the symbol grid settings paradigms, but I understand your point. I guess you noticed that the USDT price is indicated for the rebound percentage (e.g. 'Equivalent market price') so you can play with the % until it matches your target price.

I can easily extend this to the buy trigger:
Screenshot 2023-01-17 at 09 43 59

Would that cover your needs?

That said, keep in mind that the trigger prices are just triggers for placing stop orders and won't never correspond to the actual price the bot will buy or sell.

@peweb
Copy link

peweb commented Jan 17, 2023

@rando128 yes that would be great!

Copy link

@Debu976116 Debu976116 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bot

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

Successfully merging this pull request may close these issues.

None yet

5 participants