@@ -15,12 +15,7 @@ type CaseItem struct {
1515 Run func (e * BarEnv ) float64
1616}
1717
18- var env = & BarEnv {
19- TimeFrame : "1d" ,
20- TFMSecs : 86400000 ,
21- Exchange : "binance" ,
22- MarketType : "future" ,
23- }
18+ var env , _ = NewBarEnv ("binance" , "spot" , "" , "1d" )
2419
2520func runIndCases (t * testing.T , items []CaseItem ) {
2621 var fails = make (map [string ]int )
@@ -141,23 +136,18 @@ func TestSeries(t *testing.T) {
141136
142137// TestConcurrent 测试多线程并发访问
143138func TestConcurrent (t * testing.T ) {
144- testEnv := & BarEnv {
145- TimeFrame : "1d" ,
146- TFMSecs : 86400000 ,
147- Exchange : "binance" ,
148- MarketType : "future" ,
149- }
150-
139+ testEnv , _ := NewBarEnv ("binance" , "spot" , "" , "1d" )
140+
151141 // 先加载一些数据
152142 for i := 0 ; i < 20 ; i ++ {
153143 k := DataKline [i ]
154144 testEnv .OnBar (k .Time , k .Open , k .High , k .Low , k .Close , k .Volume , k .Info )
155145 }
156-
146+
157147 // 并发读取和计算
158148 var wg sync.WaitGroup
159149 goroutineNum := 10
160-
150+
161151 for i := 0 ; i < goroutineNum ; i ++ {
162152 wg .Add (1 )
163153 go func () {
@@ -166,21 +156,21 @@ func TestConcurrent(t *testing.T) {
166156 _ = testEnv .Close .Get (0 )
167157 _ = testEnv .High .Get (1 )
168158 _ = testEnv .Low .Get (2 )
169-
159+
170160 // 测试计算操作
171161 _ = testEnv .Close .Add (100 ).Get (0 )
172162 _ = testEnv .Close .Sub (50 ).Get (0 )
173163 _ = testEnv .Close .Mul (1.1 ).Get (0 )
174164 _ = testEnv .High .Sub (testEnv .Low ).Abs ().Get (0 )
175-
165+
176166 // 测试交叉计算
177167 _ = testEnv .Close .Cross (30000 )
178-
168+
179169 // 测试范围操作
180170 _ = testEnv .Close .Range (0 , 5 )
181171 }()
182172 }
183-
173+
184174 wg .Wait ()
185175 t .Log ("Concurrent test passed" )
186176}
0 commit comments