@@ -3,11 +3,11 @@ import assert from 'node:assert/strict';
33
44import {
55 collectNonZeroPriceMoves ,
6- collectPriceMovesWithExpandingWindow ,
76 formatOrderbookPrecisionShortcutLabel ,
87 getOrderbookPrecisionDecadeTarget ,
98 getOrderbookPrecisionShortcutOptions ,
109 recommendOrderbookPrecision ,
10+ recommendOrderbookPrecisionWithExpandingWindow ,
1111} from '../../../src/binance-orderbook-trade/core/precision.js' ;
1212
1313test ( 'keeps only the four smallest exact native precision shortcuts' , ( ) => {
@@ -117,7 +117,7 @@ test('ten latest trade rows provide enough movement evidence when eight do not',
117117 } ) , '0.001' ) ;
118118} ) ;
119119
120- test ( 'expands the latest-trade window only until enough effective price moves exist ' , ( ) => {
120+ test ( 'expands the latest-trade window until it produces a recommendation ' , ( ) => {
121121 const prices = [
122122 '80.757' , '80.757' , '80.756' , '80.756' , '80.756' ,
123123 '80.757' , '80.756' , '80.755' , '80.755' , '80.755' ,
@@ -126,17 +126,41 @@ test('expands the latest-trade window only until enough effective price moves ex
126126 '80.700' ,
127127 ] ;
128128
129- const result = collectPriceMovesWithExpandingWindow ( prices ) ;
129+ const result = recommendOrderbookPrecisionWithExpandingWindow ( {
130+ prices,
131+ options : [ '0.0001' , '0.001' , '0.01' , '0.1' , '1' ] ,
132+ } ) ;
130133 assert . equal ( result . usedCount , 20 ) ;
131134 assert . equal ( result . samples . length , 13 ) ;
132135 assert . deepEqual ( [ ...new Set ( result . samples ) ] , [ '0.001' ] ) ;
136+ assert . equal ( result . recommendation , '0.001' ) ;
133137} ) ;
134138
135139test ( 'returns the complete visible snapshot when price changes remain insufficient' , ( ) => {
136- assert . deepEqual ( collectPriceMovesWithExpandingWindow ( [
137- '80.7' , '80.7' , '80.7' , '80.7' , '80.7' , '80.7' ,
138- ] ) , {
140+ assert . deepEqual ( recommendOrderbookPrecisionWithExpandingWindow ( {
141+ prices : [ '80.7' , '80.7' , '80.7' , '80.7' , '80.7' , '80.7' ] ,
142+ options : [ '0.001' , '0.01' , '0.1' , '1' ] ,
143+ } ) , {
139144 samples : [ ] ,
140145 usedCount : 6 ,
146+ recommendation : null ,
141147 } ) ;
142148} ) ;
149+
150+ test ( 'keeps expanding when sample count is sufficient but no precision bucket is decisive' , ( ) => {
151+ const prices = [
152+ '79.748' , '79.747' , '79.742' , '79.742' , '79.737' ,
153+ '79.731' , '79.730' , '79.730' , '79.715' , '79.748' ,
154+ '79.748' , '79.746' , '79.740' , '79.727' , '79.727' ,
155+ '79.746' , '79.745' , '79.745' , '79.767' , '79.767' ,
156+ '79.745' , '79.738' , '79.737' ,
157+ ] ;
158+ const options = [ '0.0001' , '0.001' , '0.01' , '0.1' , '1' ] ;
159+ const firstWindowSamples = collectNonZeroPriceMoves ( prices . slice ( 0 , 10 ) ) ;
160+
161+ assert . equal ( firstWindowSamples . length , 7 ) ;
162+ assert . equal ( recommendOrderbookPrecision ( { samples : firstWindowSamples , options } ) , null ) ;
163+ const result = recommendOrderbookPrecisionWithExpandingWindow ( { prices, options } ) ;
164+ assert . equal ( result . usedCount , 20 ) ;
165+ assert . equal ( result . recommendation , '0.01' ) ;
166+ } ) ;
0 commit comments