-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(models): increase the base table
- Loading branch information
1 parent
f0d2484
commit ea8ab44
Showing
38 changed files
with
1,144 additions
and
685 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
import { fixByDigits, floorByDigit } from './format'; | ||
|
||
describe('floorByDigit', () => { | ||
describe('btc_jpy pair:', () => { | ||
let priceDigit: number; | ||
|
||
beforeEach(() => { | ||
priceDigit = 0; | ||
}); | ||
|
||
it('should return floored value #1', () => { | ||
const value = 808138; | ||
|
||
const result = floorByDigit(value, priceDigit); | ||
expect(result).toBeTruthy(); | ||
expect(result).toBe(808138); | ||
}); | ||
|
||
it('should return floored value #2', () => { | ||
const value = 808138.5; | ||
|
||
const result = floorByDigit(value, priceDigit); | ||
expect(result).toBeTruthy(); | ||
expect(result).toBe(808138); | ||
}); | ||
}); | ||
|
||
describe('xrp_jpy pair:', () => { | ||
let priceDigit: number; | ||
|
||
beforeEach(() => { | ||
priceDigit = 3; | ||
}); | ||
|
||
it('should return floored value #1', () => { | ||
const value = 64.655; | ||
|
||
const result = floorByDigit(value, priceDigit); | ||
expect(result).toBeTruthy(); | ||
expect(result).toBe(64.655); | ||
}); | ||
|
||
it('should return floored value #2', () => { | ||
const value = 64.6; | ||
|
||
const result = floorByDigit(value, priceDigit); | ||
expect(result).toBeTruthy(); | ||
expect(result).toBe(64.6); | ||
}); | ||
|
||
it('should return floored value #3', () => { | ||
const value = 64.6558; | ||
|
||
const result = floorByDigit(value, priceDigit); | ||
expect(result).toBeTruthy(); | ||
expect(result).toBe(64.655); | ||
}); | ||
}); | ||
|
||
describe('ltc_btc pair:', () => { | ||
let priceDigit: number; | ||
|
||
beforeEach(() => { | ||
priceDigit = 8; | ||
}); | ||
|
||
it('should return floored value #1', () => { | ||
const value = 0.01598311; | ||
|
||
const result = floorByDigit(value, priceDigit); | ||
expect(result).toBeTruthy(); | ||
expect(result).toBe(0.01598311); | ||
}); | ||
}); | ||
|
||
describe('eth_btc pair:', () => { | ||
let priceDigit: number; | ||
|
||
beforeEach(() => { | ||
priceDigit = 8; | ||
}); | ||
|
||
it('should return floored value #1', () => { | ||
const value = 0.07678989; | ||
|
||
const result = floorByDigit(value, priceDigit); | ||
expect(result).toBeTruthy(); | ||
expect(result).toBe(0.07678989); | ||
}); | ||
}); | ||
|
||
describe('mona_jpy pair:', () => { | ||
let priceDigit: number; | ||
|
||
beforeEach(() => { | ||
priceDigit = 3; | ||
}); | ||
|
||
it('should return floored value #1', () => { | ||
const value = 366.897; | ||
|
||
const result = floorByDigit(value, priceDigit); | ||
expect(result).toBeTruthy(); | ||
expect(result).toBe(366.897); | ||
}); | ||
}); | ||
|
||
describe('mona_btc pair:', () => { | ||
let priceDigit: number; | ||
|
||
beforeEach(() => { | ||
priceDigit = 8; | ||
}); | ||
|
||
it('should return floored value #1', () => { | ||
const value = 0.000454; | ||
|
||
const result = floorByDigit(value, priceDigit); | ||
expect(result).toBeTruthy(); | ||
expect(result).toBe(0.000454); | ||
}); | ||
}); | ||
|
||
describe('bcc_jpy pair:', () => { | ||
let priceDigit: number; | ||
|
||
beforeEach(() => { | ||
priceDigit = 0; | ||
}); | ||
|
||
it('should return floored value #7', () => { | ||
const value = 107999; | ||
|
||
const result = floorByDigit(value, priceDigit); | ||
expect(result).toBeTruthy(); | ||
expect(result).toBe(107999); | ||
}); | ||
}); | ||
|
||
describe('bcc_btc pair:', () => { | ||
let priceDigit: number; | ||
|
||
beforeEach(() => { | ||
priceDigit = 8; | ||
}); | ||
|
||
it('should return floored value #8', () => { | ||
const value = 0.13387562; | ||
|
||
const result = floorByDigit(value, priceDigit); | ||
expect(result).toBeTruthy(); | ||
expect(result).toBe(0.13387562); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('fixByDigits', () => { | ||
describe('When proper values are provided', () => { | ||
it('should calculate values properly', () => { | ||
const base = '0.001'; | ||
expect(fixByDigits(base, 1)).toBe('0.0'); | ||
expect(fixByDigits(base, 2)).toBe('0.00'); | ||
expect(fixByDigits(base, 3)).toBe('0.001'); | ||
expect(fixByDigits(base, 4)).toBe('0.0010'); | ||
}); | ||
|
||
it('should round values', () => { | ||
const base = '0.009'; | ||
expect(fixByDigits(base, 2)).toBe('0.01'); | ||
}); | ||
}); | ||
}); |
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,38 @@ | ||
import { BigNumber } from 'bignumber.js'; | ||
|
||
import { getBigNumber } from './get-big-number'; | ||
|
||
/** | ||
* get floored number by specific decimal places. | ||
* | ||
* @param {number} value - number to floor. | ||
* @param {number} decimalPlace - where to floor. | ||
* @returns {number} | ||
*/ | ||
export function floorByDigit(value: BigNumber.Value, decimalPlace: number = 0): number { | ||
const bigNumber = getBigNumber(value); | ||
|
||
// fix number with priceDigit (0.123456 -> 0.1234) | ||
const characteristic = getBigNumber(10).pow(decimalPlace); | ||
// If input is specified as a number greater than 15 digits, | ||
// it will result in an error so cast once to string. | ||
// @see https://github.com/MikeMcl/bignumber.js/issues/148 | ||
const multiplied = bigNumber.multipliedBy(characteristic); | ||
|
||
return multiplied | ||
.integerValue(BigNumber.ROUND_FLOOR) | ||
.dividedBy(characteristic) | ||
.toNumber(); | ||
} | ||
|
||
/** | ||
* Fix value with provided digits. | ||
* | ||
* @param value | ||
* @param digits | ||
*/ | ||
export function fixByDigits(value: BigNumber.Value, digits: number): string { | ||
const bn = getBigNumber(value); | ||
|
||
return bn.toFixed(digits); | ||
} |
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,2 +1,3 @@ | ||
export * from './condition'; | ||
export * from './format'; | ||
export * from './get-big-number'; |
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
29 changes: 26 additions & 3 deletions
29
modules/models/common/testing/entity-test-bed/constants.ts
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,7 +1,30 @@ | ||
import { ObjectType } from 'typeorm'; | ||
|
||
import { MasterPairEntity, MasterPairRepository } from '../../../entity'; | ||
import { | ||
CandlestickEntity, | ||
CandlestickRepository, | ||
MasterExchangeEntity, | ||
MasterExchangeRepository, | ||
MasterPairEntity, | ||
MasterPairRepository, | ||
OrderbookEntity, | ||
OrderbookRepository, | ||
TransactionEntity, | ||
TransactionRepository, | ||
} from '../../../entity'; | ||
|
||
export const allEntityTypes: ObjectType<any>[] = [MasterPairEntity]; | ||
export const allEntityTypes: ObjectType<any>[] = [ | ||
MasterPairEntity, | ||
MasterExchangeEntity, | ||
OrderbookEntity, | ||
TransactionEntity, | ||
CandlestickEntity, | ||
]; | ||
|
||
export const allRepositoryTypes: ObjectType<any>[] = [MasterPairRepository]; | ||
export const allRepositoryTypes: ObjectType<any>[] = [ | ||
MasterPairRepository, | ||
MasterExchangeRepository, | ||
OrderbookRepository, | ||
TransactionRepository, | ||
CandlestickRepository, | ||
]; |
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
Oops, something went wrong.