Skip to content
This repository was archived by the owner on Feb 22, 2024. It is now read-only.
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
87 changes: 63 additions & 24 deletions src/botPage/view/blockly/blocks/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ let purchaseChoices = [[translate('Click to select'), '']];
export const getPurchaseChoices = () => purchaseChoices;

const filterPurchaseChoices = (contractType, oppositesName) => {
if (oppositesName.toLowerCase() === 'na') {
return [[translate('Not available'), 'na']];
}

const { [oppositesName]: tradeTypes } = config.opposites;

let tmpPurchaseChoices = tradeTypes.filter(k =>
Expand Down Expand Up @@ -86,46 +90,79 @@ const getActiveMarket = markets =>

fieldGeneratorMapping.MARKET_LIST = () => {
const markets = getActiveMarket(symbolApi.activeSymbols.getMarkets());

if (Object.keys(markets).length === 0) {
return [[translate('Not available'), 'na']];
}
return Object.keys(markets).map(e => [markets[e].name, e]);
};

fieldGeneratorMapping.SUBMARKET_LIST = block => () => {
const markets = getActiveMarket(symbolApi.activeSymbols.getMarkets());
const marketName = block.getFieldValue('MARKET_LIST');
if (!marketName || marketName === 'Invalid') {
return [['', 'Invalid']];
const submarketOptions = [];

if (Object.keys(markets).length > 0 && marketName !== 'na') {
const marketObj = markets[marketName];

if (marketObj) {
const submarkets = getActiveSubMarket(marketObj.submarkets);

submarketOptions.push(
...Object.keys(submarkets)
.map(e => [submarkets[e].name, e])
// Filter out markets we don't have contracts for
.filter(submarket => !['energy'].includes(submarket[1]))
);
}
}
const submarkets = getActiveSubMarket(markets[marketName].submarkets);
return (
Object.keys(submarkets)
.map(e => [submarkets[e].name, e])
// Filter out markets we don't have contracts for
.filter(submarket => !['energy'].includes(submarket[1]))
);

if (submarketOptions.length === 0) {
return [[translate('Not available'), 'na']];
}

return submarketOptions;
};

fieldGeneratorMapping.SYMBOL_LIST = block => () => {
const markets = getActiveMarket(symbolApi.activeSymbols.getMarkets());
const submarketName = block.getFieldValue('SUBMARKET_LIST');
if (!submarketName || submarketName === 'Invalid') {
return [['', '']];
const symbolOptions = [];

if (Object.keys(markets).length > 0 && submarketName !== 'na') {
const marketName = block.getFieldValue('MARKET_LIST');
const marketObj = markets[marketName];

if (marketObj) {
const { submarkets } = marketObj;

if (Object.keys(submarkets).length > 0 && submarkets[submarketName]) {
const symbols = getActiveSymbols(submarkets[submarketName].symbols);

symbolOptions.push(
...Object.keys(symbols)
.map(e => [symbols[e].display, symbols[e].symbol])
// Filter out symbols we don't have contracts for (these symbols have only forward-starting)
.filter(symbol => !['frxGBPNOK', 'frxUSDNOK', 'frxUSDNEK', 'frxUSDSEK'].includes(symbol[1]))
);
}
}
}
const marketName = block.getFieldValue('MARKET_LIST');
const submarkets = getActiveSubMarket(markets[marketName].submarkets);
const symbols = getActiveSymbols(submarkets[submarketName].symbols);
return (
Object.keys(symbols)
.map(e => [symbols[e].display, symbols[e].symbol])
// Filter out symbols we don't have contracts for (these symbols have only forward-starting)
.filter(symbol => !['frxGBPNOK', 'frxUSDNOK', 'frxUSDNEK', 'frxUSDSEK'].includes(symbol[1]))
);

if (symbolOptions.length === 0) {
return [[translate('Not available'), 'na']];
}

return symbolOptions;
};

fieldGeneratorMapping.TRADETYPECAT_LIST = block => () => {
const symbol = block.getFieldValue('SYMBOL_LIST');
if (!symbol) {
return [['', '']];

if (!symbol || symbol === 'na') {
return [[translate('Not available'), 'na']];
}

const allowedCategories = symbolApi.getAllowedCategories(symbol.toLowerCase());
return Object.keys(config.conditionsCategoryName)
.filter(e => allowedCategories.indexOf(e) >= 0)
Expand All @@ -134,9 +171,11 @@ fieldGeneratorMapping.TRADETYPECAT_LIST = block => () => {

fieldGeneratorMapping.TRADETYPE_LIST = block => () => {
const tradeTypeCat = block.getFieldValue('TRADETYPECAT_LIST');
if (!tradeTypeCat) {
return [['', '']];

if (!tradeTypeCat || tradeTypeCat === 'na') {
return [[translate('Not available'), 'na']];
}

return (
config.conditionsCategory[tradeTypeCat]
.map(e => [config.opposites[e.toUpperCase()].map(c => c[Object.keys(c)[0]]).join('/'), e])
Expand Down
6 changes: 3 additions & 3 deletions src/botPage/view/blockly/blocks/trade/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const marketDropdown = block => {
block
.appendDummyInput('MARKETDEFINITION')
.appendField(`${translate('Market')}:`)
.appendField(new Blockly.FieldDropdown(fieldGeneratorMapping.MARKET_LIST), 'MARKET_LIST')
.appendField(new Blockly.FieldDropdown(fieldGeneratorMapping.MARKET_LIST()), 'MARKET_LIST')
.appendField('>')
.appendField(new Blockly.FieldDropdown(fieldGeneratorMapping.SUBMARKET_LIST(block)), 'SUBMARKET_LIST')
.appendField('>')
Expand All @@ -28,10 +28,10 @@ export const contractTypes = block => {
if (!block.getInput('CONTRACT_TYPE')) {
const getContractTypes = () => {
const tradeType = block.getFieldValue('TRADETYPE_LIST');
if (tradeType) {
if (tradeType && tradeType !== 'na') {
return [[translate('Both'), 'both'], ...oppositesToDropdown(config.opposites[tradeType.toUpperCase()])];
}
return [['', '']];
return [[translate('Not available'), 'na']];
};
block
.appendDummyInput('CONTRACT_TYPE')
Expand Down
6 changes: 6 additions & 0 deletions src/botPage/view/blockly/blocks/trade/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ Blockly.Blocks.trade = {
resetTradeFields(this, ev);
}

if (ev.type === Blockly.Events.BLOCK_CREATE && ev.group !== 'load') {
const marketField = this.getField('MARKET_LIST');
marketField.setValue('');
marketField.setValue(marketField.menuGenerator_[0][1]); // eslint-disable-line
}

decorateTrade(ev);
},
};
Expand Down
2 changes: 1 addition & 1 deletion src/botPage/view/blockly/blocks/trade/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const getParentValue = (block, fieldName) => {

export const updateInputList = block => {
const tradeType = getParentValue(block, 'TRADETYPE_LIST');
if (tradeType) {
if (Blockly.Blocks[tradeType]) {
Blockly.Blocks[tradeType].init.call(block);
}
};
Expand Down