Skip to content
This repository was archived by the owner on Feb 22, 2024. It is now read-only.

Commit 1b9c9d0

Browse files
authored
Merge pull request #2950 from aaron-binary/bot-bug-fix
aaron/Bot bug fix
2 parents f751729 + 6cdbb39 commit 1b9c9d0

File tree

7 files changed

+146
-132
lines changed

7 files changed

+146
-132
lines changed

src/botPage/bot/Interface/index.js

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,21 @@ export default class Interface extends ToolsInterface(TicksInterface(class {}))
3737
};
3838
}
3939
getBotInterface() {
40-
const getDetail = (i, pipSize) => createDetails(this.get('contract'), pipSize)[i];
40+
const getDetail = (i, pipSize) => createDetails(this.tradeEngine.data.contract, pipSize)[i];
4141

4242
return {
43-
init : (...args) => this.tradeEngine.init(...args),
44-
start : (...args) => this.tradeEngine.start(...args),
45-
stop : (...args) => this.tradeEngine.stop(...args),
46-
purchase : contractType => this.tradeEngine.purchase(contractType),
47-
getAskPrice : contractType => Number(this.getProposal(contractType).ask_price),
48-
getPayout : contractType => Number(this.getProposal(contractType).payout),
49-
isSellAvailable: () => this.tradeEngine.isSellAtMarketAvailable(),
50-
sellAtMarket : () => this.tradeEngine.sellAtMarket(),
51-
getSellPrice : () => this.getSellPrice(),
52-
isResult : result => getDetail(10) === result,
53-
readDetails : i => getDetail(i - 1, this.tradeEngine.getPipSize()),
43+
init : (...args) => this.tradeEngine.init(...args),
44+
start : (...args) => this.tradeEngine.start(...args),
45+
stop : (...args) => this.tradeEngine.stop(...args),
46+
purchase : (...args) => this.tradeEngine.purchase(...args),
47+
getPurchaseReference: () => this.tradeEngine.getPurchaseReference(),
48+
getAskPrice : contractType => Number(this.getProposal(contractType).ask_price),
49+
getPayout : contractType => Number(this.getProposal(contractType).payout),
50+
isSellAvailable : () => this.tradeEngine.isSellAtMarketAvailable(),
51+
sellAtMarket : () => this.tradeEngine.sellAtMarket(),
52+
getSellPrice : () => this.getSellPrice(),
53+
isResult : result => getDetail(10) === result,
54+
readDetails : i => getDetail(i - 1, this.tradeEngine.getPipSize()),
5455
};
5556
}
5657
sleep(arg = 1) {
@@ -64,22 +65,13 @@ export default class Interface extends ToolsInterface(TicksInterface(class {}))
6465
);
6566
}
6667
getProposal(contractType) {
67-
const proposals = this.get('proposals');
68-
69-
let proposal;
70-
71-
proposals.forEach(p => {
72-
if (p.contractType === contractType) {
73-
proposal = p;
74-
}
75-
});
76-
77-
return proposal;
68+
return this.tradeEngine.data.proposals.find(
69+
proposal =>
70+
proposal.contractType === contractType &&
71+
proposal.purchaseReference === this.tradeEngine.getPurchaseReference()
72+
);
7873
}
7974
getSellPrice() {
8075
return this.tradeEngine.getSellPrice();
8176
}
82-
get(key) {
83-
return this.tradeEngine.getData().get(key);
84-
}
8577
}

