changenow

package module
v0.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 22, 2019 License: MIT Imports: 5 Imported by: 0

README ΒΆ

A Go package for ChangeNOW

Golang wrapper for the ChangeNOW instant coin exchange. Implements API v1.

go get github.com/crypdex/go-changenow

Usage

import "github.com/crypdex/go-changenow"

// Initialize the client
apikey := "gogetone"
client := changenow.New(apikey)

// Make a request (catch your error)
amount, _ := client.MinAmount("XZC")

fmt.Println(amount)
// => 3.37862

This package is currently used in production, but is not yet locked down by version and is subject to change.

Implemention Status (v1)

Contributing

  • Fork the repo
  • Add desired functionality
  • Issue a Pull Request

Better testing with mocks needs to be written.

🐞 Bugs

If you find a problem with the lib, please submit an issue.

Documentation ΒΆ

Index ΒΆ

Constants ΒΆ

View Source
const (
	Waiting    string = "waiting"
	Confirming        = "confirming"
	Sending           = "sending"
	Finished          = "finished"
	Expired           = "expired"
)

Statuses

Variables ΒΆ

This section is empty.

Functions ΒΆ

This section is empty.

Types ΒΆ

type ChangeNow ΒΆ

type ChangeNow struct {
	// contains filtered or unexported fields
}

ChangeNow is the root client object

func New ΒΆ

func New(apikey string) *ChangeNow

New creates a configured instance of ChangeNow

func (*ChangeNow) AvailablePairs ΒΆ

func (c *ChangeNow) AvailablePairs() (map[string]*Pair, error)

AvailablePairs ... GET /api/v1/market-info/available-pairs/ This function caches all the pairs, subsequent calls will not refresh. Use GetPair to get a single pair after you've called this. WARNING: NOT THREAD SAFE!

func (*ChangeNow) CreateTransaction ΒΆ

func (c *ChangeNow) CreateTransaction(request *TransactionRequest) (*Transaction, error)

CreateTransaction ... POST /api/v1/transactions/:api_key Errors encountered: - not_valid_params - cannot_create_transaction (when pair is not available?) - not_valid_address - out_of_range

func (*ChangeNow) Currencies ΒΆ

func (c *ChangeNow) Currencies() ([]*Currency, error)

Currencies ... GET /currencies

func (*ChangeNow) CurrenciesTo ΒΆ

func (c *ChangeNow) CurrenciesTo(ticker string) ([]*Currency, error)

CurrenciesTo ... /currencies-to/:ticker List of available currencies for specific currency This API endpoint returns the list of available currencies. Some currencies get enabled or disabled from time to time, so make sure to refresh the list occasionally.

func (*ChangeNow) CurrencyInfo ΒΆ

func (c *ChangeNow) CurrencyInfo(ticker string) (*CurrencyInfo, error)

CurrencyInfo ... GET /currencies/:ticker

func (*ChangeNow) EstimatedExchangeAmount ΒΆ

func (c *ChangeNow) EstimatedExchangeAmount(amount float64, source, target string) (*EstimatedExchangeAmount, error)

EstimatedExchangeAmount ... GET /exchange-amount/:send_amount/:from_to

func (*ChangeNow) GetPair ΒΆ added in v0.0.3

func (c *ChangeNow) GetPair(from, to string) (*Pair, error)

GetPair returns a matching pair or error if an invalid pair

func (*ChangeNow) ListTransactions ΒΆ

func (c *ChangeNow) ListTransactions() ([]*TransactionDetails, error)

ListTransactions ... GET /api/v1/transactions/:api_key

func (*ChangeNow) MinAmount ΒΆ

func (c *ChangeNow) MinAmount(source, target string) (float64, error)

MinAmount ... GET /min-amount/:from_to This func is the one that mentions if the pair is inactive

func (*ChangeNow) TransactionStatus ΒΆ

func (c *ChangeNow) TransactionStatus(id string) (*TransactionDetails, error)

