@@ -127,7 +127,8 @@ func (m *Mock) GetCurrentMarketsTonPrice() ([]Market, error) {
127127 },
128128 }
129129 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 )
131132 if err != nil {
132133 slog .Error ("[GetCurrentMarketsTonPrice] failed to send request" , slog .Any ("error" , err ))
133134 errorsCounter .WithLabelValues (market .Name ).Inc ()
@@ -290,7 +291,8 @@ func getFiatPrices(tonPrice float64) map[string]float64 {
290291 }
291292 prices := make (map [string ]float64 )
292293 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 )
294296 if err != nil {
295297 slog .Error ("[getFiatPrices] failed to send request" , slog .Any ("error" , err ))
296298 errorsCounter .WithLabelValues (market .Name ).Inc ()
@@ -372,7 +374,8 @@ func (m *Mock) getJettonPricesFromDex(pools map[ton.AccountID]float64) map[ton.A
372374 var actualLpAssets []LpAsset
373375 // Fetch and parse pool data from each market
374376 for _ , market := range markets {
375- respBody , err := sendRequest (market .URL , "" )
377+ headers := http.Header {"Accept" : {"text/csv" }}
378+ respBody , err := sendRequest (market .URL , "" , headers )
376379 if err != nil {
377380 slog .Error ("[getJettonPricesFromDex] failed to send request" , slog .Any ("error" , err ), slog .String ("url" , market .URL ))
378381 errorsCounter .WithLabelValues (market .Name ).Inc ()
@@ -451,23 +454,27 @@ func convertedStonFiPoolResponse(respBody []byte) ([]Assets, []LpAsset, error) {
451454 return Assets {}, err
452455 }
453456 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+ }
456461 }
457462 value , ok := firstMeta ["decimals" ]
458- if ! ok {
463+ if ! ok || value != "NaN" {
459464 value = fmt .Sprintf ("%d" , defaultDecimals )
460465 }
461466 firstAsset .Decimals , err = strconv .Atoi (value .(string ))
462467 if err != nil {
463468 return Assets {}, err
464469 }
465470 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+ }
468475 }
469476 value , ok = secondMeta ["decimals" ]
470- if ! ok {
477+ if ! ok || value != "NaN" {
471478 value = fmt .Sprintf ("%d" , defaultDecimals )
472479 }
473480 secondAsset .Decimals , err = strconv .Atoi (value .(string ))
@@ -515,7 +522,7 @@ func convertedStonFiPoolResponse(respBody []byte) ([]Assets, []LpAsset, error) {
515522 }
516523 assets , err := parseAssets (record )
517524 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 ) )
519526 continue
520527 }
521528 firstAsset , secondAsset := assets .Assets [0 ], assets .Assets [1 ]
@@ -554,8 +561,8 @@ func convertedDeDustPoolResponse(respBody []byte) ([]Assets, []LpAsset, error) {
554561 return 0 , err
555562 }
556563 value , ok := converted ["decimals" ]
557- if ! ok {
558- value = "9"
564+ if ! ok || value == "NaN" {
565+ value = fmt . Sprintf ( "%d" , defaultDecimals )
559566 }
560567 decimals , err := strconv .Atoi (value .(string ))
561568 if err != nil {
@@ -787,15 +794,15 @@ func calculatePoolPrice(firstAsset, secondAsset Asset, pools map[ton.AccountID]f
787794 return calculatedAccount , price
788795}
789796
790- func sendRequest (url , token string ) ([]byte , error ) {
791- ctx , cancel := context .WithTimeout (context .Background (), time .Second * 15 )
797+ func sendRequest (url , token string , headers http. Header ) ([]byte , error ) {
798+ ctx , cancel := context .WithTimeout (context .Background (), time .Minute )
792799 defer cancel ()
793800
794801 req , err := http .NewRequestWithContext (ctx , http .MethodGet , url , nil )
795802 if err != nil {
796803 return nil , err
797804 }
798- req .Header . Set ( "Content-Type" , "application/json" )
805+ req .Header = headers
799806 if token != "" {
800807 req .Header .Set ("Authorization" , fmt .Sprintf ("Bearer %v" , token ))
801808 }
0 commit comments