Skip to content

Commit b2f252a

Browse files
authored
fix(go): add reload option to loadMarkets (ccxt#26120)
* fix(go): add reload option to loadMarkets * update imports * fix imports
1 parent 5679383 commit b2f252a

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

go/v4/exchange.go

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,15 @@ func (this *Exchange) InitThrottler() {
246246
this.Throttler = NewThrottler(this.TokenBucket)
247247
}
248248

249+
/*
250+
*
251+
- @method
252+
- @name Exchange#loadMarkets
253+
- @description Loads and prepares the markets for trading.
254+
- @param {boolean} param.reload - If true, the markets will be reloaded from the exchange.
255+
- @param {object} params - Additional exchange-specific parameters for the request.
256+
- @throws An error if the markets cannot be loaded or prepared.
257+
*/
249258
func (this *Exchange) LoadMarkets(params ...interface{}) <-chan interface{} {
250259
ch := make(chan interface{})
251260

@@ -256,28 +265,31 @@ func (this *Exchange) LoadMarkets(params ...interface{}) <-chan interface{} {
256265
ch <- "panic:" + ToString(r)
257266
}
258267
}()
268+
reload := GetArg(params, 0, false).(bool)
269+
params := GetArg(params, 1, map[string]interface{}{})
259270
this.WarmUpCache()
260-
if this.Markets != nil && len(this.Markets) > 0 {
261-
if this.Markets_by_id == nil && len(this.Markets) > 0 {
262-
// Only lock when writing
263-
this.marketsMutex.Lock()
264-
result := this.SetMarkets(this.Markets, nil)
265-
this.marketsMutex.Unlock()
266-
ch <- result
271+
if !reload {
272+
if this.Markets != nil && len(this.Markets) > 0 {
273+
if this.Markets_by_id == nil && len(this.Markets) > 0 {
274+
// Only lock when writing
275+
this.marketsMutex.Lock()
276+
result := this.SetMarkets(this.Markets, nil)
277+
this.marketsMutex.Unlock()
278+
ch <- result
279+
return
280+
}
281+
ch <- this.Markets
267282
return
268283
}
269-
ch <- this.Markets
270-
return
271284
}
272285

273286
var currencies interface{} = nil
274-
var defaultParams = map[string]interface{}{}
275287
hasFetchCurrencies := this.Has["fetchCurrencies"]
276288
if IsBool(hasFetchCurrencies) && IsTrue(hasFetchCurrencies) {
277-
currencies = <-this.DerivedExchange.FetchCurrencies(defaultParams)
289+
currencies = <-this.DerivedExchange.FetchCurrencies(params)
278290
}
279291

280-
markets := <-this.DerivedExchange.FetchMarkets(defaultParams)
292+
markets := <-this.DerivedExchange.FetchMarkets(params)
281293
PanicOnError(markets)
282294

283295
// Lock only for writing

0 commit comments

Comments
 (0)