itbit

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2022 License: MIT Imports: 29 Imported by: 0

README

GoCryptoTrader package Itbit

Build Status Software License GoDoc Coverage Status Go Report Card

This itbit package is part of the GoCryptoTrader codebase.

This is still in active development

You can track ideas, planned features and what's in progress on this Trello board: https://trello.com/b/ZAhMhpOy/gocryptotrader.

Join our slack to discuss all things related to GoCryptoTrader! GoCryptoTrader Slack

Itbit Exchange

Current Features
  • REST Support
How to enable
	// Exchanges will be abstracted out in further updates and examples will be
	// supplied then
How to do REST public/private calls
  • If enabled via "configuration".json file the exchange will be added to the IBotExchange array in the go var bot Bot and you will only be able to use the wrapper interface functions for accessing exchange data. View routines.go for an example of integration usage with GoCryptoTrader. Rudimentary example below:

main.go

var i exchange.IBotExchange

for x := range bot.Exchanges {
	if bot.Exchanges[x].GetName() == "Itbit" {
	i = bot.Exchanges[x]
	}
}

// Public calls - wrapper functions

// Fetches current ticker information
tick, err := i.FetchTicker()
if err != nil {
	// Handle error
}

// Fetches current orderbook information
ob, err := i.FetchOrderbook()
if err != nil {
	// Handle error
}

// Private calls - wrapper functions - make sure your APIKEY and APISECRET are
// set and AuthenticatedAPISupport is set to true

// Fetches current account information
accountInfo, err := i.GetAccountInfo()
if err != nil {
	// Handle error
}
  • If enabled via individually importing package, rudimentary example below:
// Public calls

// Fetches current ticker information
ticker, err := i.GetTicker()
if err != nil {
	// Handle error
}

// Fetches current orderbook information
ob, err := i.GetOrderBook()
if err != nil {
	// Handle error
}

// Private calls - make sure your APIKEY and APISECRET are set and
// AuthenticatedAPISupport is set to true

// GetUserInfo returns account info
accountInfo, err := i.GetUserInfo(...)
if err != nil {
	// Handle error
}

// Submits an order and the exchange and returns its tradeID
tradeID, err := i.Trade(...)
if err != nil {
	// Handle error
}
Please click GoDocs chevron above to view current GoDoc information for this package

Contribution

Please feel free to submit any pull requests or suggest any desired features to be added.

When submitting a PR, please abide by our coding guidelines:

  • Code must adhere to the official Go formatting guidelines (i.e. uses gofmt).
  • Code must be documented adhering to the official Go commentary guidelines.
  • Code must adhere to our coding style.
  • Pull requests need to be based on and opened against the master branch.

Donations

If this framework helped you in any way, or you would like to support the developers working on it, please donate Bitcoin to:

bc1qk0jareu4jytc0cfrhr5wgshsq8282awpavfahc

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

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"`
	Description      string  `json:"description"`
}

Balance is a sub type holding balance information

type CryptoCurrencyDeposit

type CryptoCurrencyDeposit struct {
	ID             int         `json:"id"`
	WalletID       string      `json:"walletID"`
	DepositAddress string      `json:"depositAddress"`
	Metadata       interface{} `json:"metadata"`
	Description    string      `json:"description"`
}

CryptoCurrencyDeposit holds information about a new wallet

type FundHistory

type FundHistory struct {
	BankName                    string  `json:"bankName"`
	WithdrawalID                int64   `json:"withdrawalId"`
	HoldingPeriodCompletionDate string  `json:"holdingPeriodCompletionDate"`
	DestinationAddress          string  `json:"destinationAddress"`
	TxnHash                     string  `json:"txnHash"`
	Time                        string  `json:"time"`
	Currency                    string  `json:"currency"`
	TransactionType             string  `json:"transactionType"`
	Amount                      float64 `json:"amount,string"`
	WalletName                  string  `json:"walletName"`
	Status                      string  `json:"status"`
}

