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
Show all changes
87 commits
Select commit Hold shift + click to select a range
845ce97
Remove sellExpired()
May 30, 2019
545d731
Merge pull request #1556 from binary-com/dev
ashkanx May 30, 2019
322c2af
added 2 new blocks for date/time conversion
Jun 4, 2019
4b35fb0
fix for time conversion blocks
Jun 4, 2019
571829a
Merge pull request #1567 from binary-com/dev
ashkanx Jun 7, 2019
6c161f4
fix for error messages
Jun 11, 2019
4fe495d
added tests
Jun 11, 2019
76957df
Merge pull request #1584 from binary-com/dev
ashkanx Jun 11, 2019
a82e899
fixes following code review suggestions
Jun 12, 2019
9efa44a
fixed tests
Jun 12, 2019
60e76f7
fix for timezone issue in tests
Jun 12, 2019
2d4bd0c
Merge branch 'dev' into dev
Jun 12, 2019
2e3f587
fix trackjs-missing contract required parameters
Jun 14, 2019
662caa2
Merge branch 'dev' into missing-contract-parameter
sam-binary Jun 14, 2019
fac2c55
GMT offset added, input validation refactored
Jun 15, 2019
e2b3dc0
toolbox width adjusted
anton-binary Jun 16, 2019
8caf1eb
resolved run button enabled after market type changed when the contra…
Jun 17, 2019
ca8ac3b
Merge branch 'missing-contract-parameter' of https://github.com/sam-b…
Jun 17, 2019
27f11c1
+ Download Context Menu for 'Variables' & 'Loops' blocks
Jun 17, 2019
9a94ea6
Merge branch 'dev' into download-support-variables-loops
sam-binary Jun 18, 2019
dad1a72
Change contract detail data type from string to number
Jun 18, 2019
7c1084c
Merge branch 'dev' into dev
sam-binary Jun 18, 2019
7296aac
npm test issue
Jun 18, 2019
10a0aac
restart travis
Jun 18, 2019
77a49a9
Merge branch 'dev' into datetime-blocks
Jun 20, 2019
84c460c
resolve changes
Jun 20, 2019
9f31d69
delete non-use function
Jun 20, 2019
0e89265
Merge pull request #1610 from sam-binary/dev
Jun 20, 2019
a5a6fe0
Merge branch 'dev' into datetime-blocks
Jun 20, 2019
dfa829d
Merge branch 'dev' into toolbox-width
Jun 20, 2019
7616cf8
npm test
Jun 20, 2019
c3afc00
Update src/botPage/view/View.js
sam-binary Jun 20, 2019
81da451
Update src/botPage/view/View.js
sam-binary Jun 20, 2019
4cdbc6e
Merge branch 'dev' into missing-contract-parameter
sam-binary Jun 20, 2019
0cc5c77
var error
Jun 20, 2019
0331c76
xml error
Jun 20, 2019
0688fcc
resolve changes
Jun 20, 2019
8e0daeb
Merge branch 'dev' into download-support-variables-loops
sam-binary Jun 20, 2019
3ace537
Update static/css/_blockly-toolbox.scss
anton-binary Jun 21, 2019
d670ca5
fixed safari bugs and date/time validation
anton-binary Jun 23, 2019
dd57fa1
resolve issues by QA
Jun 24, 2019
9a26387
Merge branch 'dev' into xml-error
sam-binary Jun 24, 2019
f31771d
fixed date object validation
anton-binary Jun 24, 2019
84ff2c5
removed comments
anton-binary Jun 24, 2019
d3b2699
Merge pull request #1595 from sam-binary/missing-contract-parameter
Jun 25, 2019
21a97c0
Merge branch 'dev' into download-support-variables-loops
Jun 25, 2019
20001e7
resolve xxs attack
Jun 26, 2019
ba04cd3
eslint
Jun 26, 2019
6474901
Merge pull request #1607 from sam-binary/download-support-variables-l…
Jun 26, 2019
4dbf2a3
resolve changes
Jun 26, 2019
358e93b
eslint
Jun 26, 2019
ae3f3c5
Merge branch 'dev' into xxs-attack
sam-binary Jun 26, 2019
d0276a2
regex
Jun 26, 2019
adfd1a3
copywriters
Jun 26, 2019
b783436
Merge branch 'dev' into remove-sell-expired
Jun 27, 2019
300c6d6
Merge pull request #1631 from sam-binary/xxs-attack
Jun 27, 2019
e179a45
added more flexible validation
anton-binary Jun 27, 2019
47d1bf0
resolve changes
Jun 27, 2019
c31b133
eslint & resolve changes
Jun 27, 2019
6d3898d
Merge branch 'dev' into xml-error
sam-binary Jun 27, 2019
2992b40
trim spaces in the beginning/end of date-time string
anton-binary Jun 27, 2019
b3a4b47
Merge branch 'dev' into remove-sell-expired
Jun 27, 2019
0026b7a
Merge branch 'dev' into datetime-blocks
Jul 1, 2019
4a27232
Merge pull request #1620 from sam-binary/xml-error
Jul 1, 2019
c905570
Merge branch 'dev' into toolbox-width
Jul 1, 2019
c61c1ad
Merge branch 'dev' into remove-sell-expired
Jul 1, 2019
a920392
Merge branch 'dev' into datetime-blocks
Jul 1, 2019
a001a1e
Merge pull request #1604 from anton-binary/toolbox-width
Jul 1, 2019
c1acf3f
Merge branch 'dev' into remove-sell-expired
Jul 1, 2019
745cf92
Merge branch 'dev' into datetime-blocks
Jul 1, 2019
112d172
Merge pull request #1600 from anton-binary/datetime-blocks
Jul 1, 2019
a1826f8
Merge branch 'dev' into remove-sell-expired
Jul 1, 2019
d197409
Merge pull request #1555 from aaron-binary/remove-sell-expired
Jul 1, 2019
a4a5404
Set stale.yml config
Jul 2, 2019
b4daee6
Merge pull request #1649 from aaron-binary/stale-bot
Jul 3, 2019
b3d98f9
Merge pull request #1658 from binary-com/dev
ashkanx Jul 3, 2019
e0022d9
Keep track of bot is_running status globally
Jul 9, 2019
4527c2d
Ensure correct button status
Jul 9, 2019
f5cc80c
Refactor disableRunButton function
Jul 9, 2019
280a902
Restore display on stopBeforeStart
Jul 9, 2019
e550184
Convert everything to camelCase
Jul 9, 2019
b603e31
Don't manipulate passed argument directly
Jul 9, 2019
481305d
Set #summaryStopButton to display: none by default
Jul 9, 2019
a2c8001
Be consistent in display values
Jul 9, 2019
a62ebca
Create global state in observer
Jul 9, 2019
dd6b3c0
Merge pull request #1719 from aaron-binary/running-indicator-for-beta
ashkanx Jul 18, 2019
f13e3fc
Merge branch 'master' into beta
ashkanx Jul 18, 2019
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
24 changes: 24 additions & 0 deletions .github/stale.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Configuration for probot-stale - https://github.com/probot/stale

