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: support of manual trades in breakeven amount calculator #601

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions app/cronjob/trailingTrade/step/get-indicators.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,10 @@ const nextBestBuyAmountCalculationConditions = data => {
* @param {*} currentPrice
* @param {*} lastBuyPrice
* @param {*} sellTrigger
* @param {*} buyTrigger
*/
const calculateNextBestBuyAmount = (
data,
{ currentPrice, lastBuyPrice, sellTrigger, buyTrigger }
{ currentPrice, lastBuyPrice, sellTrigger }
) => {
const {
symbolConfiguration: {
Expand Down Expand Up @@ -124,6 +123,8 @@ const calculateNextBestBuyAmount = (
}
);

const buyTrigger = 1 + (currentPrice - lastBuyPrice) / lastBuyPrice;
Copy link
Owner

@chrisleekr chrisleekr Mar 19, 2023

Choose a reason for hiding this comment

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

@rando128

I found when the lastBuyPrice is not configured, which will set as null, it returns Infinity for buyTrigger.

    currentPrice => 9000
    lastBuyPrice => null
    buyTrigger => Infinity

Is Infinity intended or it should be 1?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. It doesn't make sense to even try to calculate it in this case. Maybe we could condition nextBestBuyCalculation code with a if(lastBuyPrice > 0) statement on line 391

Copy link
Owner

Choose a reason for hiding this comment

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

Ok, good. Do you want to update, or do you want me to update? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fix just pushed!

Copy link
Owner

Choose a reason for hiding this comment

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

yay! I will check the tests and let's merge it.


let amount = null;

if (!hasObviousManualTrade && isSingleSellGrid) {
Expand Down Expand Up @@ -388,9 +389,6 @@ const execute = async (logger, rawData) => {
let nextBestBuyAmount = null;
let nextBestBuyCalculation = null;

// Compute with a grid at currentPrice
const nextBestBuyTrigger = 1 + (currentPrice - lastBuyPrice) / lastBuyPrice;

// If conservative mode is enabled, update the sell trigger for the next grid
// We won't compute nextBestBuy for multi-grid sells
const nextBestBuySellTriggerPercentage =
Expand All @@ -409,8 +407,7 @@ const execute = async (logger, rawData) => {
nextBestBuy = calculateNextBestBuyAmount(data, {
currentPrice,
lastBuyPrice,
sellTrigger: nextBestBuySellTrigger,
buyTrigger: nextBestBuyTrigger
sellTrigger: nextBestBuySellTrigger
});

nextBestBuyAmount = nextBestBuy.amount;
Expand Down