FundHistory stores historic funding transactions

type FundingRecords

type FundingRecords struct {
	TotalNumberOfRecords int           `json:"totalNumberOfRecords,string"`
	CurrentPageNumber    int           `json:"currentPageNumber,string"`
	LatestExecutedID     int64         `json:"latestExecutionId,string"`
	RecordsPerPage       int           `json:"recordsPerPage,string"`
	FundingHistory       []FundHistory `json:"fundingHistory"`
	Description          string        `json:"description"`
}

FundingRecords embodies records of fund history information

type GeneralReturn

type GeneralReturn struct {
	Code        int    `json:"code"`
	Description string `json:"description"`
	RequestID   string `json:"requestId"`
}

GeneralReturn is a generalized return type to capture any errors

type ItBit

type ItBit struct {
	exchange.Base
}

ItBit is the overarching type across the ItBit package

func (*ItBit) CancelAllOrders

func (i *ItBit) CancelAllOrders(ctx context.Context, orderCancellation *order.Cancel) (order.CancelAllResponse, error)

CancelAllOrders cancels all orders associated with a currency pair

func (*ItBit) CancelBatchOrders

func (i *ItBit) CancelBatchOrders(ctx context.Context, o []order.Cancel) (order.CancelBatchResponse, error)

CancelBatchOrders cancels an orders by their corresponding ID numbers

func (*ItBit) CancelExistingOrder

func (i *ItBit) CancelExistingOrder(ctx context.Context, walletID, orderID string) error

CancelExistingOrder cancels and open order. *This is not a guarantee that the order has been cancelled!*

func (*ItBit) CancelOrder

func (i *ItBit) CancelOrder(ctx context.Context, o *order.Cancel) error

CancelOrder cancels an order by its corresponding ID number

func (*ItBit) CreateWallet

func (i *ItBit) CreateWallet(ctx context.Context, walletName string) (Wallet, error)

CreateWallet creates a new wallet with a specified name.

func (*ItBit) FetchAccountInfo

func (i *ItBit) FetchAccountInfo(ctx context.Context, assetType asset.Item) (account.Holdings, error)

FetchAccountInfo retrieves balances for all enabled currencies

func (*ItBit) FetchOrderbook

func (i *ItBit) FetchOrderbook(ctx context.Context, p currency.Pair, assetType asset.Item) (*orderbook.Base, error)

FetchOrderbook returns orderbook base on the currency pair

func (*ItBit) FetchTicker

func (i *ItBit) FetchTicker(ctx context.Context, p currency.Pair, assetType asset.Item) (*ticker.Price, error)

FetchTicker returns the ticker for a currency pair

func (*ItBit) FetchTradablePairs

func (i *ItBit) FetchTradablePairs(ctx context.Context, asset asset.Item) ([]string, error)

FetchTradablePairs returns a list of the exchanges tradable pairs

func (*ItBit) GetActiveOrders

func (i *ItBit) GetActiveOrders(ctx context.Context, req *order.GetOrdersRequest) ([]order.Detail, error)

GetActiveOrders retrieves any orders that are active/open

func (*ItBit) GetCryptoDepositAddress

func (i *ItBit) GetCryptoDepositAddress(ctx context.Context, walletID, currency string) (CryptoCurrencyDeposit, error)

GetCryptoDepositAddress returns a deposit address to send cryptocurrency to.

func (*ItBit) GetDefaultConfig

func (i *ItBit) GetDefaultConfig() (*config.Exchange, error)

GetDefaultConfig returns a default exchange config

func (*ItBit) GetDepositAddress

func (i *ItBit) GetDepositAddress(_ context.Context, _ currency.Code, _, _ string) (*deposit.Address, error)

GetDepositAddress returns a deposit address for a specified currency NOTE: This has not been implemented due to the fact you need to generate a a specific wallet ID and they restrict the amount of deposit address you can request limiting them to 2.

func (*ItBit) GetFee

