Skip to content

Commit 8f6bbde

Browse files
committed
Optimize the buy-sell loop
1 parent 2442eae commit 8f6bbde

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

src/botPage/bot/TradeEngine/OpenContract.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ export default Engine => class OpenContract extends Engine {
2121
this.ongoingPurchase = false
2222
this.contractId = ''
2323
this.updateTotals(contract)
24-
this.api.unsubscribeByID(this.openContractId)
2524
if (this.afterPromise) {
2625
this.afterPromise()
2726
}
@@ -59,9 +58,7 @@ export default Engine => class OpenContract extends Engine {
5958
doUntilDone(() => this.api.subscribeToTransactions())
6059
}
6160

62-
doUntilDone(() => this.api.subscribeToOpenContract(contractId)).then(r => {
63-
({ proposal_open_contract: { id: this.openContractId } } = r)
64-
})
61+
doUntilDone(() => this.api.subscribeToOpenContract(contractId))
6562
}
6663
setContractFlags(contract) {
6764
const {

src/botPage/bot/TradeEngine/Proposal.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,14 @@ export default Engine => class Proposal extends Engine {
2626
throw translate('Selected proposal does not exist')
2727
}
2828

29-
return toBuy
29+
return {
30+
id: toBuy.id,
31+
askPrice: toBuy.ask_price,
32+
}
3033
}
31-
renewProposalsOnPurchase() {
32-
this.unsubscribeProposals()
34+
renewProposalsOnPurchase(toBuyId) {
3335
this.requestProposals()
36+
this.unsubscribeProposals(toBuyId)
3437
}
3538
waitForProposals() {
3639
this.data = this.data.set('proposals', new Map())
@@ -60,7 +63,7 @@ export default Engine => class Proposal extends Engine {
6063
}
6164
})
6265
}
63-
unsubscribeProposals() {
66+
unsubscribeProposals(toBuyId) {
6467
if (!this.data.has('proposals')) {
6568
return
6669
}
@@ -70,7 +73,11 @@ export default Engine => class Proposal extends Engine {
7073
this.data = this.data.set('proposals', new Map())
7174

7275
proposals.forEach(proposal => {
73-
const { uuid: id } = proposal
76+
const { uuid: id, id: streamId } = proposal
77+
78+
if (toBuyId === streamId) {
79+
return
80+
}
7481

7582
this.data = this.data.setIn(['forgetProposals', id], true)
7683

src/botPage/bot/TradeEngine/Purchase.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ let delayIndex = 0
44

55
export default Engine => class Purchase extends Engine {
66
purchase(contractType) {
7-
const toBuy = this.selectProposal(contractType)
7+
const { id, askPrice } = this.selectProposal(contractType)
88

99
this.ongoingPurchase = true
1010

11-
return recoverFromError(() => this.api.buyContract(toBuy.id, toBuy.ask_price),
11+
return recoverFromError(() => this.api.buyContract(id, askPrice),
1212
(errorCode, makeDelay) => {
1313
// if disconnected no need to resubscription (handled by live-api)
1414
if (errorCode !== 'DisconnectError') {
@@ -19,11 +19,11 @@ export default Engine => class Purchase extends Engine {
1919
.then(() => makeDelay().then(() => this.observer.emit('REVERT', 'before')))
2020
}, ['PriceMoved'], delayIndex++)
2121
.then(r => {
22-
delayIndex = 0
23-
this.broadcastPurchase(r.buy, contractType)
2422
this.subscribeToOpenContract(r.buy.contract_id)
25-
this.renewProposalsOnPurchase()
2623
this.signal('purchase')
24+
delayIndex = 0
25+
this.broadcastPurchase(r.buy, contractType)
26+
this.renewProposalsOnPurchase(id)
2727
})
2828
}
2929
}

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