forked from adshao/go-binance
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6b8abfb
commit 3c484bb
Showing
4 changed files
with
56 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package binance | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"io" | ||
"net/http" | ||
) | ||
|
||
type AllCoinService struct { | ||
c *Client | ||
} | ||
|
||
type AllCoinResponse struct { | ||
Code string `json:"code"` | ||
Message string `json:"message"` | ||
MessageDetail string `json:"messageDetail"` | ||
Data []CoinInfo `json:"data"` | ||
Success bool `json:"success"` | ||
} | ||
|
||
func (s *AllCoinService) Do(ctx context.Context) ([]CoinInfo, error) { | ||
var endpoint string = "https://www.binance.com/bapi/capital/v1/public/capital/getNetworkCoinAll" | ||
req, err := http.NewRequest(http.MethodGet, endpoint, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
resp, err := http.DefaultClient.Do(req) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer resp.Body.Close() | ||
|
||
bb, err := io.ReadAll(resp.Body) | ||
if err != nil { | ||
return nil, err | ||
} | ||
res := AllCoinResponse{} | ||
if err = json.Unmarshal(bb, &res); err != nil { | ||
return nil, err | ||
} | ||
if !res.Success { | ||
return nil, fmt.Errorf("%s", res.MessageDetail) | ||
} | ||
return res.Data, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters