jest . mock ( '../../../lib/events.enum' , ( ) => { return { EVENT : { TRADE : 0 , PERIOD : 1 } } ; } ) ; import { SoftCodedPrice } from './softcodedprice' ; import { candles } from '../../indicators/spec.helper' ; import { SIGNAL } from '../../../types' ; describe ( 'SoftCodedPrice' , ( ) => { let softCodedPrice ; beforeEach ( ( ) => { softCodedPrice = new SoftCodedPrice ( 'test' , 'test' , { buyPrice : 18.0 , sellPrice : 18.25 , stopLoss : 17.25 } ) ; } ) ; it ( 'should not return signal without a full period' , ( ) => { softCodedPrice . calculate ( '1m' , candles . slice ( 0 , 0 ) ) ; const { signal } = softCodedPrice . onPeriod ( '1m' ) ; expect ( signal ) . toBeNull ( ) ; } ) ; it ( 'should buy when price is low enough' , ( ) => { softCodedPrice . calculate ( '1m' , candles . slice ( 1 , 2 ) ) ; const { signal } = softCodedPrice . onPeriod ( '1m' ) ; expect ( signal ) . toEqual ( SIGNAL . OPEN_LONG ) ; } ) ; it ( 'should sell when price is high enough' , ( ) => { softCodedPrice . calculate ( '1m' , candles . slice ( 1 , 2 ) ) ; softCodedPrice . calculate ( '1m' , candles . slice ( 3 , 4 ) ) ; const { signal } = softCodedPrice . onPeriod ( '1m' ) ; expect ( signal ) . toEqual ( SIGNAL . CLOSE_LONG ) ; } ) ; it ( 'should sell when price is low after buy' , ( ) => { softCodedPrice . calculate ( '1m' , candles . slice ( 1 , 2 ) ) ; softCodedPrice . calculate ( '1m' , candles . slice ( 7 , 8 ) ) ; const { signal } = softCodedPrice . onPeriod ( '1m' ) ; expect ( signal ) . toEqual ( SIGNAL . CLOSE_LONG ) ; } ) ; it ( 'should not sell before a buy' , ( ) => { softCodedPrice . calculate ( '1m' , candles . slice ( 3 , 4 ) ) ; const { signal } = softCodedPrice . onPeriod ( '1m' ) ; expect ( signal ) . toBeNull ( ) ; } ) ; it ( 'should not buy or sell if not triggered' , ( ) => { softCodedPrice . calculate ( '1m' , candles . slice ( 3 , 4 ) ) ; const { signal } = softCodedPrice . onPeriod ( '1m' ) ; expect ( signal ) . toBeNull ( ) ; } ) ; it ( 'should only buy once' , ( ) => { softCodedPrice . calculate ( '1m' , candles . slice ( 1 , 2 ) ) ; softCodedPrice . calculate ( '1m' , candles . slice ( 3 , 4 ) ) ; softCodedPrice . calculate ( '1m' , candles . slice ( 1 , 2 ) ) ; const { signal } = softCodedPrice . onPeriod ( '1m' ) ; expect ( signal ) . toBeNull ( ) ; } ) ; } ) ; describe ( 'SoftCodedPrice repeating' , ( ) => { let softCodedPrice ; beforeEach ( ( ) => { softCodedPrice = new SoftCodedPrice ( 'test' , 'test' , { buyPrice : 18.0 , sellPrice : 18.25 , stopLoss : 17.25 , isRepeat : true } ) ; } ) ; it ( 'should buy again with repeat flag set' , ( ) => { softCodedPrice . calculate ( '1m' , candles . slice ( 1 , 2 ) ) ; softCodedPrice . calculate ( '1m' , candles . slice ( 3 , 4 ) ) ; softCodedPrice . calculate ( '1m' , candles . slice ( 1 , 2 ) ) ; const { signal } = softCodedPrice . onPeriod ( '1m' ) ; expect ( signal ) . toEqual ( SIGNAL . OPEN_LONG ) ; } ) ; } ) ;