func (i *ItBit) GetFee(feeBuilder *exchange.FeeBuilder) (float64, error)

GetFee returns an estimate of fee based on type of transaction

func (*ItBit) GetFeeByType

func (i *ItBit) GetFeeByType(ctx context.Context, feeBuilder *exchange.FeeBuilder) (float64, error)

GetFeeByType returns an estimate of fee based on type of transaction

func (*ItBit) GetFundingHistory

func (i *ItBit) GetFundingHistory(ctx context.Context) ([]exchange.FundHistory, error)

GetFundingHistory returns funding history, deposits and withdrawals

func (*ItBit) GetFundingHistoryForWallet

func (i *ItBit) GetFundingHistoryForWallet(ctx context.Context, walletID string, params url.Values) (FundingRecords, error)

GetFundingHistoryForWallet returns all funding history for a specified wallet.

func (*ItBit) GetHistoricCandles

func (i *ItBit) GetHistoricCandles(ctx context.Context, pair currency.Pair, a asset.Item, start, end time.Time, interval kline.Interval) (kline.Item, error)

GetHistoricCandles returns candles between a time period for a set time interval

func (*ItBit) GetHistoricCandlesExtended

func (i *ItBit) GetHistoricCandlesExtended(ctx context.Context, pair currency.Pair, a asset.Item, start, end time.Time, interval kline.Interval) (kline.Item, error)

GetHistoricCandlesExtended returns candles between a time period for a set time interval

func (*ItBit) GetHistoricTrades

func (i *ItBit) GetHistoricTrades(_ context.Context, _ currency.Pair, _ asset.Item, _, _ time.Time) ([]trade.Data, error)

GetHistoricTrades returns historic trade data within the timeframe provided

func (*ItBit) GetKlines

func (b *ItBit) GetKlines(arg interface{}) ([]*kline.Kline, error)

GetKlines checks and returns a requested kline if it exists

func (*ItBit) GetOrder

func (i *ItBit) GetOrder(ctx context.Context, walletID string, params url.Values) (Order, error)

GetOrder returns an order by id.

func (*ItBit) GetOrderHistory

func (i *ItBit) GetOrderHistory(ctx context.Context, req *order.GetOrdersRequest) ([]order.Detail, error)

GetOrderHistory retrieves account order information Can Limit response to specific order status

func (*ItBit) GetOrderInfo

func (i *ItBit) GetOrderInfo(ctx context.Context, orderID string, pair currency.Pair, assetType asset.Item) (order.Detail, error)

GetOrderInfo returns order information based on order ID

func (*ItBit) GetOrderbook

func (i *ItBit) GetOrderbook(ctx context.Context, currencyPair string) (OrderbookResponse, error)

GetOrderbook returns full order book for the specified market. currencyPair - example "XBTUSD" "XBTSGD" "XBTEUR"

func (*ItBit) GetOrders

func (i *ItBit) GetOrders(ctx context.Context, walletID, symbol, status string, page, perPage int64) ([]Order, error)

GetOrders returns active orders for itBit perPage defaults to & has a limit of 50

func (*ItBit) GetRecentTrades

func (i *ItBit) GetRecentTrades(ctx context.Context, p currency.Pair, assetType asset.Item) ([]trade.Data, error)

GetRecentTrades returns the most recent trades for a currency and asset

func (*ItBit) GetTicker

func (i *ItBit) GetTicker(ctx context.Context, currencyPair string) (Ticker, error)

GetTicker returns ticker info for a specified market. currencyPair - example "XBTUSD" "XBTSGD" "XBTEUR"

func (*ItBit) GetTradeHistory

func (i *ItBit) GetTradeHistory(ctx context.Context, currencyPair, tradeID string) (Trades, error)

GetTradeHistory returns recent trades for a specified market.

currencyPair - example "XBTUSD" "XBTSGD" "XBTEUR" timestamp - matchNumber, only executions after this will be returned

func (*ItBit) GetWallet

