shapeshift

package module
v0.0.0-...-75f7320 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2018 License: MIT Imports: 6 Imported by: 2

README

shapeshift api golang

ShapeShift in Go Language

Build Status Coverage Status GoDoc Go Report Card

This Go Language Package will allow you to use the ShapeShift API and convert your cryptocurrencies in your very own application. It includes most of the ShapeShift API requests listed on their references website. Below you'll find a perfect example of a new ShapeShift transaction.

go get -u github.com/hunterlong/shapeshift
get the most up to date version
import "github.com/hunterlong/shapeshift"

Once you've imported shapeshift into your golang project, you can use any of the requests below. Checkout the Travis CI test logs for responses of each function. See an issue? PR it!


🆕 New ShapeShift Transaction

I want to convert Ethereum to Bitcoin. The 'ToAddress' is my Bitcoin address. Once I run this, I'll get a Ethereum address from ShapeShift.

new := shapeshift.New{
	Pair: "eth_btc",
	ToAddress: "16FdfRFVPUwiKAceRSqgEfn1tmB4sVUmLh",
	// FromAddress: "0xcf2f204aC8D7714990912fA422874371c001217D",  (Optional Return To Ethereum Address)
       }

response, err := new.Shift()

if err != nil {
    panic(error)
}

if response.isOk() {

    sendToAddress := response.SendTo
    // i will send Ether to this address

    fmt.Println("Send To Address: ", sendToAddress)
    fmt.Println("Send Type: ", response.SendType)
    fmt.Println("Receiving at Address: ", response.ReturnTo)
    fmt.Println("Receiving Type: ", response.ReturnType)
    fmt.Println("Send Type: ", response.SendType)
    fmt.Println("API Key: ", response.ApiKey)
    fmt.Println("Public Data: ", response.Public)
    fmt.Println("XrpDestTag: ", response.XrpDestTag)

} else {
    fmt.Println(response.ErrorMsg())
}

🔁 Get Status of Transaction

Once I sent some Ethereum to the given Ethereum address, I want to check the status of my ShapeShift transaction by inserting the Etheruem address 'sendToAddress' that ShapeShift gave me in previous function.

var newTransactionId string

status, err := shapeshift.DepositStatus(sendToAddress)

if err != nil {
    panic(err)
}

if !response.isOk() {
    fmt.Println(status.ErrorMsg())
}

fmt.Println(status.Status)
// no_deposits
// received
// complete
// failed

if status.Status == "complete" {
	fmt.Println("Incoming Coin: ", status.IncomingCoin)
	fmt.Println("Incoming Type: ", status.IncomingType)
	fmt.Println("Outgoing Coin: ", status.OutgoingCoin)
	fmt.Println("Outgoing Type: ", status.OutgoingType)
	fmt.Println("Address: ", status.Address)
	fmt.Println("Transaction ID: ", status.Transaction)
	fmt.Println("Withdraw: ", status.Withdraw)
	
	newTransactionId = status.Transaction
	// saving transaction ID so i can send a receipt
}

⏫ Send an Email Receipt

Want to send a receipt of this transaction? Just include an email address and the transaction ID affiliated with the ShapeShift transaction.

receipt := shapeshift.Receipt{
	Email:         "user@myemailer.com",
	TransactionID: newTransactionId,
     }

response, err := receipt.Send()

if err != nil {
    panic(err)
}

if response.isOk() {
    fmt.Println("Receipt was sent to user")
} else {
    fmt.Println(status.ErrorMsg())
}


Additional Functions

The other ShapeShift API requests are available for you to use.

✅ Get Rate

Gets the current rate offered by Shapeshift. This is an estimate because the rate can occasionally change rapidly depending on the markets. The rate is also a 'use-able' rate not a direct market rate. Meaning multiplying your input coin amount times the rate should give you a close approximation of what will be sent out. This rate does not include the transaction (miner) fee taken off every transaction.

pair := shapeshift.Pair{"eth_btc"}

rate, err := pair.GetRates()

if err != nil {
    panic(err)
}


fmt.Println("Rate: ", rate)

✅ Deposit Limits

