Skip to content
This repository was archived by the owner on Feb 22, 2024. It is now read-only.
Open
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
5 changes: 3 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"parser": "babel-eslint",
"parser": "@babel/eslint-parser",
"parserOptions": {
"ecmaFeatures": {
"jsx": true
}
},
"requireConfigFile": false
},
"extends": [
"binary",
Expand Down
13,331 changes: 8,693 additions & 4,638 deletions package-lock.json

Large diffs are not rendered by default.

95 changes: 49 additions & 46 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,88 +35,91 @@
"author": "Binary.com",
"license": "MIT",
"devDependencies": {
"@babel/cli": "^7.4.4",
"@babel/core": "^7.4.4",
"@babel/plugin-proposal-class-properties": "^7.4.4",
"@babel/plugin-proposal-object-rest-spread": "^7.4.4",
"@babel/cli": "^7.16.7",
"@babel/core": "^7.16.7",
"@babel/eslint-parser": "^7.16.5",
"@babel/plugin-proposal-class-properties": "^7.16.7",
"@babel/plugin-proposal-object-rest-spread": "^7.16.7",
"@babel/polyfill": "^7.4.4",
"@babel/preset-env": "^7.4.4",
"@babel/preset-react": "^7.0.0",
"@babel/register": "^7.4.4",
"@babel/preset-env": "^7.16.7",
"@babel/preset-react": "^7.16.7",
"@babel/register": "^7.16.7",
"@binary-com/binary-indicators": "^1.6.3",
"app-module-path": "^2.2.0",
"babel-core": "^7.0.0-bridge.0",
"babel-core": "^6.26.3",
"babel-eslint": "^10.0.1",
"babel-jest": "^24.8.0",
"babel-loader": "^8.0.6",
"babel-jest": "^27.4.6",
"babel-loader": "^8.2.3",
"binary-live-api": "^29.0.1",
"binary-utils": "^4.23.0",
"chai": "^4.1.2",
"coveralls": "^3.0.3",
"deep-diff": "^1.0.2",
"del": "^4.1.1",
"es6-plato": "^1.2.2",
"eslint": "^4.14.0",
"eslint-config-airbnb": "^16.1.0",
"eslint": "^8.6.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-binary": "^1.0.2",
"eslint-config-prettier": "^2.9.0",
"eslint-plugin-import": "^2.8.0",
"eslint-plugin-jsx-a11y": "^6.0.3",
"eslint-plugin-react": "^7.5.1",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-jsx-a11y": "^6.5.1",
"eslint-plugin-react": "^7.28.0",
"file-saver": "^2.0.2",
"gulp": "^4.0.2",
"gulp-clean-css": "^4.2.0",
"gulp-clean-css": "^4.3.0",
"gulp-concat-css": "^3.1.0",
"gulp-concat-util": "^0.5.5",
"gulp-connect": "^5.0.0",
"gulp-mustache": "^4.1.1",
"gulp-connect": "^5.7.0",
"gulp-mustache": "^5.0.0",
"gulp-open": "^3.0.1",
"gulp-remote-src": "^0.4.4",
"gulp-rename": "^1.2.2",
"gulp-rename": "^2.0.0",
"gulp-rev": "^9.0.0",
"gulp-sass": "^4.0.2",
"gulp-sourcemaps": "^2.6.5",
"gulp-sourcemaps": "^3.0.0",
"gulp-watch": "^5.0.1",
"husky": "^2.3.0",
"husky": "^7.0.4",
"i18next-scanner": "^2.9.2",
"immutable": "^3.8.2",
"jest": "^24.8.0",
"jquery": "^3.5.1",
"jquery-ui": "1.12.1",
"jquery-ui-css": "1.11.4",
"js-interpreter": "2.2.0",
"json2csv": "^3.11.5",
"lint-staged": "^8.1.7",
"loader-utils": "^1.1.0",
"immutable": "^4.0.0",
"jest": "^27.4.6",
"jquery": "^3.6.0",
"jquery-ui": "^1.13.0",
"jquery-ui-css": "^1.11.4",
"js-interpreter": "^2.3.1",
"json2csv": "^5.0.6",
"lint-staged": "^12.1.5",
"loader-utils": "^3.2.0",
"notify-browser": "0.0.5",
"notifyjs-browser": "^0.4.2",
"prettier-eslint-cli": "^4.7.0",
"prop-types": "^15.7.2",
"prop-types": "^15.8.1",
"react": "^16.8.6",
"react-data-grid": "^3.0.0",
"react-dom": "^16.8.6",
"react-joyride": "^1.11.1",
"redux": "^4.0.1",
"redux-thunk": "^2.2.0",
"react-joyride": "^1.11.4",
"redux": "^4.1.2",
"redux-thunk": "^2.4.1",
"sha1": "^1.1.1",
"trackjs": "^2.10.2",
"trackjs": "^2.13.0",
"vinyl-paths": "^2.1.0",
"webpack": "^3.10.0",
"webpack-stream": "^4.0.0"
"webpack": "^3.12.0",
"webpack-cli": "^4.9.1",
"webpack-stream": "^4.0.3"
},
"dependencies": {
"@deriv/deriv-charts": "0.3.16",
"binary-style": "^0.2.4",
"blockly": "github:binary-com/blockly#fix-blockly",
"commander": "^2.20.0",
"commander": "^8.3.0",
"concat-stream": "^2.0.0",
"core-js": "^2.6.5",
"crc-32": "^1.2.0",
"gh-pages": "^2.0.1",
"js-cookie": "^2.2.1",
"mobx": "^5.9.4",
"mobx-react": "^5.4.4",
"pako": "^1.0.11",
"gh-pages": "^3.2.3",
"js-cookie": "^3.0.1",
"mobx": "^6.3.10",
"mobx-react": "^7.2.1",
"pako": "^2.0.4",
"react-render-html": "^0.6.0",
"react-transition-group": "^4.0.1",
"@deriv/deriv-charts": "0.3.16"
"react-transition-group": "^4.0.1"
}
}
2 changes: 2 additions & 0 deletions src/botPage/bot/CliTools.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/* eslint-disable */
import Observer from '../../common/utils/observer';
import Interpreter from './Interpreter';
import TicksService from '../common/TicksService';
import { generateLiveApiInstance } from '../../common/appId';
/* eslint-enable */