src/botPage/bot/Interpreter.js

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,39 +58,48 @@ export default class Interpreter {
5858
}
5959
run(code) {
6060
const initFunc = (interpreter, scope) => {
61-
const BotIf = this.bot.getInterface('Bot');
62-
const ticksIf = this.bot.getTicksInterface();
61+
const botInterface = this.bot.getInterface('Bot');
62+
const ticksInterface = this.bot.getTicksInterface();
6363
const { alert, prompt, sleep, console: customConsole } = this.bot.getInterface();
6464

6565
interpreter.setProperty(scope, 'console', interpreter.nativeToPseudo(customConsole));
66-
6766
interpreter.setProperty(scope, 'alert', interpreter.nativeToPseudo(alert));
68-
6967
interpreter.setProperty(scope, 'prompt', interpreter.nativeToPseudo(prompt));
68+
interpreter.setProperty(
69+
scope,
70+
'getPurchaseReference',
71+
interpreter.nativeToPseudo(botInterface.getPurchaseReference)
72+
);
7073

71-
const pseudoBotIf = interpreter.nativeToPseudo(BotIf);
74+
const pseudoBotInterface = interpreter.nativeToPseudo(botInterface);
7275

73-
Object.entries(ticksIf).forEach(([name, f]) => {
74-
interpreter.setProperty(pseudoBotIf, name, this.createAsync(interpreter, f));
76+
Object.entries(ticksInterface).forEach(([name, f]) => {
77+
interpreter.setProperty(pseudoBotInterface, name, this.createAsync(interpreter, f));
7578
});
7679

7780
interpreter.setProperty(
78-
pseudoBotIf,
81+
pseudoBotInterface,
7982
'start',
8083
interpreter.nativeToPseudo((...args) => {
81-
const { start } = BotIf;
84+
const { start } = botInterface;
8285
if (shouldRestartOnError(this.bot)) {
8386
this.startState = interpreter.takeStateSnapshot();
8487
}
8588
start(...args);
8689
})
8790
);
8891

89-
interpreter.setProperty(pseudoBotIf, 'purchase', this.createAsync(interpreter, BotIf.purchase));
90-
91-
interpreter.setProperty(pseudoBotIf, 'sellAtMarket', this.createAsync(interpreter, BotIf.sellAtMarket));
92-
93-
interpreter.setProperty(scope, 'Bot', pseudoBotIf);
92+
interpreter.setProperty(
93+
pseudoBotInterface,
94+
'purchase',
95+
this.createAsync(interpreter, botInterface.purchase)
96+
);
97+
interpreter.setProperty(
98+
pseudoBotInterface,
99+
'sellAtMarket',
100+
this.createAsync(interpreter, botInterface.sellAtMarket)
101+
);
102+
interpreter.setProperty(scope, 'Bot', pseudoBotInterface);
94103

95104
interpreter.setProperty(
96105
scope,

src/botPage/bot/TradeEngine/OpenContract.js

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default Engine =>
1818

1919
this.setContractFlags(contract);
2020

21-
this.data = this.data.set('contract', contract);
21+
this.data.contract = contract;
2222

2323
broadcastContract({ accountID: this.accountInfo.loginid, ...contract });
2424

@@ -37,8 +37,6 @@ export default Engine =>
3737

3838
this.store.dispatch(sell());
3939

40-
this.unsubscribeOpenContract();
41-
4240
this.cancelSubscriptionTimeout();
4341
} else {
4442
this.store.dispatch(openContractReceived());
@@ -59,8 +57,6 @@ export default Engine =>
5957
}
6058
this.contractId = contractId;
6159

62-
this.unsubscribeOpenContract();
63-
6460
doUntilDone(() =>
6561
this.api.subscribeToOpenContract(contractId).then(response => {
6662
this.openContractId = response.proposal_open_contract.id;
@@ -80,11 +76,6 @@ export default Engine =>
8076
cancelSubscriptionTimeout() {
8177
clearTimeout(this.subscriptionTimeout);
8278
}
83-
unsubscribeOpenContract() {
84-
if (this.openContractId) {
85-
doUntilDone(() => this.api.unsubscribeByID(this.openContractId));
86-
}
87-
}
8879
setContractFlags(contract) {
8980
const {
9081
is_expired: isExpired,
@@ -105,7 +96,7 @@ export default Engine =>
10596
return this.contractId && contractId === this.contractId;
10697
}
10798
getSellPrice() {
108-
const { bid_price: bidPrice, buy_price: buyPrice, currency } = this.data.get('contract');
99+
const { bid_price: bidPrice, buy_price: buyPrice, currency } = this.data.contract;
109100
return Number(roundBalance({ currency, balance: Number(bidPrice) - Number(buyPrice) }));
110101
}
111102
};

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