itbit

package
v0.0.0-...-9a79cc2 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2019 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const (
	StatusCancelled = "cancelled"
	StatusFilled    = "filled"
	StatusOpen      = "open"
	StatusRejected  = "rejected"
	StatusSubmitted = "submitted"

	Bitcoin         = "XBT"
	Etherium        = "ETH"
	Euro            = "EUR"
	SingaporeDollar = "SGD"
	USDollar        = "USD"

	BitcoinUSDollar         = "XBTUSD"
	BitcoinSingaporeDollar  = "XBTSGD"
	BitcoinEuro             = "XBTEUR"
	EtheriumUSDollar        = "ETHUSD"
	EtheriumEuro            = "ETHEUR"
	EtheriumSingaporeDollar = "ETHSGD"
)

Variables

View Source
var (
	Endpoint = "https://api.itbit.com/v1"
)

Functions

This section is empty.

Types

type Balance

type Balance struct {
	Currency         string  `json:"currency"`
	AvailableBalance float64 `json:"availableBalance,string"`
	TotalBalance     float64 `json:"totalBalance,string"`
}

type Client

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

func NewClient

func NewClient(key, secret string) *Client

func (*Client) CancelOrder

func (c *Client) CancelOrder(walletID, orderID string) (bool, error)

CancelOrder cancels an order for the specified wallet ID and order ID. A successful response indicates that the request was recieved, but does not guarantee the order was cancelled.

Example
package main

import (
	"fmt"
	"log"

	"github.com/juliansniff/go-itbit/itbit"
)

func main() {
	c := itbit.NewClient("key", "secret")

	ok, err := c.CancelOrder("walletID", "orderID")
	if err != nil {
		log.Panic(err)
	}

	fmt.Printf("%t", ok)
}
Output:

true

func (*Client) CreateNewOrder

func (c *Client) CreateNewOrder(walletID string, order Order) (Order, error)
Example
package main

import (
	"fmt"
	"log"

	"github.com/juliansniff/go-itbit/itbit"
)

func main() {
	c := itbit.NewClient("key", "secret")

	order, err := c.CreateNewOrder("walletID", itbit.Order{
		Side:                  "buy",
		Type:                  "limit",
		Currency:              itbit.Bitcoin,
		Amount:                100.0350,
		Display:               100.0350,
		Price:                 750.53,
		Instrument:            itbit.BitcoinUSDollar,
		ClientOrderIdentifier: "optional",
		PostOnly:              true,
	})
	if err != nil {
		log.Panic(err)
	}

	fmt.Printf("Successfully created order: %s %.2f %s", order.Side, order.Amount, order.Currency)
}
Output:

Successfully created order: buy 100.03 XBT

func (*Client) CreateNewWallet

func (c *Client) CreateNewWallet(userID, walletName string) (Wallet, error)

CreateNewWallet creates a new wallet and returns a reference to it.

Example
package main

import (
	"fmt"
	"log"

	"github.com/juliansniff/go-itbit/itbit"
)

func main() {
	c := itbit.NewClient("key", "secret")
	wallet, err := c.CreateNewWallet("userID", "New Wallet")
	if err != nil {
		log.Panic(err)
	}

	fmt.Printf("%s:\n", wallet.Name)
	for _, balance := range wallet.Balances {
		fmt.Printf("%.2f %s Available\n", balance.AvailableBalance, balance.Currency)
	}
}
Output:

New Wallet:
0.00 USD Available
0.00 XBT Available
0.00 EUR Available
0.00 SGD Available

func (*Client) GetAllWallets

func (c *Client) GetAllWallets(userID string, page, perPage int) ([]Wallet, error)
Example
package main

import (
	"fmt"
	"log"

	"github.com/juliansniff/go-itbit/itbit"
)

func main() {
	c := itbit.NewClient("key", "secret")

	wallets, err := c.GetAllWallets("userID", 0, 0)
	if err != nil {
		log.Panic(err)
	}

	for _, wallet := range wallets {
		fmt.Printf("%s:\n", wallet.Name)
		for _, balance := range wallet.Balances {
			fmt.Printf("%.2f %s", balance.AvailableBalance, balance.Currency)
		}
		fmt.Printf("\n")
	}
}
Output:

Wallet 1:
0.00 USD0.00 XBT0.00 EUR0.00 SGD
Wallet 2:
75631.89 USD100100.03 XBT100000.00 EUR100000.00 SGD

func (*Client) GetFundingHistory

func (c *Client) GetFundingHistory(walletID, lastExecutionID, page, perPage string, rangeStart, rangeEnd time.Time) (Funding, error)
Example
package main

import (
	"fmt"
	"log"
	"time"

	"github.com/juliansniff/go-itbit/itbit"
)

func main() {
	c := itbit.NewClient("key", "secret")
	f, err := c.GetFundingHistory("walletID", "", "", "", time.Time{}, time.Time{})
	if err != nil {
		log.Panic(err)
	}

	fmt.Printf("%s\n", f.TotalNumberOfRecords)
}
Output:

2

func (*Client) GetOrder

func (c *Client) GetOrder(walletID, orderID string) (Order, error)

GetOrder returns a particular order based off of a wallet ID and an order ID.

Both walletID and orderID are required parameters.

Example
package main

import (
	"fmt"
	"log"

	"github.com/juliansniff/go-itbit/itbit"
)

func main() {
	c := itbit.NewClient("key", "secret")

	order, err := c.GetOrder("walletID", "orderID")
	if err != nil {
		log.Panic(err)
	}

	fmt.Printf("Order:\n")
	fmt.Printf("----------\n")
	fmt.Printf("Currency: %s\n", order.Currency)
	fmt.Printf("Amount: %.2f\n", order.Amount)
	fmt.Printf("Price: %.2f\n", order.Price)
	fmt.Printf("Status: %s\n", order.Status)

}
Output:

Order:
----------
Currency: XBT
Amount: 2.50
Price: 650.00
Status: open

func (*Client) GetOrderBook

func (c *Client) GetOrderBook(tickerSymbol string) (OrderBook, error)

GetOrderBook returns the full order book for the specified market.

Example
package main

import (
	"fmt"
	"log"

	"github.com/juliansniff/go-itbit/itbit"
)

func main() {
	c := itbit.NewClient("key", "secret")

	orderBook, err := c.GetOrderBook(itbit.BitcoinUSDollar)
	if err != nil {
		log.Panic(err)
	}

	fmt.Printf("Asks:\n")
	for _, ask := range orderBook.Asks {
		fmt.Printf("[%.2f, %.2f]\n", ask[0], ask[1])
	}
	fmt.Printf("Bids:\n")
	for _, bid := range orderBook.Bids {
		fmt.Printf("[%.2f, %.2f]\n", bid[0], bid[1])
	}

}
Output:

Asks:
[219.82, 2.19]
[219.83, 6.05]
[220.19, 17.59]
[220.52, 3.36]
[220.53, 33.46]
Bids:
[219.40, 17.46]
[219.13, 53.93]
[219.08, 2.20]
[218.58, 98.73]
[218.20, 3.37]

func (*Client) GetOrders

func (c *Client) GetOrders(walletID, instrument, page, perPage, status string) ([]Order, error)

GetOrders returns an array of orders given a wallet ID.

Example
package main

import (
	"fmt"
	"log"

	"github.com/juliansniff/go-itbit/itbit"
)

func main() {
	c := itbit.NewClient("key", "secret")

	orders, err := c.GetOrders("id", "", "", "", itbit.StatusOpen)
	if err != nil {
		log.Panic(err)
	}

	for i, order := range orders {
		fmt.Printf("Order %d:\n", i+1)
		fmt.Printf("----------\n")
		fmt.Printf("Currency: %s\n", order.Currency)
		fmt.Printf("Amount: %.2f\n", order.Amount)
		fmt.Printf("Price: %.2f\n", order.Price)
		fmt.Printf("Status: %s\n", order.Status)
	}

}
Output:

Order 1:
----------
Currency: XBT
Amount: 2.50
Price: 650.00
Status: open

func (*Client) GetRecentTrades

func (c *Client) GetRecentTrades(tickerSymbol, since string) (Trades, error)

MarketService returns recent trades for the specified market

