-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #110 from farabi-deriv/farabi/bot-2280/update-accu…
…mulators-feature Farabi/bot-2280/update-accumulators-feature
- Loading branch information
Showing
21 changed files
with
452 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/external/bot-skeleton/scratch/accumulators-proposal-handler.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { api_base } from '../services/api'; | ||
import DBotStore from './dbot-store'; | ||
|
||
export const DEFAULT_PROPOSAL_REQUEST = { | ||
amount: undefined, | ||
basis: 'stake', | ||
contract_type: 'ACCU', | ||
currency: undefined, | ||
symbol: undefined, | ||
growth_rate: undefined, | ||
proposal: 1, | ||
subscribe: 1, | ||
}; | ||
|
||
export const forgetAccumulatorsProposalRequest = async instance => { | ||
if (instance && !instance.is_bot_running) { | ||
await api_base?.api?.send({ forget_all: 'proposal' }); | ||
instance.subscription_id_for_accumulators = null; | ||
instance.is_proposal_requested_for_accumulators = false; | ||
window.Blockly.accumulators_request = {}; | ||
} | ||
}; | ||
|
||
export const handleProposalRequestForAccumulators = instance => { | ||
const top_parent_block = instance?.getTopParent(); | ||
const market_block = top_parent_block?.getChildByType('trade_definition_market'); | ||
const symbol = market_block?.getFieldValue('SYMBOL_LIST'); | ||
const currency = DBotStore.instance.client.currency; | ||
const growth_rate = instance?.getFieldValue('GROWTHRATE_LIST') || 0.01; | ||
const amount = instance?.childBlocks_?.[0]?.getField('NUM')?.getValue() || 0; | ||
const proposal_request = { | ||
...DEFAULT_PROPOSAL_REQUEST, | ||
amount, | ||
currency, | ||
symbol, | ||
growth_rate, | ||
}; | ||
window.Blockly.accumulators_request = proposal_request; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/external/bot-skeleton/scratch/blocks/Binary/Tick Analysis/stat.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { localize } from '@deriv-com/translations'; | ||
import { modifyContextMenu } from '../../../utils'; | ||
|
||
Blockly.Blocks.stat = { | ||
init() { | ||
this.jsonInit(this.definition()); | ||
}, | ||
definition() { | ||
return { | ||
message0: localize('Current Stat'), | ||
output: 'Number', | ||
outputShape: Blockly.OUTPUT_SHAPE_ROUND, | ||
colour: Blockly.Colours.Base.colour, | ||
colourSecondary: Blockly.Colours.Base.colourSecondary, | ||
colourTertiary: Blockly.Colours.Base.colourTertiary, | ||
tooltip: localize('Returns the Current Stat'), | ||
category: Blockly.Categories.Tick_Analysis, | ||
}; | ||
}, | ||
meta() { | ||
return { | ||
display_name: localize('Current Stat'), | ||
description: localize('This block gives you the Current Stat value.'), | ||
}; | ||
}, | ||
customContextMenu(menu) { | ||
modifyContextMenu(menu); | ||
}, | ||
}; | ||
|
||
Blockly.JavaScript.javascriptGenerator.forBlock.stat = () => [ | ||
'Bot.getCurrentStat()', | ||
Blockly.JavaScript.javascriptGenerator.ORDER_ATOMIC, | ||
]; |
34 changes: 34 additions & 0 deletions
34
src/external/bot-skeleton/scratch/blocks/Binary/Tick Analysis/stat_list.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { localize } from '@deriv-com/translations'; | ||
import { modifyContextMenu } from '../../../utils'; | ||
|
||
Blockly.Blocks.stat_list = { | ||
init() { | ||
this.jsonInit(this.definition()); | ||
}, | ||
definition() { | ||
return { | ||
message0: localize('Current stat list'), | ||
output: 'Array', | ||
outputShape: Blockly.OUTPUT_SHAPE_ROUND, | ||
colour: Blockly.Colours.Base.colour, | ||
colourSecondary: Blockly.Colours.Base.colourSecondary, | ||
colourTertiary: Blockly.Colours.Base.colourTertiary, | ||
tooltip: localize('Returns the list of last digits of 1000 recent tick values'), | ||
category: Blockly.Categories.Tick_Analysis, | ||
}; | ||
}, | ||
meta() { | ||
return { | ||
display_name: localize('Current stat list'), | ||
description: localize('This block gives you a list of the cuurent stats of the last 1000 tick values.'), | ||
}; | ||
}, | ||
customContextMenu(menu) { | ||
modifyContextMenu(menu); | ||
}, | ||
}; | ||
|
||
Blockly.JavaScript.javascriptGenerator.forBlock.stat_list = () => [ | ||
'Bot.getStatList()', | ||
Blockly.JavaScript.javascriptGenerator.ORDER_ATOMIC, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ import './epoch'; | |
import './timeout'; | ||
import './todatetime'; | ||
import './totimestamp'; | ||
import './tickdelay'; |
84 changes: 84 additions & 0 deletions
84
src/external/bot-skeleton/scratch/blocks/Binary/Tools/Time/tickdelay.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { localize } from '@deriv-com/translations'; | ||
import DBotStore from '../../../../dbot-store'; | ||
import { evaluateExpression, modifyContextMenu } from '../../../../utils'; | ||
|
||
Blockly.Blocks.tick_delay = { | ||
init() { | ||
this.jsonInit(this.definition()); | ||
const { client } = DBotStore.instance; | ||
if (client && client.is_logged_in) { | ||
this.workspace_to_code = Blockly.JavaScript.javascriptGenerator.workspaceToCode(Blockly.derivWorkspace); | ||
} | ||
}, | ||
definition() { | ||
return { | ||
message0: localize('{{ stack_input }} Run after {{ number }} tick(s)', { | ||
stack_input: '%1', | ||
number: '%2', | ||
}), | ||
args0: [ | ||
{ | ||
type: 'input_statement', | ||
name: 'TICKDELAYSTACK', | ||
}, | ||
{ | ||
type: 'input_value', | ||
name: 'TICKDELAYVALUE', | ||
}, | ||
], | ||
colour: Blockly.Colours.Base.colour, | ||
colourSecondary: Blockly.Colours.Base.colourSecondary, | ||
colourTertiary: Blockly.Colours.Base.colourTertiary, | ||
previousStatement: null, | ||
nextStatement: null, | ||
tooltip: localize('Run the blocks inside after a given number of ticks'), | ||
category: Blockly.Categories.Time, | ||
}; | ||
}, | ||
meta() { | ||
return { | ||
display_name: localize('Tick Delayed run'), | ||
description: localize( | ||
'This block delays execution for a given number of ticks. You can place any blocks within this block. The execution of other blocks in your strategy will be paused until the instructions in this block are carried out.' | ||
), | ||
}; | ||
}, | ||
customContextMenu(menu) { | ||
modifyContextMenu(menu); | ||
}, | ||
getRequiredValueInputs() { | ||
return { | ||
TICKDELAYVALUE: input_value => { | ||
const evaluated_result = evaluateExpression(input_value); | ||
if (evaluated_result === 'invalid_input') { | ||
// this was done to check if any equation or varible assignment is present in the code. | ||
if (this.workspace_to_code && this.workspace_to_code.includes(input_value)) { | ||
return false; | ||
} | ||
this.error_message = localize('Invalid Input {{ input_value }}.', { input_value }); | ||
return true; | ||
} | ||
|
||
if (evaluated_result < 0) { | ||
this.error_message = localize('Values cannot be negative. Provided value: {{ input_value }}.', { | ||
input_value, | ||
}); | ||
return true; | ||
} | ||
}, | ||
}; | ||
}, | ||
}; | ||
|
||
Blockly.JavaScript.javascriptGenerator.forBlock.tick_delay = block => { | ||
const stack = Blockly.JavaScript.javascriptGenerator.statementToCode(block, 'TICKDELAYSTACK'); | ||
const ticks_value = | ||
Blockly.JavaScript.javascriptGenerator.valueToCode( | ||
block, | ||
'TICKDELAYVALUE', | ||
Blockly.JavaScript.javascriptGenerator.ORDER_ATOMIC | ||
) || '1'; | ||
|
||
const code = `Bot.getDelayTickValue(${ticks_value})\n${stack}\n`; | ||
return code; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.