@@ -10,15 +10,26 @@ const NEWS_INTERVAL_TICKS = 15;
1010type AssetType = 'OIL' | 'GOLD' | 'SILVER' | 'BR' | 'RU' | 'MA' | 'UR' | 'TBOND' ;
1111type ViewMode = 'auto' | 'mobile' | 'desktop' ;
1212
13- const ASSET_CONFIG : Record < AssetType , { name : string , basePrice : number , minPrice : number , maxPrice : number , vol : number , icon : string } > = {
14- OIL : { name : '原油' , basePrice : 75 , minPrice : 20 , maxPrice : 150 , vol : 0.0025 , icon : '🛢️' } ,
15- GOLD : { name : '黄金' , basePrice : 2000 , minPrice : 1200 , maxPrice : 3000 , vol : 0.00012 , icon : '✨' } ,
16- SILVER : { name : '白银' , basePrice : 30 , minPrice : 15 , maxPrice : 60 , vol : 0.0015 , icon : '🥈' } ,
17- BR : { name : '合成胶' , basePrice : 12000 , minPrice : 8000 , maxPrice : 20000 , vol : 0.002 , icon : '🧪' } ,
18- RU : { name : '天然胶' , basePrice : 13000 , minPrice : 8000 , maxPrice : 25000 , vol : 0.002 , icon : '🌲' } ,
19- MA : { name : '甲醇' , basePrice : 2500 , minPrice : 1500 , maxPrice : 4000 , vol : 0.002 , icon : '🔥' } ,
20- UR : { name : '尿素' , basePrice : 2200 , minPrice : 1500 , maxPrice : 3500 , vol : 0.0018 , icon : '🌾' } ,
21- TBOND : { name : '国债' , basePrice : 100 , minPrice : 80 , maxPrice : 120 , vol : 0.0005 , icon : '📜' } ,
13+ interface AssetConfig {
14+ name : string ;
15+ basePrice : number ;
16+ minPrice : number ;
17+ maxPrice : number ;
18+ vol : number ;
19+ icon : string ;
20+ precision : number ; // 小数点位数
21+ step : number ; // 最小变动价位
22+ }
23+
24+ const ASSET_CONFIG : Record < AssetType , AssetConfig > = {
25+ OIL : { name : '原油' , basePrice : 75 , minPrice : 20 , maxPrice : 150 , vol : 0.0025 , icon : '🛢️' , precision : 2 , step : 0.01 } ,
26+ GOLD : { name : '黄金' , basePrice : 2000 , minPrice : 1200 , maxPrice : 3000 , vol : 0.00012 , icon : '✨' , precision : 2 , step : 0.01 } ,
27+ SILVER : { name : '白银' , basePrice : 30 , minPrice : 15 , maxPrice : 60 , vol : 0.0015 , icon : '🥈' , precision : 0 , step : 1 } ,
28+ BR : { name : '合成胶' , basePrice : 12000 , minPrice : 8000 , maxPrice : 20000 , vol : 0.002 , icon : '🧪' , precision : 0 , step : 5 } ,
29+ RU : { name : '天然胶' , basePrice : 13000 , minPrice : 8000 , maxPrice : 25000 , vol : 0.002 , icon : '🌲' , precision : 0 , step : 5 } ,
30+ MA : { name : '甲醇' , basePrice : 2500 , minPrice : 1500 , maxPrice : 4000 , vol : 0.002 , icon : '🔥' , precision : 0 , step : 1 } ,
31+ UR : { name : '尿素' , basePrice : 2200 , minPrice : 1500 , maxPrice : 3500 , vol : 0.0018 , icon : '🌾' , precision : 0 , step : 1 } ,
32+ TBOND : { name : '国债' , basePrice : 100 , minPrice : 80 , maxPrice : 120 , vol : 0.0005 , icon : '📜' , precision : 3 , step : 0.005 } ,
2233} ;
2334
2435const NEWS_POOL = [
@@ -65,7 +76,7 @@ const App: React.FC = () => {
6576 ) ;
6677
6778 useEffect ( ( ) => {
68- console . log ( "期货风云核心逻辑版本: 3.2 - 多品种扩充版 " ) ;
79+ console . log ( "期货风云核心逻辑版本: 3.3 - 拟真报价版 (精度与步长优化) " ) ;
6980 const saved = localStorage . getItem ( 'cc_user' ) ;
7081 if ( saved ) {
7182 const parsed = JSON . parse ( saved ) ;
@@ -162,6 +173,10 @@ const App: React.FC = () => {
162173 delta = Math . max ( - 0.005 , Math . min ( 0.005 , delta ) ) ;
163174
164175 let p = prevP * ( 1 + delta ) ;
176+
177+ // 核心修正:按照步长和精度修约价格
178+ p = Math . round ( p / config . step ) * config . step ;
179+
165180 if ( ! isFinite ( p ) || p <= 0 ) p = config . basePrice ;
166181 p = Math . min ( config . maxPrice , Math . max ( config . minPrice , p ) ) ;
167182
@@ -274,7 +289,12 @@ const App: React.FC = () => {
274289 < ChevronDown size = { 14 } className = "select-icon" />
275290 </ div >
276291 < div className = "chart-price-box" >
277- < span className = "current-price" > { prices [ activeAsset ] . toLocaleString ( undefined , { minimumFractionDigits : 2 } ) } </ span >
292+ < span className = "current-price" >
293+ { prices [ activeAsset ] . toLocaleString ( undefined , {
294+ minimumFractionDigits : ASSET_CONFIG [ activeAsset ] . precision ,
295+ maximumFractionDigits : ASSET_CONFIG [ activeAsset ] . precision
296+ } ) }
297+ </ span >
278298 < span className = { `price-change ${ prices [ activeAsset ] >= ( priceHistory [ activeAsset ] ? priceHistory [ activeAsset ] [ 0 ] : prices [ activeAsset ] ) ? 'up' : 'down' } ` } >
279299 { priceChangePercent } %
280300 </ span >
0 commit comments