since is an optional parameter

Example
package main

import (
	"fmt"
	"log"

	"github.com/juliansniff/go-itbit/itbit"
)

func main() {
	c := itbit.NewClient("key", "secret")

	trades, err := c.GetRecentTrades(itbit.BitcoinUSDollar, "")
	if err != nil {
		log.Panic(err)
	}

	fmt.Printf("%d Trades:\n", trades.Count)
	for i, trade := range trades.RecentTrades {
		fmt.Printf("%d) Price: %.2f, Amount: %.4f\n", i+1, trade.Price, trade.Amount)
	}

}
Output:

3 Trades:
1) Price: 351.45, Amount: 0.0001
2) Price: 352.00, Amount: 0.0001
3) Price: 351.45, Amount: 0.0001

func (*Client) GetTicker

func (c *Client) GetTicker(tickerSymbol string) (Ticker, error)

GetTicker returns Ticker for the specified market.

Example
package main

import (
	"fmt"
	"log"

	"github.com/juliansniff/go-itbit/itbit"
)

func main() {
	c := itbit.NewClient("key", "secret")

	ticker, err := c.GetTicker(itbit.BitcoinUSDollar)
	if err != nil {
		log.Panic(err)
	}

	fmt.Printf("%s:\n", ticker.Pair)
	fmt.Printf("Last Price: %.2f\n", ticker.LastPrice)
	fmt.Printf("Last Amount: %.4f\n", ticker.LastAmt)

}
Output:

XBTUSD:
Last Price: 618.00
Last Amount: 0.0004

func (*Client) GetWallet

func (c *Client) GetWallet(walletID string) (Wallet, error)
Example
package main

import (
	"fmt"
	"log"

	"github.com/juliansniff/go-itbit/itbit"
)

func main() {
	c := itbit.NewClient("key", "secret")

	wallet, err := c.GetWallet("testWalletID")
	if err != nil {
		log.Panic(err)
	}

	fmt.Printf("%s:\n", wallet.Name)
	for _, balance := range wallet.Balances {
		fmt.Printf("%.2f %s Available\n", balance.AvailableBalance, balance.Currency)
	}
}
Output:

Test Wallet:
50000.00 USD Available
100.00 XBT Available
100000.00 EUR Available
515440.88 SGD Available

func (*Client) GetWalletBalance

func (c *Client) GetWalletBalance(walletID, currencyCode string) (Balance, error)

GetWalletBalance returns the Balance of a wallet given a Wallet ID and a valid Currency Code.

Example
package main

import (
	"fmt"
	"log"

	"github.com/juliansniff/go-itbit/itbit"
)

func main() {
	c := itbit.NewClient("key", "secret")
	balance, err := c.GetWalletBalance("walletID", itbit.USDollar)
	if err != nil {
		log.Panic(err)
	}

	fmt.Printf("wallet has %.2f %s", balance.TotalBalance, balance.Currency)
}
Output:

wallet has 0.00 USD

func (*Client) NewWalletTransfer

func (c *Client) NewWalletTransfer(transfer Transfer) (Transfer, error)

NewWalletTransfer transfers funds from one wallet to another.

Example
package main

import (
	"fmt"
	"log"

	"github.com/juliansniff/go-itbit/itbit"
)

func main() {
	c := itbit.NewClient("key", "secret")
	t, err := c.NewWalletTransfer(itbit.Transfer{
		SourceWalletID:      "7e037345-1288-4c39-12fe-d0f99a475a98",
		DestinationWalletID: "b30cpab8-c468-9950-a771-be0db2b39dea",
		Amount:              1773.80,
		CurrencyCode:        itbit.Bitcoin,
	})
	if err != nil {
		log.Panic(err)
	}

	fmt.Printf("Successfully transferred %.2f %s from %s to %s", t.Amount, t.CurrencyCode, t.SourceWalletID, t.DestinationWalletID)
}
Output:

Successfully transferred 1773.80 XBT from 7e037345-1288-4c39-12fe-d0f99a475a98 to b30cpab8-c468-9950-a771-be0db2b39dea

func (*Client) SetHttpClient

func (c *Client) SetHttpClient(client *http.Client)

