Skip to content
This repository has been archived by the owner on Dec 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #113 from codewc/master
Browse files Browse the repository at this point in the history
add `GET /api/v2/currencies/{currency}` endpoint
  • Loading branch information
1bazinga25 authored Dec 3, 2021
2 parents 697313a + 57dbc15 commit 3d9e646
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 2 deletions.
35 changes: 35 additions & 0 deletions currency.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func (as *ApiService) Currencies() (*ApiResponse, error) {
}

// Currency returns the details of the currency.
// Deprecated: Use CurrencyV2 instead.
func (as *ApiService) Currency(currency string, chain string) (*ApiResponse, error) {
params := map[string]string{}
if chain != "" {
Expand All @@ -39,6 +40,40 @@ func (as *ApiService) Currency(currency string, chain string) (*ApiResponse, err
return as.Call(req)
}

// ChainsModel Chains Model
type ChainsModel struct {
ChainName string `json:"chainName"`
WithdrawalMinSize string `json:"withdrawalMinSize"`
WithdrawalMinFee string `json:"withdrawalMinFee"`
IsWithdrawEnabled bool `json:"isWithdrawEnabled"`
IsDepositEnabled bool `json:"isDepositEnabled"`
Confirms int64 `json:"confirms"`
ContractAddress string `json:"contractAddress"`
}

// CurrencyV2Model CurrencyV2 Model
type CurrencyV2Model struct {
Name string `json:"name"`
Currency string `json:"currency"`
FullName string `json:"fullName"`
Precision uint8 `json:"precision"`
Confirms int64 `json:"confirms"`
ContractAddress string `json:"contractAddress"`
IsMarginEnabled bool `json:"isMarginEnabled"`
IsDebitEnabled bool `json:"isDebitEnabled"`
Chains []*ChainsModel `json:"chains"`
}

// CurrencyV2 returns the details of the currency.
func (as *ApiService) CurrencyV2(currency string, chain string) (*ApiResponse, error) {
params := map[string]string{}
if chain != "" {
params["chain"] = chain
}
req := NewRequest(http.MethodGet, "/api/v2/currencies/"+currency, params)
return as.Call(req)
}

type PricesModel map[string]string

// Prices returns the fiat prices for currency.
Expand Down
21 changes: 21 additions & 0 deletions currency_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,27 @@ func TestApiService_Currency(t *testing.T) {
}
}

func TestApiService_Currency_V2(t *testing.T) {
s := NewApiServiceFromEnv()
rsp, err := s.CurrencyV2("BTC", "")
if err != nil {
t.Fatal(err)
}
c := &CurrencyV2Model{}
if err := rsp.ReadData(c); err != nil {
t.Fatal(err)
}
t.Log(ToJsonString(c))
switch {
case c.Name == "":
t.Error("Empty key 'name'")
case c.Currency == "":
t.Error("Empty key 'currency'")
case c.FullName == "":
t.Error("Empty key 'fullName'")
}
}

func TestApiService_Prices(t *testing.T) {
s := NewApiServiceFromEnv()
rsp, err := s.Prices("USD", "BTC,KCS")
Expand Down
4 changes: 2 additions & 2 deletions order.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type CreateOrderModel struct {
Price string `json:"price,omitempty"`
Size string `json:"size,omitempty"`
TimeInForce string `json:"timeInForce,omitempty"`
CancelAfter uint64 `json:"cancelAfter,omitempty"`
CancelAfter int64 `json:"cancelAfter,omitempty"`
PostOnly bool `json:"postOnly,omitempty"`
Hidden bool `json:"hidden,omitempty"`
IceBerg bool `json:"iceberg,omitempty"`
Expand Down Expand Up @@ -113,7 +113,7 @@ type OrderModel struct {
Hidden bool `json:"hidden"`
IceBerg bool `json:"iceberg"`
VisibleSize string `json:"visibleSize"`
CancelAfter uint64 `json:"cancelAfter"`
CancelAfter int64 `json:"cancelAfter"`
Channel string `json:"channel"`
ClientOid string `json:"clientOid"`
Remark string `json:"remark"`
Expand Down

0 comments on commit 3d9e646

Please sign in to comment.