Gets the current deposit limit set by Shapeshift. Amounts deposited over this limit will be sent to the return address if one was entered, otherwise the user will need to contact ShapeShift support to retrieve their coins. This is an estimate because a sudden market swing could move the limit.

pair := shapeshift.Pair{"eth_btc"}
limits, err := pair.GetLimits()

if err != nil {
    panic(err)
}

fmt.Println("Limit: ", limits)

✅ Market Info

This gets the market info (pair, rate, limit, minimum limit, miner fee)

pair := shapeshift.Pair{"btc_eth"}
info, err := pair.GetInfo()

if err != nil {
    panic(err)
}

fmt.Println("Pair: ", info.Pair)
fmt.Println("Min: ", info.Min)
fmt.Println("Miner Fee: ", info.MinerFee)
fmt.Println("Limit: ", info.Limit)
fmt.Println("Rate: ", info.Rate)

✅ Recent Transactions
recent, err := shapeshift.RecentTransactions("5")

if err != nil {
    panic(err)
}

for _, v := range recent {
    fmt.Println("In: ", v.CurIn)
    fmt.Println("Out: ", v.CurOut)
    fmt.Println("Amount: ", v.Amount)
    fmt.Println("Timestamp: ", v.Timestamp)
    fmt.Println("-------------------------------")
}

✅ Deposit Address Status

This returns the status of the most recent deposit transaction to the address.

status, err := shapeshift.DepositStatus("1JP7QWC9GbpKEHSvefygWk5woFy9xeQHKc")

if err != nil {
    panic(err)
}

fmt.Println("Deposit Status: ", status.Status)
fmt.Println("Incoming Coin: ", status.IncomingCoin)
fmt.Println("Incoming Type: ", status.IncomingType)
fmt.Println("Outgoing Coin: ", status.OutgoingCoin)
fmt.Println("Outgoing Type: ", status.OutgoingType)
fmt.Println("Address: ", status.Address)
fmt.Println("Transaction ID: ", status.Transaction)
fmt.Println("Withdraw: ", status.Withdraw)

✅ Time Remaining on Fixed Transaction Amount

Get a list of the most recent transactions.

status, err := shapeshift.TimeRemaining("16FdfRFVPUwiKAceRSqgEfn1tmB4sVUmLh")

if err != nil {
    panic(err)
}

fmt.Println(status.Status)

✅ Get Available Coins

Allows anyone to get a list of all the currencies that Shapeshift currently supports at any given time. The list will include the name, symbol, availability status, and an icon link for each.

coins, err := shapeshift.Coins()

if err != nil {
    panic(err)
}

eth := coins.ETH
fmt.Println("Coin: ", eth.Name)
fmt.Println("Status: ", eth.Status)

✅ Validate Address with Coin Symbol

Allows user to verify that their receiving address is a valid address according to a given wallet daemon. If isvalid returns true, this address is valid according to the coin daemon indicated by the currency symbol.

address, err := shapeshift.Validate("16FdfRFVPUwiKAceRSqgEfn1tmB4sVUmLh", "btc")

if err != nil {
    panic(err)
}

fmt.Println("Address is: ", address.Valid)
fmt.Println("Error: ",address.Error)

Primary Requests

✅ Create New Transaction

This is the primary data input into ShapeShift.

new := shapeshift.New{
		Pair:        "eth_btc",
		ToAddress:   "16FdfRFVPUwiKAceRSqgEfn1tmB4sVUmLh",
		FromAddress: "0xcf2f204aC8D7714990912fA422874371c001217D",
	}

response, err := new.Shift()

if err != nil {
    panic(err)
}

fmt.Println("Send To Address: ", response.SendTo)
fmt.Println("Send Type: ", response.SendType)
fmt.Println("Receiving at Address: ", response.ReturnTo)
fmt.Println("Receiving Type: ", response.ReturnType)
fmt.Println("Send Type: ", response.SendType)
fmt.Println("API Key: ", response.ApiKey)
fmt.Println("Public Data: ", response.Public)
fmt.Println("XrpDestTag: ", response.XrpDestTag)

✅ Request Email Receipt

This call requests a receipt for a transaction. The email address will be added to the conduit associated with that transaction as well. (Soon it will also send receipts to subsequent transactions on that conduit)

info := shapeshift.Receipt{
		Email: "user@awesome.com",
		TransactionID: "owkdwodkkwokdwdw",
	}

response, err := info.Send();

if err != nil {
    panic(err)
}

fmt.Println(response)

✅ Fixed Amount Transaction

When a transaction is created with a fixed amount requested there is a 10 minute window for the deposit. After the 10 minute window if the deposit has not been received the transaction expires and a new one must be created. This api call returns how many seconds are left before the transaction expires. Please note that if the address is a ripple address, it will include the "?dt=destTagNUM" appended on the end, and you will need to use the URIEncodeComponent() function on the address before sending it in as a param, to get a successful response.

new := shapeshift.New{
		Pair: "eth_btc",
		Amount: 0.25,
		ToAddress: "16FdfRFVPUwiKAceRSqgEfn1tmB4sVUmLh",
		FromAddress: "0xcf2f204aC8D7714990912fA422874371c001217D",
	}

response, err := new.FixedShift()

if err != nil {
    panic(err)
}

fmt.Println("Pair: ", response.Pair)
fmt.Println("Quoted Rate: ", response.QuotedRate)
fmt.Println("Deposit Address: ", response.Deposit)
fmt.Println("Deposit Amount: ", response.DepositAmount)
fmt.Println("Withdraw Amount: ", response.WithdrawalAmount)
fmt.Println("Withdraw Address: ", response.Withdrawal)
fmt.Println("Expiration: ", response.Expiration)

✅ Cancel Pending Transaction

This call allows you to request for canceling a pending transaction by the deposit address. If there is fund sent to the deposit address, this pending transaction cannot be canceled.

old := shapeshift.Address{
		Id: newSendToAddress,
	}

	response, err := old.Cancel()

	if err != nil {
        panic(err)
    }


API Key Required Requests

✅ Get Transactions from Private API Key

Allows vendors to get a list of all transactions that have ever been done using a specific API key. Transactions are created with an affilliate PUBLIC KEY, but they are looked up using the linked PRIVATE KEY, to protect the privacy of our affiliates' account details.

api := shapeshift.API{
		Key: "oskdfoijsfuhsdhufhewhuf",
	   }

list, err := api.ListTransactions()

if err != nil {
    panic(err)
}

for _,v := range list.Transactions {
    fmt.Println("Input: ",v.InputAddress)
    fmt.Println("Amount: ",v.InputAmount)
}
there was no way for me to test this transaction since i'm not a vendor

✅ Get Transactions from Output Address

Allows vendors to get a list of all transactions that have ever been sent to one of their addresses. The affilliate's PRIVATE KEY must be provided, and will only return transactions that were sent to output address AND were created using / linked to the affiliate's PUBLIC KEY. Please note that if the address is a ripple address and it includes the "?dt=destTagNUM" appended on the end, you will need to use the URIEncodeComponent() function on the address before sending it in as a param, to get a successful response.

api := shapeshift.API{
		Key: "oskdfoijsfuhsdhufhewhuf",
		Address: "1JP7QWC9GbpKEHSvefygWk5woFy9xeQHKc",
	}

list, err := api.ListTransactions()

if err != nil {
    panic(err)
}

for _,v := range list.Transactions {
    fmt.Println("Input: ",v.InputAddress)
    fmt.Println("Amount: ",v.InputAmount)
}
there was no way for me to test this transaction since i'm not a vendor

Coin Pairs

Many of the requests require a 'coin pair'. A coin pair is of the format deposit_withdrawal. Example: 'btc_ltc'. Valid pairs are any combination of the below listed valid coins.* The list will grow as we add more:

btc, ltc, ppc, drk, doge, nmc, ftc, blk, nxt, btcd, qrk, rdd, nbt, bts, bitusd, xcp, xmr

ShapeShift Coins

  • If a particular coin goes offline any pairs using it will return a message stating that pair is temporarily unavailable.

All requests are only available via HTTPS, in the interest of security best practices we do not support API calls over HTTP.


Package Useful? 🍺 🐛

If this package saved you some time, or if you're excited to make that next crypto-bot, feel free to throw some coins my way. If you see an issue with this golang package, please submit a pull request.