func (i *ItBit) GetWallet(ctx context.Context, walletID string) (Wallet, error)

GetWallet returns wallet information by walletID

func (*ItBit) GetWalletBalance

func (i *ItBit) GetWalletBalance(ctx context.Context, walletID, currency string) (Balance, error)

GetWalletBalance returns balance information for a specific currency in a wallet.

func (*ItBit) GetWalletTrades

func (i *ItBit) GetWalletTrades(ctx context.Context, walletID string, params url.Values) (Records, error)

GetWalletTrades returns all trades for a specified wallet.

func (*ItBit) GetWallets

func (i *ItBit) GetWallets(ctx context.Context, params url.Values) ([]Wallet, error)

GetWallets returns information about all wallets associated with the account.

params --

page - [optional] page to return example 1. default 1
perPage - [optional] items per page example 50, default 50 max 50

func (*ItBit) GetWithdrawalsHistory

func (i *ItBit) GetWithdrawalsHistory(ctx context.Context, c currency.Code) (resp []exchange.WithdrawalHistory, err error)

GetWithdrawalsHistory returns previous withdrawals data

func (*ItBit) ModifyOrder

func (i *ItBit) ModifyOrder(ctx context.Context, action *order.Modify) (order.Modify, error)

ModifyOrder will allow of changing orderbook placement and limit to market conversion

func (*ItBit) PlaceOrder

func (i *ItBit) PlaceOrder(ctx context.Context, walletID, side, orderType, currency string, amount, price float64, instrument, clientRef string) (Order, error)

PlaceOrder places a new order

func (*ItBit) Run

func (i *ItBit) Run()

Run implements the ItBit wrapper

func (*ItBit) SendAuthenticatedHTTPRequest

func (i *ItBit) SendAuthenticatedHTTPRequest(ctx context.Context, ep exchange.URL, method, path string, params map[string]interface{}, result interface{}) error

SendAuthenticatedHTTPRequest sends an authenticated request to itBit

func (*ItBit) SendHTTPRequest

func (i *ItBit) SendHTTPRequest(ctx context.Context, ep exchange.URL, path string, result interface{}) error

SendHTTPRequest sends an unauthenticated HTTP request

func (*ItBit) SetDefaults

func (i *ItBit) SetDefaults()

SetDefaults sets the defaults for the exchange

func (*ItBit) Setup

func (i *ItBit) Setup(exch *config.Exchange) error

Setup sets the exchange parameters from exchange config

func (*ItBit) Start

func (i *ItBit) Start(wg *sync.WaitGroup) error

Start starts the ItBit go routine

func (*ItBit) SubmitOrder

func (i *ItBit) SubmitOrder(ctx context.Context, s *order.Submit) (order.SubmitResponse, error)

SubmitOrder submits a new order

func (*ItBit) UpdateAccountInfo

func (i *ItBit) UpdateAccountInfo(ctx context.Context, assetType asset.Item) (account.Holdings, error)

UpdateAccountInfo retrieves balances for all enabled currencies

func (*ItBit) UpdateOrderbook

func (i *ItBit) UpdateOrderbook(ctx context.Context, p currency.Pair, assetType asset.Item) (*orderbook.Base, error)

UpdateOrderbook updates and returns the orderbook for a currency pair

func (*ItBit) UpdateTicker

func (i *ItBit) UpdateTicker(ctx context.Context, p currency.Pair, a asset.Item) (*ticker.Price, error)

UpdateTicker updates and returns the ticker for a currency pair

func (*ItBit) UpdateTickers

func (i *ItBit) UpdateTickers(ctx context.Context, a asset.Item) error

UpdateTickers updates the ticker for all currency pairs of a given asset type

func (*ItBit) UpdateTradablePairs

func (i *ItBit) UpdateTradablePairs(ctx context.Context, forceUpdate bool) error

UpdateTradablePairs updates the exchanges available pairs and stores them in the exchanges config

func (*ItBit) ValidateCredentials

