-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added market.base and market.quote facts (#4)
- Loading branch information
Showing
10 changed files
with
229 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
module.exports = { | ||
ta: require('./ta') | ||
ta: require('./ta'), | ||
market: require('./market') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const Fact = require('../base') | ||
|
||
class Base extends Fact { | ||
get id () { | ||
return 'market.base' | ||
} | ||
|
||
get name () { | ||
return 'Base symbol for market' | ||
} | ||
|
||
get description () { | ||
return 'Get the base symbol from a market symbol' | ||
} | ||
|
||
get schema () { | ||
return { | ||
market: { type: 'market', required: true, description: 'The market symbol.' }, | ||
$$strict: 'remove' | ||
} | ||
} | ||
|
||
async value (params = {}) { | ||
params = super.value(params) | ||
|
||
return params.market.split('/')[0] | ||
} | ||
} | ||
|
||
module.exports = Base |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
const base = require('./base') | ||
const quote = require('./quote') | ||
|
||
module.exports = { base, quote } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const Fact = require('../base') | ||
|
||
class Quote extends Fact { | ||
get id () { | ||
return 'market.quote' | ||
} | ||
|
||
get name () { | ||
return 'Quote symbol for market' | ||
} | ||
|
||
get description () { | ||
return 'Get the quote symbol from a market symbol' | ||
} | ||
|
||
get schema () { | ||
return { | ||
market: { type: 'market', required: true, description: 'The market symbol.' }, | ||
$$strict: 'remove' | ||
} | ||
} | ||
|
||
async value (params = {}) { | ||
params = super.value(params) | ||
|
||
return params.market.split('/')[1] | ||
} | ||
} | ||
|
||
module.exports = Quote |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
const { expect, chance } = require('../../helpers') | ||
const Base = require('../../../lib/facts/market/base') | ||
|
||
describe('Fact market.base', () => { | ||
describe('#value', () => { | ||
const fact = new Base() | ||
|
||
describe('params', () => { | ||
describe('market', () => { | ||
it('is required', async () => { | ||
let thrownErr = null | ||
|
||
try { | ||
await fact.value() | ||
} catch (err) { | ||
thrownErr = err | ||
} | ||
|
||
expect(thrownErr.type).to.eql('VALIDATION_ERROR') | ||
expect(thrownErr.data[0].message).to.eql('market is required') | ||
}) | ||
|
||
it('must be a string', async () => { | ||
let thrownErr = null | ||
|
||
try { | ||
await fact.value({ market: chance.bool() }) | ||
} catch (err) { | ||
thrownErr = err | ||
} | ||
|
||
expect(thrownErr.type).to.eql('VALIDATION_ERROR') | ||
expect(thrownErr.data[0].message).to.eql('market must be a string') | ||
}) | ||
}) | ||
}) | ||
|
||
it('returns the base symbol', async () => { | ||
const result = await fact.value({ market: 'BTC/USD' }) | ||
|
||
expect(result).to.eql('BTC') | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
const { expect, chance } = require('../../helpers') | ||
const Quote = require('../../../lib/facts/market/quote') | ||
|
||
describe('Fact market.quote', () => { | ||
describe('#value', () => { | ||
const fact = new Quote() | ||
|
||
describe('params', () => { | ||
describe('market', () => { | ||
it('is required', async () => { | ||
let thrownErr = null | ||
|
||
try { | ||
await fact.value() | ||
} catch (err) { | ||
thrownErr = err | ||
} | ||
|
||
expect(thrownErr.type).to.eql('VALIDATION_ERROR') | ||
expect(thrownErr.data[0].message).to.eql('market is required') | ||
}) | ||
|
||
it('must be a string', async () => { | ||
let thrownErr = null | ||
|
||
try { | ||
await fact.value({ market: chance.bool() }) | ||
} catch (err) { | ||
thrownErr = err | ||
} | ||
|
||
expect(thrownErr.type).to.eql('VALIDATION_ERROR') | ||
expect(thrownErr.data[0].message).to.eql('market must be a string') | ||
}) | ||
}) | ||
}) | ||
|
||
it('returns the quote symbol', async () => { | ||
const result = await fact.value({ market: 'BTC/USDT' }) | ||
|
||
expect(result).to.eql('USDT') | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters