Documentation ¶
Index ¶
- Constants
- Variables
- type Balance
- type Client
- func (c *Client) CancelOrder(walletID, orderID string) (bool, error)
- func (c *Client) CreateNewOrder(walletID string, order Order) (Order, error)
- func (c *Client) CreateNewWallet(userID, walletName string) (Wallet, error)
- func (c *Client) GetAllWallets(userID string, page, perPage int) ([]Wallet, error)
- func (c *Client) GetFundingHistory(walletID, lastExecutionID, page, perPage string, ...) (Funding, error)
- func (c *Client) GetOrder(walletID, orderID string) (Order, error)
- func (c *Client) GetOrderBook(tickerSymbol string) (OrderBook, error)
- func (c *Client) GetOrders(walletID, instrument, page, perPage, status string) ([]Order, error)
- func (c *Client) GetRecentTrades(tickerSymbol, since string) (Trades, error)
- func (c *Client) GetTicker(tickerSymbol string) (Ticker, error)
- func (c *Client) GetWallet(walletID string) (Wallet, error)
- func (c *Client) GetWalletBalance(walletID, currencyCode string) (Balance, error)
- func (c *Client) NewWalletTransfer(transfer Transfer) (Transfer, error)
- func (c *Client) SetHttpClient(client *http.Client)
- func (c *Client) SetKey(key string)
- func (c *Client) SetSecret(secret string)
- type Funding
- type Order
- type OrderBook
- type Ticker
- type Trades
- type Transfer
- type Wallet
Examples ¶
Constants ¶
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 ¶
var (
Endpoint = "https://api.itbit.com/v1"
)
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) CancelOrder ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
func (*OrderBook) UnmarshalJSON ¶
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"` }