func (i *ItBit) ValidateCredentials(ctx context.Context, assetType asset.Item) error

ValidateCredentials validates current credentials used for wrapper functionality

func (*ItBit) WalletTransfer

func (i *ItBit) WalletTransfer(ctx context.Context, walletID, sourceWallet, destWallet string, amount float64, currency string) (WalletTransfer, error)

WalletTransfer transfers funds between wallets.

func (*ItBit) WithdrawCryptocurrencyFunds

func (i *ItBit) WithdrawCryptocurrencyFunds(_ context.Context, _ *withdraw.Request) (*withdraw.ExchangeResponse, error)

WithdrawCryptocurrencyFunds returns a withdrawal ID when a withdrawal is submitted

func (*ItBit) WithdrawFiatFunds

func (i *ItBit) WithdrawFiatFunds(_ context.Context, _ *withdraw.Request) (*withdraw.ExchangeResponse, error)

WithdrawFiatFunds returns a withdrawal ID when a withdrawal is submitted

func (*ItBit) WithdrawFiatFundsToInternationalBank

func (i *ItBit) WithdrawFiatFundsToInternationalBank(_ context.Context, _ *withdraw.Request) (*withdraw.ExchangeResponse, error)

WithdrawFiatFundsToInternationalBank returns a withdrawal ID when a withdrawal is submitted

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"`
	Price                      float64     `json:"price,string"`
	AmountFilled               float64     `json:"amountFilled,string"`
	VolumeWeightedAveragePrice float64     `json:"volumeWeightedAveragePrice,string"`
	CreatedTime                string      `json:"createdTime"`
	Status                     string      `json:"Status"`
	Metadata                   interface{} `json:"metadata"`
	ClientOrderIdentifier      string      `json:"clientOrderIdentifier"`
	Description                string      `json:"description"`
}

Order holds order information

type OrderbookResponse

type OrderbookResponse struct {
	Bids [][]string `json:"bids"`
	Asks [][]string `json:"asks"`
}

OrderbookResponse contains multi-arrayed strings of bid and ask side information

type Records

type Records struct {
	TotalNumberOfRecords int            `json:"totalNumberOfRecords,string"`
	CurrentPageNumber    int            `json:"currentPageNumber,string"`
	LatestExecutedID     int64          `json:"latestExecutionId,string"`
	RecordsPerPage       int            `json:"recordsPerPage,string"`
	TradingHistory       []TradeHistory `json:"tradingHistory"`
	Description          string         `json:"description"`
}

Records embodies records of trade history information

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"`
}

Ticker holds returned ticker information

type TradeHistory

type TradeHistory struct {
	OrderID            string  `json:"orderId"`
	Timestamp          string  `json:"timestamp"`
	Instrument         string  `json:"instrument"`
	Direction          string  `json:"direction"`
	CurrencyOne        string  `json:"currency1"`
	CurrencyOneAmount  float64 `json:"currency1Amount,string"`
	CurrencyTwo        string  `json:"currency2"`
	CurrencyTwoAmount  float64 `json:"currency2Amount"`
	Rate               float64 `json:"rate,string"`
	CommissionPaid     float64 `json:"commissionPaid,string"`
	CommissionCurrency string  `json:"commissionCurrency"`
	RebatesApplied     float64 `json:"rebatesApplied,string"`
	RebateCurrency     string  `json:"rebateCurrency"`
}

TradeHistory stores historic trade values

type Trades

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

Trades holds recent trades with associated information

type Wallet

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

Wallet contains specific wallet information

type WalletTransfer

type WalletTransfer struct {
	SourceWalletID      string  `json:"sourceWalletId"`
	DestinationWalletID string  `json:"destinationWalletId"`
	Amount              float64 `json:"amount,string"`
	CurrencyCode        string  `json:"currencyCode"`
	Description         string  `json:"description"`
}

WalletTransfer holds wallet transfer information

Jump to

Keyboard shortcuts

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