@@ -127,7 +127,8 @@ func (m *Mock) GetCurrentMarketsTonPrice() ([]Market, error) {
127
127
},
128
128
}
129
129
for idx , market := range markets {
130
- respBody , err := sendRequest (market .URL , "" )
130
+ headers := http.Header {"Content-Type" : {"application/json" }}
131
+ respBody , err := sendRequest (market .URL , "" , headers )
131
132
if err != nil {
132
133
slog .Error ("[GetCurrentMarketsTonPrice] failed to send request" , slog .Any ("error" , err ))
133
134
errorsCounter .WithLabelValues (market .Name ).Inc ()
@@ -290,7 +291,8 @@ func getFiatPrices(tonPrice float64) map[string]float64 {
290
291
}
291
292
prices := make (map [string ]float64 )
292
293
for _ , market := range markets {
293
- respBody , err := sendRequest (market .URL , "" )
294
+ headers := http.Header {"Content-Type" : {"application/json" }}
295
+ respBody , err := sendRequest (market .URL , "" , headers )
294
296
if err != nil {
295
297
slog .Error ("[getFiatPrices] failed to send request" , slog .Any ("error" , err ))
296
298
errorsCounter .WithLabelValues (market .Name ).Inc ()
@@ -372,7 +374,8 @@ func (m *Mock) getJettonPricesFromDex(pools map[ton.AccountID]float64) map[ton.A
372
374
var actualLpAssets []LpAsset
373
375
// Fetch and parse pool data from each market
374
376
for _ , market := range markets {
375
- respBody , err := sendRequest (market .URL , "" )
377
+ headers := http.Header {"Accept" : {"text/csv" }}
378
+ respBody , err := sendRequest (market .URL , "" , headers )
376
379
if err != nil {
377
380
slog .Error ("[getJettonPricesFromDex] failed to send request" , slog .Any ("error" , err ), slog .String ("url" , market .URL ))
378
381
errorsCounter .WithLabelValues (market .Name ).Inc ()
@@ -451,23 +454,27 @@ func convertedStonFiPoolResponse(respBody []byte) ([]Assets, []LpAsset, error) {
451
454
return Assets {}, err
452
455
}
453
456
firstMeta := make (map [string ]any )
454
- if err = json .Unmarshal ([]byte (record [4 ]), & firstMeta ); err != nil {
455
- return Assets {}, err
457
+ if record [4 ] != "NULL" {
458
+ if err = json .Unmarshal ([]byte (record [4 ]), & firstMeta ); err != nil {
459
+ return Assets {}, err
460
+ }
456
461
}
457
462
value , ok := firstMeta ["decimals" ]
458
- if ! ok {
463
+ if ! ok || value != "NaN" {
459
464
value = fmt .Sprintf ("%d" , defaultDecimals )
460
465
}
461
466
firstAsset .Decimals , err = strconv .Atoi (value .(string ))
462
467
if err != nil {
463
468
return Assets {}, err
464
469
}
465
470
secondMeta := make (map [string ]any )
466
- if err = json .Unmarshal ([]byte (record [5 ]), & secondMeta ); err != nil {
467
- return Assets {}, err
471
+ if record [5 ] != "NULL" {
472
+ if err = json .Unmarshal ([]byte (record [5 ]), & secondMeta ); err != nil {
473
+ return Assets {}, err
474
+ }
468
475
}
469
476
value , ok = secondMeta ["decimals" ]
470
- if ! ok {
477
+ if ! ok || value != "NaN" {
471
478
value = fmt .Sprintf ("%d" , defaultDecimals )
472
479
}
473
480
secondAsset .Decimals , err = strconv .Atoi (value .(string ))
@@ -515,7 +522,7 @@ func convertedStonFiPoolResponse(respBody []byte) ([]Assets, []LpAsset, error) {
515
522
}
516
523
assets , err := parseAssets (record )
517
524
if err != nil {
518
- slog .Error ("failed to parse assets" , slog .Any ("error" , err ))
525
+ slog .Error ("failed to parse assets" , slog .Any ("error" , err ), slog . Any ( "assets" , record ) )
519
526
continue
520
527
}
521
528
firstAsset , secondAsset := assets .Assets [0 ], assets .Assets [1 ]
@@ -554,8 +561,8 @@ func convertedDeDustPoolResponse(respBody []byte) ([]Assets, []LpAsset, error) {
554
561
return 0 , err
555
562
}
556
563
value , ok := converted ["decimals" ]
557
- if ! ok {
558
- value = "9"
564
+ if ! ok || value == "NaN" {
565
+ value = fmt . Sprintf ( "%d" , defaultDecimals )
559
566
}
560
567
decimals , err := strconv .Atoi (value .(string ))
561
568
if err != nil {
@@ -787,15 +794,15 @@ func calculatePoolPrice(firstAsset, secondAsset Asset, pools map[ton.AccountID]f
787
794
return calculatedAccount , price
788
795
}
789
796
790
- func sendRequest (url , token string ) ([]byte , error ) {
797
+ func sendRequest (url , token string , headers http. Header ) ([]byte , error ) {
791
798
ctx , cancel := context .WithTimeout (context .Background (), time .Second * 15 )
792
799
defer cancel ()
793
800
794
801
req , err := http .NewRequestWithContext (ctx , http .MethodGet , url , nil )
795
802
if err != nil {
796
803
return nil , err
797
804
}
798
- req .Header . Set ( "Content-Type" , "application/json" )
805
+ req .Header = headers
799
806
if token != "" {
800
807
req .Header .Set ("Authorization" , fmt .Sprintf ("Bearer %v" , token ))
801
808
}
0 commit comments