# Limit to only `issues`
only: issues

# Number of days of inactivity before an Issue or Pull Request is closed.
# Set to false to disable. If disabled, issues still need to be closed manually, but will remain marked as stale.
daysUntilClose: 14

# Issues or Pull Requests with these labels will never be considered stale. Set to `[]` to disable
exemptLabels:
- bug
- "technical issues"

# Comment to post when marking as stale. Set to `false` to disable
markComment: false

# Comment to post when closing a stale Issue or Pull Request.
closeComment: >
This issue has been automatically closed since there has not been
any recent activity. Please open a new issue for related bugs.

# Limit the number of actions per hour, from 1-30. Default is 30
limitPerRun: 30
67 changes: 66 additions & 1 deletion src/botPage/bot/Interface/ToolsInterface.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,78 @@
import CandleInterface from './CandleInterface';
import MiscInterface from './MiscInterface';
import IndicatorsInterface from './IndicatorsInterface';
import { translate } from '../../../common/i18n';

// prettier-ignore
export default Interface => class extends IndicatorsInterface(
MiscInterface(CandleInterface(Interface))) {
getToolsInterface() {
return {
getTime: () => parseInt(new Date().getTime() / 1000),
getTime : () => parseInt(new Date().getTime() / 1000),
toDateTime: (timestamp) => {
const getTwoDigitValue = input => {
if (input < 10) {
return `0${input}`;
}
return `${input}`;
}
const invalidTimestamp = () => `${translate('Invalid timestamp')}: ${timestamp}`;
if (typeof timestamp === 'number') {
const dateTime = new Date(timestamp * 1000);
if (dateTime.getTime()) {
const year = dateTime.getFullYear();
const month = getTwoDigitValue(dateTime.getMonth() + 1);
const day = getTwoDigitValue(dateTime.getDate());
const hours = getTwoDigitValue(dateTime.getHours());
const minutes = getTwoDigitValue(dateTime.getMinutes());
const seconds = getTwoDigitValue(dateTime.getSeconds());
const formatGTMoffset = () => {
const GMToffsetRaw = dateTime.getTimezoneOffset();
const sign = GMToffsetRaw > 0 ? '-' : '+';
const GMToffset = Math.abs(GMToffsetRaw);
const h = Math.floor(GMToffset / 60);
const m = GMToffset - h * 60;
return `GMT${sign}${getTwoDigitValue(h)}${getTwoDigitValue(m)}`;
}
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds} ${formatGTMoffset()}`;
}
return invalidTimestamp();
}
return invalidTimestamp();
},
toTimestamp: (dateTimeString) => {
const invalidDatetime = () => `${translate('Invalid date/time')}: ${dateTimeString}`;
if (typeof dateTimeString === 'string') {
const dateTime = dateTimeString
.replace(/[^0-9.:-\s]/g, '')
.replace(/\s+/g,' ')
.trim()
.split(' ');

const d = /^[12]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/;
const t = /^(0[0-9]|1[0-9]|2[0-3]):([0-5][0-9])(:([0-5][0-9])?)?$/;

let validatedDateTime;

if(dateTime.length >= 2) {
validatedDateTime = d.test(dateTime[0]) && t.test(dateTime[1]) ? `${dateTime[0]}T${dateTime[1]}` : null;
} else if(dateTime.length === 1) {
validatedDateTime = d.test(dateTime[0]) ? dateTime[0] : null;
} else {
validatedDateTime = null;
}

if(validatedDateTime) {
const dateObj = new Date(validatedDateTime);
// eslint-disable-next-line no-restricted-globals
if(dateObj instanceof Date && !isNaN(dateObj)) {
return dateObj.getTime() / 1000;
}
}
return invalidDatetime();
}
return invalidDatetime();
},
...this.getCandleInterface(),
...this.getMiscInterface(),
...this.getIndicatorsInterface(),
Expand Down
4 changes: 3 additions & 1 deletion src/botPage/bot/Interpreter.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,10 @@ export default class Interpreter {
}
terminateSession() {
this.$scope.api.disconnect();
globalObserver.emit('bot.stop');
this.stopped = true;

globalObserver.emit('bot.stop');
globalObserver.setState({ isRunning: false });
}
stop() {
if (this.bot.tradeEngine.isSold === false && !this.isErrorTriggered) {
Expand Down
9 changes: 1 addition & 8 deletions src/botPage/bot/TradeEngine/OpenContract.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ export default Engine =>

this.setContractFlags(contract);

this.sellExpired();

this.data = this.data.set('contract', contract);

broadcastContract({ accountID: this.accountInfo.loginid, ...contract });
Expand All @@ -45,11 +43,7 @@ export default Engine =>
this.store.dispatch(openContractReceived());
if (!this.isExpired) {
this.resetSubscriptionTimeout();
return;
}
if (!this.retriedUnsuccessfullSellExpired) {
this.retriedUnsuccessfullSellExpired = true;
this.resetSubscriptionTimeout(AFTER_FINISH_TIMEOUT);

}
}
});
Expand All @@ -61,7 +55,6 @@ export default Engine =>
}
subscribeToOpenContract(contractId = this.contractId) {
if (this.contractId !== contractId) {
this.retriedUnsuccessfullSellExpired = false;
this.resetSubscriptionTimeout();
}
this.contractId = contractId;
Expand Down
5 changes: 0 additions & 5 deletions src/botPage/bot/TradeEngine/Sell.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,4 @@ export default Engine =>
delayIndex++
).then(onSuccess);
}
sellExpired() {
if (this.isSellAvailable && this.isExpired) {
doUntilDone(() => this.api.sellExpiredContracts());
}
}
};
2 changes: 1 addition & 1 deletion src/botPage/bot/TradeEngine/Total.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { translate } from '../../../common/i18n';
import { roundBalance } from '../../common/tools';
import { info, notify } from '../broadcast';
import createError from '../../common/error';
import { createError } from '../../common/error';
import { observer as globalObserver } from '../../../common/utils/observer';

const skeleton = {
Expand Down
3 changes: 2 additions & 1 deletion src/botPage/bot/TradeEngine/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createStore, applyMiddleware } from 'redux';
import thunk from 'redux-thunk';
import { durationToSecond } from '../../../common/utils/tools';
import { translate } from '../../..//common/i18n';
import createError from '../../common/error';
import { createError } from '../../common/error';
import { doUntilDone } from '../tools';
import { expectInitArg, expectTradeOptions } from '../sanitize';
import Proposal from './Proposal';
Expand Down Expand Up @@ -92,6 +92,7 @@ export default class TradeEngine extends Balance(Purchase(Sell(OpenContract(Prop
}

globalObserver.emit('bot.running');
globalObserver.setState({ isRunning: true });

this.tradeOptions = expectTradeOptions(tradeOptions);

Expand Down
2 changes: 1 addition & 1 deletion src/botPage/bot/__tests__/block-tests/After.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('After Purchase Blocks', () => {
it('After purchase api', () => {
expectResultTypes(result, [
'boolean', // is result win
'string', // statement
'number', // statement
]);
});
});
14 changes: 14 additions & 0 deletions src/botPage/bot/__tests__/block-tests/tools-test/Time.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,17 @@ describe('Time in tools', () => {
expect(time2 - time1).most(3);
});
});

describe('Convert timestamp to date/time and back', () => {
const timestamp = Math.ceil(new Date().getTime() / 1000);
let result;
beforeAll(done => {
run(`(function() {return Bot.toTimestamp(Bot.toDateTime(${timestamp}));})()`).then(v => {
result = v;
done();
});
});
it('converts timestamp to date/time string', () => {
expect(result).satisfy(dt => dt === timestamp);
});
});
2 changes: 1 addition & 1 deletion src/botPage/bot/sanitize.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { translate } from '../../common/i18n';
import createError from '../common/error';
import { createError } from '../common/error';

const isPositiveNumber = num => Number.isFinite(num) && num > 0;

Expand Down
10 changes: 8 additions & 2 deletions src/botPage/common/error.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
const createError = (name, message) => {
import { observer as globalObserver } from '../../common/utils/observer';
import { translate } from '../../common/i18n';

export const createError = (name, message) => {
const e = new Error(message);
e.name = name;
return e;
};

export default createError;
export const createErrorAndEmit = (name, message) => {
globalObserver.emit('ui.log.warn', `${translate(message)}`);
return createError(name, message);
};
51 changes: 46 additions & 5 deletions src/botPage/view/View.js
Original file line number Diff line number Diff line change
Expand Up @@ -511,9 +511,19 @@ export default class View {
});

const startBot = limitations => {
$('#stopButton, #summaryStopButton').show();
$('#runButton, #summaryRunButton').hide();
$('#runButton, #summaryRunButton').prop('disabled', true);
const elRunButtons = document.querySelectorAll('#runButton, #summaryRunButton');
const elStopButtons = document.querySelectorAll('#stopButton, #summaryStopButton');

elRunButtons.forEach(el => {
const elRunButton = el;
elRunButton.style.display = 'none';
elRunButton.setAttributeNode(document.createAttribute('disabled'));
});
elStopButtons.forEach(el => {
const elStopButton = el;
elStopButton.style.display = 'inline-block';
});

globalObserver.emit('summary.disable_clear');
showSummary();
this.blockly.run(limitations);
Expand Down Expand Up @@ -625,23 +635,54 @@ export default class View {
this.blockly.stop();
}
addEventHandlers() {
const getRunButtonElements = () => document.querySelectorAll('#runButton, #summaryRunButton');
const getStopButtonElements = () => document.querySelectorAll('#stopButton, #summaryStopButton');

window.addEventListener('storage', e => {
window.onbeforeunload = null;
if (e.key === 'activeToken' && !e.newValue) window.location.reload();
if (e.key === 'realityCheckTime') hideRealityCheck();
});

globalObserver.register('Error', error => {
$('#runButton, #summaryRunButton').prop('disabled', false);
getRunButtonElements().forEach(el => {
const elRunButton = el;
elRunButton.removeAttribute('disabled');
});

if (error.error && error.error.error.code === 'InvalidToken') {
removeAllTokens();
updateTokenList();
this.stop();
}
});

globalObserver.register('bot.running', () => {
getRunButtonElements().forEach(el => {
const elRunButton = el;
elRunButton.style.display = 'none';
elRunButton.setAttributeNode(document.createAttribute('disabled'));
});
getStopButtonElements().forEach(el => {
const elStopButton = el;
elStopButton.style.display = 'inline-block';
elStopButton.removeAttribute('disabled');
});
});

globalObserver.register('bot.stop', () => {
$('#runButton, #summaryRunButton').prop('disabled', false);
// Enable run button, this event is emitted after the interpreter
// killed the API connection.
getStopButtonElements().forEach(el => {
const elStopButton = el;
elStopButton.style.display = null;
elStopButton.removeAttribute('disabled');
});
getRunButtonElements().forEach(el => {
const elRunButton = el;
elRunButton.style.display = null;
elRunButton.removeAttribute('disabled');
});
});

globalObserver.register('bot.info', info => {
Expand Down
19 changes: 19 additions & 0 deletions src/botPage/view/blockly/blocks/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -409,3 +409,22 @@ export const getPredictionForContracts = (contracts, selectedContractType) => {
}
return predictionRange;
};

export const disableRunButton = shouldDisable => {
const elRunButtons = document.querySelectorAll('#runButton, #summaryRunButton');
const isRunning = globalObserver.getState('isRunning');

elRunButtons.forEach(elRunButton => {
if (isRunning) {
if (shouldDisable) {
elRunButton.setAttributeNode(document.createAttribute('disabled'));
} else {
// Do not enable. The bot is running.
}
} else if (shouldDisable) {
elRunButton.setAttributeNode(document.createAttribute('disabled'));
} else {
elRunButton.removeAttribute('disabled');
}
});
};
2 changes: 2 additions & 0 deletions src/botPage/view/blockly/blocks/tools/time/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import './epoch';
import './timeout';
import './interval';
import './todatetime';
import './totimestamp';
30 changes: 30 additions & 0 deletions src/botPage/view/blockly/blocks/tools/time/todatetime.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { translate } from '../../../../../../common/i18n';

Blockly.Blocks.todatetime = {
init: function init() {
this.appendDummyInput();
this.appendValueInput('TIMESTAMP').appendField(translate('To Date/Time'));
this.setInputsInline(true);
this.setOutput(true, 'String');
this.setColour('#dedede');
this.setTooltip(
translate(
'Converts a number of seconds since Epoch into a string representing date and time. Example: 1546347825 will be converted to 2019-01-01 21:03:45.'
)
);
},
};

Blockly.JavaScript.todatetime = block => {
const timestamp = Blockly.JavaScript.valueToCode(block, 'TIMESTAMP', Blockly.JavaScript.ORDER_ATOMIC);
// eslint-disable-next-line no-underscore-dangle
const functionName = Blockly.JavaScript.provideFunction_('timestampToDateString', [
// eslint-disable-next-line no-underscore-dangle
`function ${Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_}(timestamp) {
return Bot.toDateTime(timestamp);
}`,
]);

const code = `${functionName}(${timestamp})`;
return [code, Blockly.JavaScript.ORDER_FUNCTION_CALL];
};
Loading