export const createScope = () => {
const observer = new Observer();
Expand Down
1 change: 1 addition & 0 deletions src/botPage/bot/Interface/IndicatorsInterface.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default Interface =>
macda: (input, config, field) => this.decorate(macda, input, config).map(r => r[field]),
};
}

decorate(f, input, config, ...args) {
const pipSize = this.tradeEngine.getPipSize();

Expand Down
9 changes: 9 additions & 0 deletions src/botPage/bot/Interface/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
/* eslint-disable */
import TradeEngine from '../TradeEngine';
import { noop, createDetails } from '../tools';
import TicksInterface from './TicksInterface';
import ToolsInterface from './ToolsInterface';
/* eslint-enable */

/**
* Bot - Bot Module
* @namespace Bot
*/

/* eslint-disable no-promise-executor-return */
export default class Interface extends ToolsInterface(TicksInterface(class {})) {
constructor($scope) {
super();
Expand All @@ -16,6 +19,7 @@ export default class Interface extends ToolsInterface(TicksInterface(class {}))
this.observer = $scope.observer;
this.$scope = $scope;
}

getInterface(name = 'Global') {
if (name === 'Bot') {
return {
Expand All @@ -36,6 +40,7 @@ export default class Interface extends ToolsInterface(TicksInterface(class {}))
},
};
}

getBotInterface() {
const getDetail = (i, pipSize) => createDetails(this.tradeEngine.data.contract, pipSize)[i];

Expand All @@ -54,6 +59,7 @@ export default class Interface extends ToolsInterface(TicksInterface(class {}))
readDetails : i => getDetail(i - 1, this.tradeEngine.getPipSize()),
};
}

sleep(arg = 1) {
return new Promise(
r =>
Expand All @@ -64,14 +70,17 @@ export default class Interface extends ToolsInterface(TicksInterface(class {}))
noop
);
}

getProposal(contractType) {
return this.tradeEngine.data.proposals.find(
proposal =>
proposal.contractType === contractType &&
proposal.purchaseReference === this.tradeEngine.getPurchaseReference()
);
}

getSellPrice() {
return this.tradeEngine.getSellPrice();
}
}
/* eslint-enable no-promise-executor-return */
10 changes: 10 additions & 0 deletions src/botPage/bot/Interpreter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import JSInterpreter from 'js-interpreter';
/* eslint-disable */
import { createScope } from './CliTools';
/* eslint-enable */
import Interface from './Interface';
import { clone } from '../common/clone';
import { observer as globalObserver } from '../../common/utils/observer';
Expand Down Expand Up @@ -48,6 +50,7 @@ export default class Interpreter {
constructor() {
this.init();
}

init() {
this.$scope = createScope();
this.bot = new Interface(this.$scope);
Expand All @@ -56,6 +59,7 @@ export default class Interpreter {
this.revert(watchName === 'before' ? this.beforeState : this.duringState)
);
}

run(code) {
const initFunc = (interpreter, scope) => {
const botInterface = this.bot.getInterface('Bot');
Expand Down Expand Up @@ -160,17 +164,20 @@ export default class Interpreter {
this.loop();
});
}

loop() {
if (this.stopped || !this.interpreter.run()) {
this.onFinish(this.interpreter.pseudoToNative(this.interpreter.value));
}
}

revert(state) {
this.interpreter.restoreStateSnapshot(state);
// eslint-disable-next-line no-underscore-dangle
this.interpreter.paused_ = false;
this.loop();
}

terminateSession() {
const { socket } = this.$scope.api;
if (socket.readyState === 0) {
Expand All @@ -186,6 +193,7 @@ export default class Interpreter {
globalObserver.emit('bot.stop');
globalObserver.setState({ isRunning: false });
}

stop() {
if (this.bot.tradeEngine.isSold === false && !this.isErrorTriggered) {
globalObserver.register('contract.status', contractStatus => {
Expand All @@ -198,6 +206,7 @@ export default class Interpreter {
this.terminateSession();
}
}

createAsync(interpreter, func) {
const asyncFunc = (...args) => {
const callback = args.pop();
Expand Down Expand Up @@ -225,6 +234,7 @@ export default class Interpreter {
Object.defineProperty(asyncFunc, 'length', { value: MAX_ACCEPTABLE_FUNC_ARGS + 1 });
return interpreter.createAsyncFunction(asyncFunc);
}

hasStarted() {
return !this.stopped;
}
Expand Down
1 change: 1 addition & 0 deletions src/botPage/bot/TradeEngine/Balance.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default Engine =>
info({ accountID: this.accountInfo.loginid, balance: balanceStr });
});
}

// eslint-disable-next-line class-methods-use-this
getBalance(type) {
const balance = globalObserver.getState('balance');
Expand Down
7 changes: 7 additions & 0 deletions src/botPage/bot/TradeEngine/OpenContract.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@ export default Engine =>
}
});
}

waitForAfter() {
return new Promise(resolve => {
this.afterPromise = resolve;
});
}

subscribeToOpenContract(contractId = this.contractId) {
if (this.contractId !== contractId) {
this.resetSubscriptionTimeout();
Expand All @@ -66,16 +68,19 @@ export default Engine =>
observer.emit('Error', error);
});
}

resetSubscriptionTimeout(timeout = this.getContractDuration() + AFTER_FINISH_TIMEOUT) {
this.cancelSubscriptionTimeout();
this.subscriptionTimeout = setInterval(() => {
this.subscribeToOpenContract();
this.resetSubscriptionTimeout(timeout);
}, timeout * 1000);
}

cancelSubscriptionTimeout() {
clearTimeout(this.subscriptionTimeout);
}

setContractFlags(contract) {
const {
is_expired: isExpired,
Expand All @@ -92,9 +97,11 @@ export default Engine =>

this.hasEntryTick = Boolean(entryTick);
}

expectedContractId(contractId) {
return this.contractId && contractId === this.contractId;
}

getSellPrice() {
const { bid_price: bidPrice, buy_price: buyPrice, currency } = this.data.contract;
return Number(roundBalance({ currency, balance: Number(bidPrice) - Number(buyPrice) }));
Expand Down
Loading