TransactionStatus ... GET /api/v1/transactions/:id/:api_key

type Currency ΒΆ

type Currency struct {
	Ticker            string `json:"ticker"`
	Image             string `json:"image"`
	HasExternalID     bool   `json:"hasExternalId"`
	IsFiat            bool   `json:"isFiat"`
	SupportsFixedRate bool   `json:"supportsFixedRate"`
	Featured          bool   `json:"featured"`
}

Currency response

type CurrencyInfo ΒΆ

type CurrencyInfo struct {
	Name           string `json:"name"`
	Image          string `json:"image"`
	WarningMessage string `json:"warningMessage"`
	HasExternalID  bool   `json:"hasExternalId"`
	IsFiat         bool   `json:"isFiat"`
	IsAnonymous    bool   `json:"isAnonymous"`
	Wallets        struct {
		Primary []struct {
			Name     string `json:"name"`
			URL      string `json:"url"`
			ImageURL string `json:"imageUrl"`
		} `json:"primary"`
	} `json:"wallets"`
}

CurrencyInfo response

type EstimatedExchangeAmount ΒΆ

type EstimatedExchangeAmount struct {
	EstimatedAmount          float64 `json:"estimatedAmount"`
	TransactionSpeedForecast string  `json:"transactionSpeedForecast"`
	WarningMessage           string  `json:"warningMessage"`
}

EstimatedExchangeAmount response

type MinAmount ΒΆ

type MinAmount struct {
	Amount float64 `json:"minAmount"`
}

MinAmount response

type Pair ΒΆ

type Pair struct {
	Name      string
	Source    string
	Target    string
	MinAmount float64
	IsActive  bool
}

func NewPair ΒΆ

func NewPair(name string) *Pair

type RequestError ΒΆ

type RequestError struct {
	Message string `json:"error"`
}

RequestError embeds in all responses Some responses from ChangeNow have an "error" instead.

func (*RequestError) Error ΒΆ

func (e *RequestError) Error() string

func (*RequestError) IsError ΒΆ

func (e *RequestError) IsError() bool

type Transaction ΒΆ

type Transaction struct {
	// Base fields (create transaction)
	ID            string `json:"id"`
	PayinAddress  string `json:"payinAddress"`
	PayoutAddress string `json:"payoutAddress"`
	PayinExtraID  string `json:"payinExtraId"`
	FromCurrency  string `json:"fromCurrency"`
	ToCurrency    string `json:"toCurrency"`
	RefundAddress string `json:"refundAddress"`
}

Transaction ...

type TransactionDetails ΒΆ

type TransactionDetails struct {
	ID            string  `json:"id"`
	PayinAddress  string  `json:"payinAddress"`
	PayoutAddress string  `json:"payoutAddress"`
	PayinExtraID  string  `json:"payinExtraId"`
	FromCurrency  string  `json:"fromCurrency"`
	ToCurrency    string  `json:"toCurrency"`
	Status        string  `json:"status"`
	Hash          string  `json:"hash"`
	PayinHash     string  `json:"payinHash"`
	PayoutHash    string  `json:"payoutHash"`
	AmountSend    float64 `json:"amountSend"`
	AmountReceive float64 `json:"amountReceive"`
	NetworkFee    float64 `json:"networkFee"`
	UpdatedAt     string  `json:"updatedAt"`
}

TransactionDetails ...

type TransactionRequest ΒΆ

type TransactionRequest struct {
	From          string  `json:"from"`                    // from (Required): Ticker of a currency you want to send
	To            string  `json:"to"`                      // to (Required): Ticker of a currency you want to receive
	Address       string  `json:"address"`                 // address (Required): Address to receive a currency
	Amount        float64 `json:"amount"`                  // amount (Required): Amount you want to exchange
	ExtraID       string  `json:"extraId,omitempty"`       // extraId (Optional): Extra Id for currencies that require it
	RefundAddress string  `json:"refundAddress,omitempty"` // refundAddress (Optional): Refund address
}

TransactionRequest request

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL