All Projects → hunterlong → Shapeshift

hunterlong / Shapeshift

Licence: mit
ShapeShift API for Go Language - convert cryptocurrencies with ease using ShapeShift and golang

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Shapeshift

Donut
🏹 Dead-simple cross-platform cryptocurrency tracker.
Stars: ✭ 367 (+948.57%)
Mutual labels:  ethereum, bitcoin, cryptocurrency, dash
Cryptocurrency Cli
💰 Cryptocurrency Portfolio On The Command Line 💰
Stars: ✭ 99 (+182.86%)
Mutual labels:  ethereum, bitcoin, cryptocurrency, dash
Moneda Cli
Command line to track cryptocurrency prices
Stars: ✭ 114 (+225.71%)
Mutual labels:  ethereum, bitcoin, cryptocurrency, dash
Cryptocurrency Dashboard
Crypto Currency Dashboard Using Twitter 🐦 And Coinmarketcap 🚀 API
Stars: ✭ 54 (+54.29%)
Mutual labels:  ethereum, bitcoin, cryptocurrency, dash
Crypto Whale Watching App
Python Dash app that tracks whale activity in cryptocurrency markets.
Stars: ✭ 389 (+1011.43%)
Mutual labels:  ethereum, bitcoin, cryptocurrency, dash
Ethlist
The Comprehensive Ethereum Reading List
Stars: ✭ 3,576 (+10117.14%)
Mutual labels:  ethereum, bitcoin, cryptocurrency
Bitcoinlib
Bitcoin Core RPC compatible, battle-tested .NET library and RPC wrapper for Bitcoin and Altcoins
Stars: ✭ 350 (+900%)
Mutual labels:  bitcoin, cryptocurrency, dash
Algo Coin
Python library for algorithmic trading cryptocurrencies across multiple exchanges
Stars: ✭ 365 (+942.86%)
Mutual labels:  ethereum, bitcoin, cryptocurrency
Crypto Arbitrage
Automatic Cryptocurrency Trading Bot using Triangular or Exchange Arbitrages
Stars: ✭ 369 (+954.29%)
Mutual labels:  ethereum, bitcoin, cryptocurrency
Cryptocurrency
Overview of top cryptocurrencies
Stars: ✭ 385 (+1000%)
Mutual labels:  ethereum, bitcoin, cryptocurrency
Finch
An Open Source Cryptocurrency Payment Processor.
Stars: ✭ 27 (-22.86%)
Mutual labels:  ethereum, bitcoin, cryptocurrency
Wolfbot
Crypto currency trading bot written in TypeScript for NodeJS
Stars: ✭ 335 (+857.14%)
Mutual labels:  ethereum, bitcoin, cryptocurrency
Ccxt
A JavaScript / Python / PHP cryptocurrency trading API with support for more than 100 bitcoin/altcoin exchanges
Stars: ✭ 22,501 (+64188.57%)
Mutual labels:  ethereum, bitcoin, cryptocurrency
React Native Redux Crypto Tracker
💎 Learn how to build a Redux + React Native cryptocurrency app
Stars: ✭ 351 (+902.86%)
Mutual labels:  ethereum, bitcoin, cryptocurrency
Blockchain Wallet V4 Frontend
Blockchain.com's Wallet built with React & Redux
Stars: ✭ 323 (+822.86%)
Mutual labels:  ethereum, bitcoin, cryptocurrency
Awesome Coins
₿ A guide (for humans!) to cryto-currencies and their algos.
Stars: ✭ 3,469 (+9811.43%)
Mutual labels:  ethereum, bitcoin, cryptocurrency
Qtbitcointrader
Secure multi crypto exchange trading client
Stars: ✭ 520 (+1385.71%)
Mutual labels:  ethereum, bitcoin, cryptocurrency
Exchangesharp
ExchangeSharp is a powerful, fast and easy to use .NET/C# API for interfacing with many crypto currency exchanges. REST and web sockets are supported.
Stars: ✭ 489 (+1297.14%)
Mutual labels:  ethereum, bitcoin, cryptocurrency
Wallet Core
Cross-platform, cross-blockchain wallet library.
Stars: ✭ 657 (+1777.14%)
Mutual labels:  ethereum, bitcoin, cryptocurrency
Edge React Gui
Edge Wallet React Native GUI for iOS and Android
Stars: ✭ 303 (+765.71%)
Mutual labels:  ethereum, bitcoin, dash

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:         "[email protected]",
	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: "[email protected]",
		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 👍 👍

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].