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
322c2af
added 2 new blocks for date/time conversion
Jun 4, 2019
4b35fb0
fix for time conversion blocks
Jun 4, 2019
6c161f4
fix for error messages
Jun 11, 2019
825cd7e
tooltip-misalignment
Jun 11, 2019
4756300
Merge branch 'dev' into tooltip-misalignment
sam-binary Jun 11, 2019
4fe495d
added tests
Jun 11, 2019
a82e899
fixes following code review suggestions
Jun 12, 2019
ee5ab2e
fix extra space between rectangle and narrow
Jun 12, 2019
eaa364a
fix space between triangle & box
Jun 12, 2019
3705eb0
fix space between triangle & textbox
Jun 12, 2019
697054c
fix space between triangle and box
Jun 12, 2019
9efa44a
fixed tests
Jun 12, 2019
c60f91d
The play() request was interrupted by a call to pause().
Jun 12, 2019
44f87f1
Merge branch 'dev' into trackjs-audio
sam-binary Jun 12, 2019
b3cc10c
disable trackjs for non-production domain
Jun 12, 2019
74ff06d
Merge branch 'dev' into illegal-break-statement
sam-binary Jun 12, 2019
60e76f7
fix for timezone issue in tests
Jun 12, 2019
2d4bd0c
Merge branch 'dev' into dev
Jun 12, 2019
c58d78a
Merge pull request #1589 from sam-binary/trackjs-audio
ashkanx Jun 13, 2019
b22b46d
Merge branch 'dev' into illegal-break-statement
ashkanx Jun 13, 2019
d07695c
Merge pull request #1590 from sam-binary/illegal-break-statement
ashkanx Jun 13, 2019
9478391
Merge branch 'dev' into tooltip-misalignment
ashkanx Jun 13, 2019
d4d8587
Merge pull request #1587 from sam-binary/tooltip-misalignment
ashkanx Jun 13, 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
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
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
2 changes: 1 addition & 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
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);
};
18 changes: 14 additions & 4 deletions src/botPage/view/View.js
Original file line number Diff line number Diff line change
Expand Up @@ -511,9 +511,11 @@ export default class View {
});

const startBot = limitations => {
$('#stopButton, #summaryStopButton').show();
$('#runButton, #summaryRunButton').hide();
$('#runButton, #summaryRunButton').prop('disabled', true);
const $runButtons = $('#runButton, #summaryRunButton');
const $stopButtons = $('#stopButton, #summaryStopButton');
$stopButtons.show();
$runButtons.hide();
$runButtons.prop('disabled', true);
globalObserver.emit('summary.disable_clear');
showSummary();
this.blockly.run(limitations);
Expand Down Expand Up @@ -641,7 +643,15 @@ export default class View {
});

globalObserver.register('bot.stop', () => {
$('#runButton, #summaryRunButton').prop('disabled', false);
const $runButtons = $('#runButton, #summaryRunButton');
const $stopButtons = $('#stopButton, #summaryStopButton');
if ($runButtons.is(':visible') || $stopButtons.is(':visible')) {
$runButtons.show();
$stopButtons.hide();

$stopButtons.prop('disabled', false);
$runButtons.prop('disabled', false);
}
});

globalObserver.register('bot.info', info => {
Expand Down
4 changes: 4 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,7 @@ export const getPredictionForContracts = (contracts, selectedContractType) => {
}
return predictionRange;
};

export const disableRunButton = isDisabled => {
$('#runButton, #summaryRunButton').attr('disabled', isDisabled);
};
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];
};
30 changes: 30 additions & 0 deletions src/botPage/view/blockly/blocks/tools/time/totimestamp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { translate } from '../../../../../../common/i18n';

Blockly.Blocks.totimestamp = {
init: function init() {
this.appendDummyInput();
this.appendValueInput('DATETIME').appendField(translate('To Timestamp'));
this.setInputsInline(true);
this.setOutput(true, 'Number');
this.setColour('#dedede');
this.setTooltip(
translate(
'Converts a string representing a date/time string into seconds since Epoch. Example: 2019-01-01 21:03:45 GMT+0800 will be converted to 1546347825. Time and time zone offset are optional.'
)
);
},
};

Blockly.JavaScript.totimestamp = block => {
const dateString = Blockly.JavaScript.valueToCode(block, 'DATETIME', Blockly.JavaScript.ORDER_ATOMIC);
// eslint-disable-next-line no-underscore-dangle
const functionName = Blockly.JavaScript.provideFunction_('dateTimeStringToTimestamp', [
// eslint-disable-next-line no-underscore-dangle
`function ${Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_}(dateTimeString) {
return Bot.toTimestamp(dateTimeString);
}`,
]);

const code = `${functionName}(${dateString})`;
return [code, Blockly.JavaScript.ORDER_FUNCTION_CALL];
};
16 changes: 12 additions & 4 deletions src/botPage/view/blockly/blocks/trade/tradeOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
getDurationsForContracts,
getBarriersForContracts,
getPredictionForContracts,
disableRunButton,
} from '../shared';
import { insideTrade } from '../../relationChecker';
import { findTopParentBlock, hideInteractionsFromBlockly, getBlocksByType } from '../../utils';
Expand Down Expand Up @@ -102,33 +103,40 @@ export default () => {
}
},
pollForContracts(symbol) {
disableRunButton(true);
return new Promise(resolve => {
const contractsForSymbol = haveContractsForSymbol(symbol);

const resolveContracts = resolveObj => {
disableRunButton(false);
resolve(resolveObj);
};

if (!contractsForSymbol) {
// Register an event and use as a lock to avoid spamming API
const event = `contractsLoaded.${symbol}`;
if (!globalObserver.isRegistered(event)) {
globalObserver.register(event, () => {});
getContractsAvailableForSymbol(symbol).then(contracts => {
globalObserver.unregisterAll(event); // Release the lock
resolve(contracts);
resolveContracts(contracts);
});
} else {
// Request in progress, start polling localStorage until contracts are available.
const pollingFn = setInterval(() => {
const contracts = haveContractsForSymbol(symbol);
if (contracts) {
clearInterval(pollingFn);
resolve(contracts.available);
resolveContracts(contracts.available);
}
}, 100);
setTimeout(() => {
clearInterval(pollingFn);
resolve([]);
resolveContracts([]);
}, 10000);
}
} else {
resolve(contractsForSymbol.available);
resolveContracts(contractsForSymbol.available);
}
});
},
Expand Down
Loading