func (*Client) SetKey

func (c *Client) SetKey(key string)

func (*Client) SetSecret

func (c *Client) SetSecret(secret string)

type Funding

type Funding struct {
	TotalNumberOfRecords string `json:"totalNumberOfRecords"`
	CurrentPageNumber    string `json:"currentPageNumber"`
	LatestExecutionID    string `json:"latestExecutionId"`
	RecordsPerPage       string `json:"recordsPerPage"`
	FundingHistory       []struct {
		BankName                    string `json:"bankName,omitempty"`
		WithdrawalID                int    `json:"withdrawalId,omitempty"`
		HoldingPeriodCompletionDate string `json:"holdingPeriodCompletionDate,omitempty"`
		Time                        string `json:"time"`
		Currency                    string `json:"currency"`
		TransactionType             string `json:"transactionType"`
		Amount                      string `json:"amount"`
		WalletName                  string `json:"walletName"`
		Status                      string `json:"status"`
		DestinationAddress          string `json:"destinationAddress,omitempty"`
		TxnHash                     string `json:"txnHash,omitempty"`
	} `json:"fundingHistory"`
}

type Order

type Order struct {
	ID                         string      `json:"id"`
	WalletID                   string      `json:"walletId"`
	Side                       string      `json:"side"`
	Instrument                 string      `json:"instrument"`
	Type                       string      `json:"type"`
	Currency                   string      `json:"currency"`
	Amount                     float64     `json:"amount,string"`
	Display                    float64     `json:"display,string"`
	Price                      float64     `json:"price,string"`
	AmountFilled               float64     `json:"amountFilled,string"`
	VolumeWeightedAveragePrice string      `json:"volumeWeightedAveragePrice"`
	CreatedTime                time.Time   `json:"createdTime"`
	Status                     string      `json:"status"`
	Metadata                   interface{} `json:"metadata"`
	ClientOrderIdentifier      interface{} `json:"clientOrderIdentifier"`
	PostOnly                   bool        `json:"postOnly"`
}

type OrderBook

type OrderBook struct {
	Asks [][]float64 `json:"asks"`
	Bids [][]float64 `json:"bids"`
}

func (*OrderBook) UnmarshalJSON

func (ob *OrderBook) UnmarshalJSON(b []byte) error

type Ticker

type Ticker struct {
	Pair          string    `json:"pair"`
	Bid           float64   `json:"bid,string"`
	BidAmt        float64   `json:"bidAmt,string"`
	Ask           float64   `json:"ask,string"`
	AskAmt        float64   `json:"askAmt,string"`
	LastPrice     float64   `json:"lastPrice,string"`
	LastAmt       float64   `json:"lastAmt,string"`
	Volume24H     float64   `json:"volume24h,string"`
	VolumeToday   float64   `json:"volumeToday,string"`
	High24H       float64   `json:"high24h,string"`
	Low24H        float64   `json:"low24h,string"`
	HighToday     float64   `json:"highToday,string"`
	LowToday      float64   `json:"lowToday,string"`
	OpenToday     float64   `json:"openToday,string"`
	VwapToday     float64   `json:"vwapToday,string"`
	Vwap24H       float64   `json:"vwap24h,string"`
	ServerTimeUTC time.Time `json:"serverTimeUTC"`
}

type Trades

type Trades struct {
	Count        int `json:"count"`
	RecentTrades []struct {
		Timestamp   time.Time `json:"timestamp"`
		MatchNumber string    `json:"matchNumber"`
		Price       float64   `json:"price,string"`
		Amount      float64   `json:"amount,string"`
	} `json:"recentTrades"`
}

type Transfer

type Transfer struct {
	SourceWalletID      string  `json:"sourceWalletID"`
	DestinationWalletID string  `json:"destinationWalletID"`
	Amount              float64 `json:"amount,string"`
	CurrencyCode        string  `json:"currencyCode"`
}

type Wallet

type Wallet struct {
	ID       string    `json:"id"`
	UserID   string    `json:"userId"`
	Name     string    `json:"name"`
	Balances []Balance `json:"balances"`
}

Jump to

Keyboard shortcuts

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