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

Prince/ allow custom variables and function values for limit order #9490

Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,10 @@ Blockly.JavaScript.trade_definition_multiplier = block => {
const take_profit =
!block.getChildByType('multiplier_take_profit')?.disabled &&
block.childValueToCode('multiplier_take_profit', 'AMOUNT');
const limit_order = {};
limit_order.take_profit = take_profit ? +take_profit : undefined;
limit_order.stop_loss = stop_loss ? +stop_loss : undefined;
const limit_order = {
stop_loss: stop_loss ? `+(Number(${stop_loss}).toFixed(2))` : undefined,
take_profit: take_profit ? `+(Number(${take_profit}).toFixed(2))` : undefined,
};

setContractUpdateConfig(take_profit, stop_loss);
// Determine decimal places for rounding the stake, this is done so Martingale multipliers
Expand All @@ -280,6 +281,8 @@ Blockly.JavaScript.trade_definition_multiplier = block => {
amount : ${stake_amount},
limit_order : ${JSON.stringify(limit_order)},
basis : 'stake',
stop_loss : ${limit_order.stop_loss},
take_profit : ${limit_order.take_profit},
});
BinaryBotPrivateHasCalledTradeOptions = true;
`;
Expand Down
15 changes: 15 additions & 0 deletions packages/bot-skeleton/src/services/tradeEngine/trade/Total.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,21 @@ export default Engine =>
}
}

/* eslint-disable class-methods-use-this */
validateTradeOptions(tradeOptions) {
const take_profit = tradeOptions.take_profit;
const stop_loss = tradeOptions.stop_loss;

if (take_profit) {
tradeOptions.limit_order.take_profit = take_profit;
}
if (stop_loss) {
tradeOptions.limit_order.stop_loss = stop_loss;
}

return tradeOptions;
}

getAccountStat() {
const { loginid: accountID } = this.accountInfo;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,12 @@ export default class TradeEngine extends Balance(Purchase(Sell(OpenContract(Prop

globalObserver.emit('bot.running');

this.tradeOptions = tradeOptions;
const validated_trade_options = this.validateTradeOptions(tradeOptions);

this.tradeOptions = validated_trade_options;
this.store.dispatch(start());
this.checkLimits(tradeOptions);
this.makeProposals({ ...this.options, ...tradeOptions });
this.checkLimits(validated_trade_options);
this.makeProposals({ ...this.options, ...validated_trade_options });
this.checkProposalReady();
}

Expand Down