Skip to content

Commit ce66393

Browse files
committed
Merge branch 'beta'
2 parents 4e5eb11 + 2551e1c commit ce66393

File tree

9 files changed

+113
-215
lines changed

9 files changed

+113
-215
lines changed

src/botPage/bot/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ export default class Bot {
122122
}
123123
setTradeOptions() {
124124
if (!_.isEmpty(this.tradeOption)) {
125-
this.pip = this.symbol.activeSymbols.getSymbols()[this.tradeOption.symbol].pip
125+
this.pip = this.symbol.activeSymbols.getSymbols()[this.tradeOption.symbol.toLowerCase()].pip
126126
const opposites = config.opposites[this.tradeOption.condition]
127127
this.candleInterval = this.tradeOption.candleInterval
128128
this.tradeOptions = []

src/botPage/bot/symbol/__tests__/activeSymbols.js

Lines changed: 1 addition & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/botPage/bot/symbol/__tests__/index.js

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,12 @@ describe('symbol', () => {
1717
expect(() => {
1818
_Symbol.getConditionName()
1919
}).to.throw(Error)
20-
expect(() => {
21-
_Symbol.getCategoryForCondition()
22-
}).to.throw(Error)
2320
expect(() => {
2421
_Symbol.getCategoryNameForCondition()
2522
}).to.throw(Error)
2623
expect(() => {
2724
_Symbol.getAllowedCategoryNames()
2825
}).to.throw(Error)
29-
expect(() => {
30-
_Symbol.findSymbol()
31-
}).to.throw(Error)
3226
})
3327
})
3428
describe('Checking functions', () => {
@@ -39,13 +33,8 @@ describe('symbol', () => {
3933
done()
4034
})
4135
})
42-
it('findSymbol returns symbol if exist', () => {
43-
expect(symbol.findSymbol('R_100')).to.be.ok
44-
.and.to.have.property('R_100')
45-
expect(symbol.findSymbol('FAKE')).not.to.be.ok
46-
})
4736
it('getAllowedCategoryNames returns allowed category names', () => {
48-
expect(symbol.getAllowedCategoryNames('R_100')).to.be.ok
37+
expect(symbol.getAllowedCategoryNames('r_100')).to.be.ok
4938
.and.to.have.all.members(['Up/Down', 'Digits', 'Asians',
5039
'Touch/No Touch', 'Ends In/Out', 'Stays In/Goes Out'])
5140
expect(symbol.getAllowedCategoryNames('FAKE')).to.be.empty
@@ -54,38 +43,20 @@ describe('symbol', () => {
5443
expect(symbol.getCategoryNameForCondition('risefall'))
5544
.to.be.equal('Up/Down')
5645
})
57-
it('getCategoryForCondition returns category of a condition', () => {
58-
expect(symbol.getCategoryForCondition('risefall'))
59-
.to.be.equal('callput')
60-
})
6146
it('getConditionName returns name of a condition', () => {
6247
expect(symbol.getConditionName('risefall'))
6348
.to.be.equal('Rise/Fall')
6449
})
6550
it('isConditionAllowedInSymbol returns true if a condition is allowed in a symbol', () => {
66-
expect(symbol.isConditionAllowedInSymbol('R_100', 'risefall'))
51+
expect(symbol.isConditionAllowedInSymbol('r_100', 'risefall'))
6752
.to.be.ok
68-
expect(symbol.isConditionAllowedInSymbol('frxEURUSD', 'asians'))
53+
expect(symbol.isConditionAllowedInSymbol('frxeurusd', 'asians'))
6954
.not.to.be.ok
7055
expect(symbol.isConditionAllowedInSymbol('fake', 'asians'))
7156
.not.to.be.ok
72-
expect(symbol.isConditionAllowedInSymbol('frxEURUSD', 'fake'))
57+
expect(symbol.isConditionAllowedInSymbol('frxeurusd', 'fake'))
7358
.not.to.be.ok
7459
})
75-
it('getAllowedConditionsForSymbol returns allowed conditions for a symbol', () => {
76-
expect(symbol.getAllowedConditionsForSymbol('R_100'))
77-
.to.have.all.members(['risefall', 'higherlower', 'matchesdiffers',
78-
'evenodd', 'overunder', 'asians', 'touchnotouch', 'endsinout', 'staysinout'])
79-
expect(symbol.getAllowedConditionsForSymbol('fake'))
80-
.to.be.empty
81-
})
82-
it('getAllowedCategoriesForSymbol returns allowed categories for a symbol', () => {
83-
expect(symbol.getAllowedCategoriesForSymbol('R_100'))
84-
.to.have.all.members(['callput', 'digits', 'asian',
85-
'touchnotouch', 'endsinout', 'staysinout'])
86-
expect(symbol.getAllowedCategoriesForSymbol('fake'))
87-
.to.be.empty
88-
})
8960
})
9061
after(() => {
9162
api.destroy()

src/botPage/bot/symbol/activeSymbols.js

Lines changed: 49 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,64 @@
11
import _ from 'underscore'
22

3-
export default class ActiveSymbols {
4-
constructor(activeSymbols) {
5-
this.activeSymbols = activeSymbols
6-
this.markets = {}
7-
this.submarkets = {}
8-
this.symbols = {}
9-
this.getMarkets()
10-
}
11-
getMarkets() {
12-
if (!_.isEmpty(this.markets)) {
13-
return this.markets
14-
}
15-
const markets = _.groupBy(this.activeSymbols, 'market')
16-
for (const marketName of Object.keys(markets)) {
17-
const marketSymbols = markets[marketName]
18-
const symbol = marketSymbols[0]
19-
this.markets[marketName] = {
20-
name: symbol.market_display_name,
21-
is_active: !symbol.is_trading_suspended && symbol.exchange_is_open,
22-
}
23-
this.getSubmarketsForMarket(marketName)
24-
}
25-
return this.markets
26-
}
27-
getSubmarketsForMarket(marketName) {
28-
const market = this.markets[marketName]
29-
market.submarkets = {}
30-
const submarkets = _.groupBy(_.groupBy(this.activeSymbols, 'market')[marketName], 'submarket')
31-
for (const submarketName of Object.keys(submarkets)) {
32-
const submarketSymbols = submarkets[submarketName]
33-
const symbol = submarketSymbols[0]
34-
this.submarkets[submarketName] = market.submarkets[submarketName] = {
35-
name: symbol.submarket_display_name,
36-
is_active: !symbol.is_trading_suspended && symbol.exchange_is_open,
37-
}
38-
this.getSymbolsForSubmarket(submarketName)
3+
let apiActiveSymbols
4+
let groupedMarkets
5+
let groupedSubmarkets
6+
7+
const parsedMarkets = {}
8+
const parsedSubmarkets = {}
9+
const parsedSymbols = {}
10+
11+
const parseSymbols = () => {
12+
for (const s of apiActiveSymbols) {
13+
const submarket = parsedSubmarkets[s.submarket]
14+
submarket.symbols = submarket.symbols || {}
15+
parsedSymbols[s.symbol.toLowerCase()] = submarket.symbols[s.symbol.toLowerCase()] = {
16+
...s,
17+
display: s.display_name,
18+
is_active: !s.is_trading_suspended && s.exchange_is_open,
3919
}
40-
return market.submarkets
4120
}
42-
getSymbolsForSubmarket(submarketName) {
43-
const submarket = this.submarkets[submarketName]
44-
submarket.symbols = {}
45-
const symbols = _.groupBy(this.activeSymbols, 'submarket')[submarketName]
46-
for (const symbol of symbols) {
47-
this.symbols[symbol.symbol] = submarket.symbols[symbol.symbol] = {
48-
display: symbol.display_name,
49-
symbol_type: symbol.symbol_type,
50-
is_active: !symbol.is_trading_suspended && symbol.exchange_is_open,
51-
pip: symbol.pip,
52-
market: symbol.market,
53-
submarket: symbol.submarket,
54-
}
21+
}
22+
23+
const parseSubmarkets = () => {
24+
for (const k of Object.keys(groupedSubmarkets)) {
25+
const symbol = groupedSubmarkets[k][0]
26+
const market = parsedMarkets[symbol.market]
27+
market.submarkets = market.submarkets || {}
28+
parsedSubmarkets[k] = market.submarkets[k] = {
29+
name: symbol.submarket_display_name,
30+
is_active: !symbol.is_trading_suspended && symbol.exchange_is_open,
5531
}
56-
return submarket.symbols
5732
}
58-
getSubmarkets() {
59-
if (!_.isEmpty(this.submarkets)) {
60-
return this.submarkets
33+
}
34+
35+
const parseMarkets = () => {
36+
for (const k of Object.keys(groupedMarkets)) {
37+
const symbol = groupedMarkets[k][0]
38+
parsedMarkets[k] = {
39+
name: symbol.market_display_name,
40+
is_active: !symbol.is_trading_suspended && symbol.exchange_is_open,
6141
}
62-
this.getMarkets()
63-
return this.submarkets
6442
}
65-
getSymbols() {
66-
if (!_.isEmpty(this.symbols)) {
67-
return this.symbols
68-
}
69-
this.getMarkets()
70-
return this.symbols
43+
}
44+
45+
export default class ActiveSymbols {
46+
constructor(activeSymbols) {
47+
apiActiveSymbols = activeSymbols
48+
groupedMarkets = _.groupBy(apiActiveSymbols, 'market')
49+
groupedSubmarkets = _.groupBy(apiActiveSymbols, 'submarket')
50+
parseMarkets()
51+
parseSubmarkets()
52+
parseSymbols()
7153
}
72-
getMarketsList() {
73-
const tradeMarketsList = {}
74-
_.extend(tradeMarketsList, this.getMarkets())
75-
_.extend(tradeMarketsList, this.getSubmarkets())
76-
return tradeMarketsList
54+
getMarkets() {
55+
return parsedMarkets
7756
}
78-
getTradeUnderlyings() {
79-
const tradeUnderlyings = {}
80-
const symbols = this.getSymbols()
81-
for (const key of Object.keys(symbols)) {
82-
const symbol = symbols[key]
83-
if (!tradeUnderlyings[symbol.market]) {
84-
tradeUnderlyings[symbol.market] = {}
85-
}
86-
if (!tradeUnderlyings[symbol.submarket]) {
87-
tradeUnderlyings[symbol.submarket] = {}
88-
}
89-
tradeUnderlyings[symbol.market][key] = symbol
90-
tradeUnderlyings[symbol.submarket][key] = symbol
91-
}
92-
return tradeUnderlyings
57+
getSymbols() {
58+
return parsedSymbols
9359
}
9460
getSymbolNames() {
95-
const symbols = _.clone(this.getSymbols())
61+
const symbols = _.clone(parsedSymbols)
9662
for (const key of Object.keys(symbols)) {
9763
symbols[key] = symbols[key].display
9864
}

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