Skip to content

Commit bb5c2e7

Browse files
committed
Removed markets with no available trade
1 parent b2340e5 commit bb5c2e7

File tree

2 files changed

+51
-49
lines changed

2 files changed

+51
-49
lines changed

src/botPage/view/blockly/blocks/trade/markets.js

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,43 +7,42 @@ import { BlocklyError } from '../../../../../common/error';
77
export default () => {
88
const symbolNames = bot.symbol.activeSymbols.getSymbolNames();
99
for (const symbol of Object.keys(symbolNames)) {
10-
Blockly.Blocks[symbol.toLowerCase()] = {
11-
init: function init() {
12-
this.appendDummyInput()
13-
.appendField(symbolNames[symbol]);
14-
this.appendDummyInput()
15-
.appendField(`${translator.translateText('Accepts')}: (${
16-
bot.symbol.getAllowedCategoryNames(symbol)})`);
17-
this.appendStatementInput('CONDITION')
18-
.setCheck('Condition');
19-
this.setInputsInline(false);
20-
this.setPreviousStatement(true, null);
21-
this.setColour('#f2f2f2');
22-
this.setTooltip(`${translator.translateText('Chooses the symbol:')} ${symbolNames[symbol]}`); // eslint-disable-line max-len
23-
this.setHelpUrl('https://github.com/binary-com/binary-bot/wiki');
24-
},
25-
onchange: function onchange(ev) {
26-
submarket(this, ev);
27-
},
28-
};
29-
}
30-
31-
for (const symbol of Object.keys(symbolNames)) {
32-
Blockly.JavaScript[symbol.toLowerCase()] = function market(block) {
33-
const condition = Blockly.JavaScript.statementToCode(block, 'CONDITION');
34-
if (!condition) {
35-
return new BlocklyError(
36-
translator.translateText('A trade type has to be defined for the symbol')).emit();
37-
}
38-
const code = `
10+
const allowedCategories = bot.symbol.getAllowedCategoryNames(symbol);
11+
if (allowedCategories.length) {
12+
Blockly.Blocks[symbol.toLowerCase()] = {
13+
init: function init() {
14+
this.appendDummyInput()
15+
.appendField(symbolNames[symbol]);
16+
this.appendDummyInput()
17+
.appendField(`${translator.translateText('Accepts')}: (${allowedCategories})`);
18+
this.appendStatementInput('CONDITION')
19+
.setCheck('Condition');
20+
this.setInputsInline(false);
21+
this.setPreviousStatement(true, null);
22+
this.setColour('#f2f2f2');
23+
this.setTooltip(`${translator.translateText('Chooses the symbol:')} ${symbolNames[symbol]}`); // eslint-disable-line max-len
24+
this.setHelpUrl('https://github.com/binary-com/binary-bot/wiki');
25+
},
26+
onchange: function onchange(ev) {
27+
submarket(this, ev);
28+
},
29+
};
30+
Blockly.JavaScript[symbol.toLowerCase()] = function market(block) {
31+
const condition = Blockly.JavaScript.statementToCode(block, 'CONDITION');
32+
if (!condition) {
33+
return new BlocklyError(
34+
translator.translateText('A trade type has to be defined for the symbol')).emit();
35+
}
36+
const code = `
3937
getTradeOptions = function getTradeOptions() {
4038
var tradeOptions = {};
4139
tradeOptions = ${condition.trim()};
4240
tradeOptions.symbol = '${symbol}'
4341
return tradeOptions;
4442
};
4543
`;
46-
return code;
47-
};
44+
return code;
45+
};
46+
}
4847
}
4948
};

src/botPage/view/blockly/index.js

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,26 @@ const cleanUp = (newBlocks) => {
6666
Blockly.mainWorkspace.resizeContents();
6767
};
6868

69+
const createXmlTag = (obj) => {
70+
let xmlStr = '<category name="Markets" colour="#2a3052" i18n-text="Markets">\n';
71+
for (const market of Object.keys(obj)) {
72+
xmlStr += `\t<category name="${obj[market].name}" colour="#2a3052">`;
73+
for (const submarket of Object.keys(obj[market].submarkets)) {
74+
xmlStr += `\t\t<category name="${
75+
obj[market].submarkets[submarket].name}" colour="#2a3052">`;
76+
for (const symbol of Object.keys(obj[market].submarkets[submarket].symbols)) {
77+
if (bot.symbol.getAllowedCategoryNames(symbol).length) {
78+
xmlStr += `\t\t\t<block type="${symbol.toLowerCase()}"></block>`;
79+
}
80+
}
81+
xmlStr += '\t\t</category>\n';
82+
}
83+
xmlStr += '\t</category>\n';
84+
}
85+
xmlStr += '</category>\n';
86+
return xmlStr;
87+
};
88+
6989
export default class _Blockly {
7090
constructor() {
7191
this.blocksXmlStr = '';
@@ -106,30 +126,13 @@ export default class _Blockly {
106126
cleanUp() {
107127
Blockly.mainWorkspace.cleanUp();
108128
}
109-
createXmlTag(obj) {
110-
let xmlStr = '<category name="Markets" colour="#2a3052" i18n-text="Markets">\n';
111-
for (const market of Object.keys(obj)) {
112-
xmlStr += `\t<category name="${obj[market].name}" colour="#2a3052">`;
113-
for (const submarket of Object.keys(obj[market].submarkets)) {
114-
xmlStr += `\t\t<category name="${
115-
obj[market].submarkets[submarket].name}" colour="#2a3052">`;
116-
for (const symbol of Object.keys(obj[market].submarkets[submarket].symbols)) {
117-
xmlStr += `\t\t\t<block type="${symbol.toLowerCase()}"></block>`;
118-
}
119-
xmlStr += '\t\t</category>\n';
120-
}
121-
xmlStr += '\t</category>\n';
122-
}
123-
xmlStr += '</category>\n';
124-
return xmlStr;
125-
}
126129
xmlToStr(xml) {
127130
const serializer = new XMLSerializer();
128131
return serializer.serializeToString(xml);
129132
}
130133
marketsToXml(xml) {
131134
const xmlStr = this.xmlToStr(xml);
132-
const marketXml = this.createXmlTag(
135+
const marketXml = createXmlTag(
133136
bot.symbol.activeSymbols.getMarkets(), bot.symbol.assetIndex);
134137
return xmlStr.replace('<!--Markets-->', marketXml);
135138
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy