Skip to content

Commit bab49bf

Browse files
authored
Merge branch 'dev' into contract-pip-size
2 parents 0f48048 + d39404f commit bab49bf

File tree

16 files changed

+234
-24
lines changed

16 files changed

+234
-24
lines changed

.github/stale.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Configuration for probot-stale - https://github.com/probot/stale
2+
3+
# Limit to only `issues`
4+
only: issues
5+
6+
# Number of days of inactivity before an Issue or Pull Request is closed.
7+
# Set to false to disable. If disabled, issues still need to be closed manually, but will remain marked as stale.
8+
daysUntilClose: 14
9+
10+
# Issues or Pull Requests with these labels will never be considered stale. Set to `[]` to disable
11+
exemptLabels:
12+
- bug
13+
- "technical issues"
14+
- "feature request"
15+
16+
17+
# Label to use when marking an issue as stale
18+
staleLabel: stale
19+
20+
# Comment to post when marking as stale. Set to `false` to disable
21+
markComment: false
22+
23+
# Comment to post when closing a stale Issue or Pull Request.
24+
closeComment: >
25+
This issue has been automatically closed since there has not been
26+
any recent activity. Please open a new issue for related bugs.
27+
28+
# Limit the number of actions per hour, from 1-30. Default is 30
29+
limitPerRun: 30

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ install: npm ci
55
cache:
66
directories:
77
- node_modules
8+
script: travis_retry npm test

src/botPage/bot/Interface/ToolsInterface.js

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,78 @@
11
import CandleInterface from './CandleInterface';
22
import MiscInterface from './MiscInterface';
33
import IndicatorsInterface from './IndicatorsInterface';
4+
import { translate } from '../../../common/i18n';
45

56
// prettier-ignore
67
export default Interface => class extends IndicatorsInterface(
78
MiscInterface(CandleInterface(Interface))) {
89
getToolsInterface() {
910
return {
10-
getTime: () => parseInt(new Date().getTime() / 1000),
11+
getTime : () => parseInt(new Date().getTime() / 1000),
12+
toDateTime: (timestamp) => {
13+
const getTwoDigitValue = input => {
14+
if (input < 10) {
15+
return `0${input}`;
16+
}
17+
return `${input}`;
18+
}
19+
const invalidTimestamp = () => `${translate('Invalid timestamp')}: ${timestamp}`;
20+
if (typeof timestamp === 'number') {
21+
const dateTime = new Date(timestamp * 1000);
22+
if (dateTime.getTime()) {
23+
const year = dateTime.getFullYear();
24+
const month = getTwoDigitValue(dateTime.getMonth() + 1);
25+
const day = getTwoDigitValue(dateTime.getDate());
26+
const hours = getTwoDigitValue(dateTime.getHours());
27+
const minutes = getTwoDigitValue(dateTime.getMinutes());
28+
const seconds = getTwoDigitValue(dateTime.getSeconds());
29+
const formatGTMoffset = () => {
30+
const GMToffsetRaw = dateTime.getTimezoneOffset();
31+
const sign = GMToffsetRaw > 0 ? '-' : '+';
32+
const GMToffset = Math.abs(GMToffsetRaw);
33+
const h = Math.floor(GMToffset / 60);
34+
const m = GMToffset - h * 60;
35+
return `GMT${sign}${getTwoDigitValue(h)}${getTwoDigitValue(m)}`;
36+
}
37+
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds} ${formatGTMoffset()}`;
38+
}
39+
return invalidTimestamp();
40+
}
41+
return invalidTimestamp();
42+
},
43+
toTimestamp: (dateTimeString) => {
44+
const invalidDatetime = () => `${translate('Invalid date/time')}: ${dateTimeString}`;
45+
if (typeof dateTimeString === 'string') {
46+
const dateTime = dateTimeString
47+
.replace(/[^0-9.:-\s]/g, '')
48+
.replace(/\s+/g,' ')
49+
.trim()
50+
.split(' ');
51+
52+
const d = /^[12]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/;
53+
const t = /^(0[0-9]|1[0-9]|2[0-3]):([0-5][0-9])(:([0-5][0-9])?)?$/;
54+
55+
let validatedDateTime;
56+
57+
if(dateTime.length >= 2) {
58+
validatedDateTime = d.test(dateTime[0]) && t.test(dateTime[1]) ? `${dateTime[0]}T${dateTime[1]}` : null;
59+
} else if(dateTime.length === 1) {
60+
validatedDateTime = d.test(dateTime[0]) ? dateTime[0] : null;
61+
} else {
62+
validatedDateTime = null;
63+
}
64+
65+
if(validatedDateTime) {
66+
const dateObj = new Date(validatedDateTime);
67+
// eslint-disable-next-line no-restricted-globals
68+
if(dateObj instanceof Date && !isNaN(dateObj)) {
69+
return dateObj.getTime() / 1000;
70+
}
71+
}
72+
return invalidDatetime();
73+
}
74+
return invalidDatetime();
75+
},
1176
...this.getCandleInterface(),
1277
...this.getMiscInterface(),
1378
...this.getIndicatorsInterface(),

src/botPage/bot/TradeEngine/OpenContract.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ export default Engine =>
1717

1818
this.setContractFlags(contract);
1919

20-
this.sellExpired();
21-
2220
this.data = this.data.set('contract', contract);
2321

2422
broadcastContract({ accountID: this.accountInfo.loginid, ...contract });
@@ -45,11 +43,7 @@ export default Engine =>
4543
this.store.dispatch(openContractReceived());
4644
if (!this.isExpired) {
4745
this.resetSubscriptionTimeout();
48-
return;
49-
}
50-
if (!this.retriedUnsuccessfullSellExpired) {
51-
this.retriedUnsuccessfullSellExpired = true;
52-
this.resetSubscriptionTimeout(AFTER_FINISH_TIMEOUT);
46+
5347
}
5448
}
5549
});
@@ -61,7 +55,6 @@ export default Engine =>
6155
}
6256
subscribeToOpenContract(contractId = this.contractId) {
6357
if (this.contractId !== contractId) {
64-
this.retriedUnsuccessfullSellExpired = false;
6558
this.resetSubscriptionTimeout();
6659
}
6760
this.contractId = contractId;

src/botPage/bot/TradeEngine/Sell.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,4 @@ export default Engine =>
4646
delayIndex++
4747
).then(onSuccess);
4848
}
49-
sellExpired() {
50-
if (this.isSellAvailable && this.isExpired) {
51-
doUntilDone(() => this.api.sellExpiredContracts());
52-
}
53-
}
5449
};

src/botPage/bot/TradeEngine/Total.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { translate } from '../../../common/i18n';
22
import { roundBalance } from '../../common/tools';
33
import { info, notify } from '../broadcast';
4-
import createError from '../../common/error';
4+
import { createError } from '../../common/error';
55
import { observer as globalObserver } from '../../../common/utils/observer';
66

77
const skeleton = {

src/botPage/bot/TradeEngine/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { createStore, applyMiddleware } from 'redux';
33
import thunk from 'redux-thunk';
44
import { durationToSecond } from '../../../common/utils/tools';
55
import { translate } from '../../..//common/i18n';
6-
import createError from '../../common/error';
6+
import { createError } from '../../common/error';
77
import { doUntilDone } from '../tools';
88
import { expectInitArg, expectTradeOptions } from '../sanitize';
99
import Proposal from './Proposal';

src/botPage/bot/__tests__/block-tests/tools-test/Time.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,17 @@ describe('Time in tools', () => {
2727
expect(time2 - time1).most(3);
2828
});
2929
});
30+
31+
describe('Convert timestamp to date/time and back', () => {
32+
const timestamp = Math.ceil(new Date().getTime() / 1000);
33+
let result;
34+
beforeAll(done => {
35+
run(`(function() {return Bot.toTimestamp(Bot.toDateTime(${timestamp}));})()`).then(v => {
36+
result = v;
37+
done();
38+
});
39+
});
40+
it('converts timestamp to date/time string', () => {
41+
expect(result).satisfy(dt => dt === timestamp);
42+
});
43+
});

src/botPage/bot/sanitize.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { translate } from '../../common/i18n';
2-
import createError from '../common/error';
2+
import { createError } from '../common/error';
33

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

src/botPage/common/error.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1-
const createError = (name, message) => {
1+
import { observer as globalObserver } from '../../common/utils/observer';
2+
import { translate } from '../../common/i18n';
3+
4+
export const createError = (name, message) => {
25
const e = new Error(message);
36
e.name = name;
47
return e;
58
};
69

7-
export default createError;
10+
export const createErrorAndEmit = (name, message) => {
11+
globalObserver.emit('ui.log.warn', `${translate(message)}`);
12+
return createError(name, message);
13+
};

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