ETH: 0x9741C5522B85E195B92C71CE29B54A4C99D76c13
BTC: 16FdfRFVPUwiKAceRSqgEfn1tmB4sVUmLh

License

This golang package is built for the cryptocurrency community and is released with MIT license.

👍 👍 ShapeShift.io 👍 👍

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DoHttp

func DoHttp(method string, apimethod string, url string) ([]byte, error)

func DoPostHttp

func DoPostHttp(method string, apimethod string, data interface{}) ([]byte, error)

func ToFloat

func ToFloat(s string) float64

ShapeShift's API responds in float and string for decimals for different functions. Since we arn't really using 'big numbers' I think it's ok to be using this. This golang package is not doing any math, just responding back from ShapeShift API.

Types

type API

type API struct {
	Key     string
	Address string
}

func (API) ListTransactions

func (i API) ListTransactions() ([]Transaction, error)

type Address

type Address struct {
	Id string `json:"address"`
}

func (Address) Cancel

func (n Address) Cancel() (*CancelResponse, error)

type CancelResponse

type CancelResponse struct {
	Success string `json:"success,omitempty"`
	Error
}

type Coin

type Coin struct {
	Name            string `json:"name"`
	Symbol          string `json:"symbol"`
	Status          string `json:"status"`
	Image           string `json:"image,omitempty"`
	SpecialReturn   bool   `json:"specialReturn,omitempty"`
	SpecialOutgoing bool   `json:"specialOutgoing,omitempty"`
	SpecialIncoming bool   `json:"specialIncoming,omitempty"`
	FieldName       string `json:"fieldName,omitempty"`
	FieldKey        string `json:"fieldKey,omitempty"`
	QrName          string `json:"qrName,omitempty"`
}

func CoinsAsList

func CoinsAsList() ([]Coin, error)

type CoinsResponse

