Skip to content

Commit

Permalink
chore: remove exchange
Browse files Browse the repository at this point in the history
  • Loading branch information
totanvix committed Nov 29, 2023
1 parent b2d5887 commit cf5707f
Showing 1 changed file with 1 addition and 33 deletions.
34 changes: 1 addition & 33 deletions utils/bitcoin/bitcoin.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (

func GetBitcoinPrice() (string, error) {
acUsd := accounting.Accounting{Symbol: "$", Precision: 2}
acVnd := accounting.Accounting{Symbol: "", Precision: 0, Thousand: "."}

btc, err := getCurrentPrice()
if err != nil {
Expand All @@ -26,14 +25,8 @@ func GetBitcoinPrice() (string, error) {
}

usd := acUsd.FormatMoney(p)
v, err := exchangeUsdToVnd(p)
if err != nil {
return "", err
}

vnd := acVnd.FormatMoney(*v) + " đ"

return fmt.Sprintf("1 Bitcoin = %s (<b>%s</b>)", usd, vnd), nil
return fmt.Sprintf("1 Bitcoin = %s", usd), nil
}

func getCurrentPrice() (*structs.Btc, error) {
Expand All @@ -58,28 +51,3 @@ func getCurrentPrice() (*structs.Btc, error) {

return &data, nil
}

func exchangeUsdToVnd(p float64) (*float64, error) {
price := fmt.Sprintf("%.2f", p)

res, err := http.Get("https://api.exchangerate.host/convert?from=USD&to=VND&amount=" + price)
if err != nil {
return nil, err
}

defer res.Body.Close()

body, err := ioutil.ReadAll(res.Body)
if err != nil {
return nil, err
}

var data structs.Exchange

err = json.Unmarshal(body, &data)
if err != nil {
return nil, err
}

return &data.Result, nil
}

0 comments on commit cf5707f

Please sign in to comment.