type CoinsResponse struct {
	FIRST struct {
		Coin
	} `json:"1ST"`
	ANT struct {
		Coin
	} `json:"ANT"`
	BAT struct {
		Coin
	} `json:"BAT"`
	BCH struct {
		Coin
	} `json:"BCH"`
	BCY struct {
		Coin
	} `json:"BCY"`
	BLK struct {
		Coin
	} `json:"BLK"`
	BNT struct {
		Coin
	} `json:"BNT"`
	BTC struct {
		Coin
	} `json:"BTC"`
	BTCD struct {
		Coin
	} `json:"BTCD"`
	BTG struct {
		Coin
	} `json:"BTG"`
	BTS struct {
		Coin
	} `json:"BTS"`
	CLAM struct {
		Coin
	} `json:"CLAM"`
	CVC struct {
		Coin
	} `json:"CVC"`
	DASH struct {
		Coin
	} `json:"DASH"`
	DCR struct {
		Coin
	} `json:"DCR"`
	DGB struct {
		Coin
	} `json:"DGB"`
	DNT struct {
		Coin
	} `json:"DNT"`
	DOGE struct {
		Coin
	} `json:"DOGE"`
	EDG struct {
		Coin
	} `json:"EDG"`
	EMC struct {
		Coin
	} `json:"EMC"`
	EOS struct {
		Coin
	} `json:"EOS"`
	ETC struct {
		Coin
	} `json:"ETC"`
	ETH struct {
		Coin
	} `json:"ETH"`
	FCT struct {
		Coin
	} `json:"FCT"`
	FUN struct {
		Coin
	} `json:"FUN"`
	GAME struct {
		Coin
	} `json:"GAME"`
	GNO struct {
		Coin
	} `json:"GNO"`
	GNT struct {
		Coin
	} `json:"GNT"`
	GUP struct {
		Coin
	} `json:"GUP"`
	KMD struct {
		Coin
	} `json:"KMD"`
	LBC struct {
		Coin
	} `json:"LBC"`
	LSK struct {
		Coin
	} `json:"LSK"`
	LTC struct {
		Coin
	} `json:"LTC"`
	MAID struct {
		Coin
	} `json:"MAID"`
	MLN struct {
		Coin
	} `json:"MLN"`
	MONA struct {
		Coin
	} `json:"MONA"`
	MSC struct {
		Coin
	} `json:"MSC"`
	MTL struct {
		Coin
	} `json:"MTL"`
	NBT struct {
		Coin
	} `json:"NBT"`
	NEO struct {
		Coin
	} `json:"NEO"`
	NMC struct {
		Coin
	} `json:"NMC"`
	NMR struct {
		Coin
	} `json:"NMR"`
	NVC struct {
		Coin
	} `json:"NVC"`
	NXT struct {
		Coin
	} `json:"NXT"`
	OMG struct {
		Coin
	} `json:"OMG"`
	POT struct {
		Coin
	} `json:"POT"`
	PPC struct {
		Coin
	} `json:"PPC"`
	QTUM struct {
		Coin
	} `json:"QTUM"`
	RCN struct {
		Coin
	} `json:"RCN"`
	RDD struct {
		Coin
	} `json:"RDD"`
	REP struct {
		Coin
	} `json:"REP"`
	RLC struct {
		Coin
	} `json:"RLC"`
	SALT struct {
		Coin
	} `json:"SALT"`
	SC struct {
		Coin
	} `json:"SC"`
	SNGLS struct {
		Coin
	} `json:"SNGLS"`
	SNT struct {
		Coin
	} `json:"SNT"`
	START struct {
		Coin
	} `json:"START"`
	STEEM struct {
		Coin
	} `json:"STEEM"`
	STORJ struct {
		Coin
	} `json:"STORJ"`
	SWT struct {
		Coin
	} `json:"SWT"`
	TRST struct {
		Coin
	} `json:"TRST"`
	USDT struct {
		Coin
	} `json:"USDT"`
	VOX struct {
		Coin
	} `json:"VOX"`
	VRC struct {
		Coin
	} `json:"VRC"`
	VTC struct {
		Coin
	} `json:"VTC"`
	WAVES struct {
		Coin
	} `json:"WAVES"`
	WINGS struct {
		Coin
	} `json:"WINGS"`
	XCP struct {
		Coin
	} `json:"XCP"`
	XEM struct {
		Coin
	} `json:"XEM"`
	XMR struct {
		Coin
	} `json:"XMR"`
	XRP struct {
		Coin
	} `json:"XRP"`
	ZEC struct {
		Coin
	} `json:"ZEC"`
	ZRX struct {
		Coin
	} `json:"ZRX"`
}

func Coins

func Coins() (*CoinsResponse, error)

type DepositStatusResponse

type DepositStatusResponse struct {
	Status       string  `json:"status"`
	Address      string  `json:"address"`
	Withdraw     string  `json:"withdraw,omitempty"`
	IncomingCoin float64 `json:"incomingCoin,omitempty"`
	IncomingType string  `json:"incomingType,omitempty"`
	OutgoingCoin string  `json:"outgoingCoin,omitempty"`
	OutgoingType string  `json:"outgoingType,omitempty"`
	Transaction  string  `json:"transaction,omitempty"`
	Error
}

func DepositStatus

func DepositStatus(addr string) (*DepositStatusResponse, error)

type Error

type Error struct {
	Message string `json:"error,omitempty"`
}

func (Error) ErrorMsg

func (e Error) ErrorMsg() string

type ErrorMsg

type ErrorMsg interface {
	ErrorMsg() string
	// contains filtered or unexported methods
}

type FixedTransactionResponse

type FixedTransactionResponse struct {
	Response NewFixedTransactionResponse `json:"success"`
	Error
}

type LimitResponse

type LimitResponse struct {
	Pair  string `json:"pair,omitempty"`
	Limit string `json:"limit"`
	Error
}

type ListTransactionsAPIResponse

type ListTransactionsAPIResponse struct {
	Transactions []Transaction
	Error
}

type MarketInfoResponse

type MarketInfoResponse struct {
	Pair     string  `json:"pair,omitempty"`
	Rate     float64 `json:"rate,string,omitempty"`
	Limit    float64 `json:"limit,omitempty"`
	Min      float64 `json:"min,omitempty"`
	MinerFee float64 `json:"minerFee,omitempty"`
	Error
}

func MarketInfo

func MarketInfo() ([]MarketInfoResponse, error)

type New

type New struct {
	Pair        string  `json:"pair,omitempty"`
	ToAddress   string  `json:"withdrawal"`
	FromAddress string  `json:"returnAddress,omitempty"`
	DestTag     string  `json:"destTag,omitempty"`
	RsAddress   string  `json:"rsAddress,omitempty"`
	ApiKey      string  `json:"apiKey,omitempty"`
	Amount      float64 `json:"amount,omitempty"`
}

func (New) FixedShift

func (n New) FixedShift() (*NewFixedTransactionResponse, error)

func (New) Shift

func (n New) Shift() (*NewTransactionResponse, error)

type NewFixedTransactionResponse

type NewFixedTransactionResponse struct {
	OrderID          string  `json:"orderId"`
	Pair             string  `json:"pair,omitempty"`
	Withdrawal       string  `json:"withdrawal"`
	WithdrawalAmount string  `json:"withdrawalAmount"`
	Deposit          string  `json:"deposit"`
	DepositAmount    string  `json:"depositAmount"`
	Expiration       int64   `json:"expiration"`
	QuotedRate       string  `json:"quotedRate"`
	MaxLimit         float64 `json:"maxLimit"`
	ReturnAddress    string  `json:"returnAddress"`
	APIPubKey        string  `json:"apiPubKey"`
	MinerFee         string  `json:"minerFee"`
	Error
}

type NewTransactionResponse

type NewTransactionResponse struct {
	SendTo     string `json:"deposit"`
	SendType   string `json:"depositType"`
	ReturnTo   string `json:"withdrawal"`
	ReturnType string `json:"withdrawalType"`
	Public     string `json:"public"`
	XrpDestTag string `json:"xrpDestTag"`
	ApiKey     string `json:"apiPubKey"`
	Error
}

type Pair

type Pair struct {
	Name string `json:"pair,omitempty"`
}

func (Pair) GetInfo

func (p Pair) GetInfo() (*MarketInfoResponse, error)

func (Pair) GetLimits

func (p Pair) GetLimits() (float64, error)

func (Pair) GetRates

func (p Pair) GetRates() (float64, error)

type RateResponse

type RateResponse struct {
	Pair string `json:"pair,omitempty"`
	Rate string `json:"rate"`
	Error
}

type Receipt

type Receipt struct {
	Email         string `json:"email"`
	TransactionID string `json:"txid"`
}

func (Receipt) Send

func (r Receipt) Send() (*ReceiptResponse, error)

type ReceiptResponse

type ReceiptResponse struct {
	Email struct {
		Status  string `json:"status"`
		Message string `json:"message"`
	} `json:"email"`
	Error
}

type RecentTranxResponse

type RecentTranxResponse []struct {
	CurIn     string  `json:"curIn"`
	CurOut    string  `json:"curOut"`
	Timestamp float64 `json:"timestamp"`
	Amount    float64 `json:"amount"`
	Error
}

func RecentTransactions

func RecentTransactions(count string) (*RecentTranxResponse, error)

type TimeRemainingResponse

type TimeRemainingResponse struct {
	Status  string `json:"status"`
	Seconds string `json:"seconds_remaining"`
	Error
}

func TimeRemaining

func TimeRemaining(addr string) (*TimeRemainingResponse, error)

type Transaction

type Transaction struct {
	InputTXID      string  `json:"inputTXID"`
	InputAddress   string  `json:"inputAddress"`
	InputCurrency  string  `json:"inputCurrency,omitempty"`
	InputAmount    float64 `json:"inputAmount,omitempty"`
	OutputTXID     string  `json:"outputTXID,omitempty"`
	OutputAddress  string  `json:"outputAddress,omitempty"`
	OutputCurrency string  `json:"outputCurrency,omitempty"`
	OutputAmount   string  `json:"outputAmount,omitempty"`
	ShiftRate      string  `json:"shiftRate,omitempty"`
	Status         string  `json:"status,omitempty"`
}

type ValidateResponse

type ValidateResponse struct {
	Valid bool `json:"isValid"`
	Error
}

func Validate

func Validate(addr string, coin string) (*ValidateResponse, error)

Jump to

Keyboard shortcuts

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