-- import "github.com/bitfinexcom/bitfinex-api-go/v1"
Package bitfinex is the official client to access to bitfinex.com API
const (
// BaseURL is the v1 REST endpoint.
BaseURL = "https://api.bitfinex.com/v1/"
// WebSocketURL the v1 Websocket endpoint.
WebSocketURL = "wss://api-pub.bitfinex.com/ws/"
)
const (
LEND = "lend"
LOAN = "loan"
)
const (
OrderTypeMarket = "market"
OrderTypeLimit = "limit"
OrderTypeStop = "stop"
OrderTypeTrailingStop = "trailing-stop"
OrderTypeFillOrKill = "fill-or-kill"
OrderTypeExchangeMarket = "exchange market"
OrderTypeExchangeLimit = "exchange limit"
OrderTypeExchangeStop = "exchange stop"
OrderTypeExchangeTrailingStop = "exchange trailing-stop"
OrderTypeExchangeFillOrKill = "exchange fill-or-kill"
)
Order types that the API can return.
const (
WALLET_TRADING = "trading"
WALLET_EXCHANGE = "exchange"
WALLET_DEPOSIT = "deposit"
)
const (
// Pairs
BTCUSD = "BTCUSD"
LTCUSD = "LTCUSD"
LTCBTC = "LTCBTC"
ETHUSD = "ETHUSD"
ETHBTC = "ETHBTC"
ETCUSD = "ETCUSD"
ETCBTC = "ETCBTC"
BFXUSD = "BFXUSD"
BFXBTC = "BFXBTC"
ZECUSD = "ZECUSD"
ZECBTC = "ZECBTC"
XMRUSD = "XMRUSD"
XMRBTC = "XMRBTC"
RRTUSD = "RRTUSD"
RRTBTC = "RRTBTC"
XRPUSD = "XRPUSD"
XRPBTC = "XRPBTC"
EOSETH = "EOSETH"
EOSUSD = "EOSUSD"
EOSBTC = "EOSBTC"
IOTUSD = "IOTUSD"
IOTBTC = "IOTBTC"
IOTETH = "IOTETH"
BCCBTC = "BCCBTC"
BCUBTC = "BCUBTC"
BCCUSD = "BCCUSD"
BCUUSD = "BCUUSD"
// Channels
ChanBook = "book"
ChanTrade = "trades"
ChanTicker = "ticker"
)
Pairs available
type AccountInfo struct {
MakerFees float64 `json:"maker_fees,string"`
TakerFees float64 `json:"taker_fees,string"`
Fees []AccountPairFee
}
type AccountPairFee struct {
Pair string
MakerFees float64 `json:"maker_fees,string"`
TakerFees float64 `json:"taker_fees,string"`
}
type AccountService struct {
}
func (a *AccountService) Info() (AccountInfo, error)
GET account_infos
func (a *AccountService) KeyPermission() (Permissions, error)
func (a *AccountService) Summary() (Summary, error)
type ActiveOffer struct {
ID int64
Currency string
Rate string
Period int
Direction string
Timestamp string
IsLive bool `json:"is_live"`
IsCancelled bool `json:"is_cancelled"`
OriginalAmount string `json:"original_amount"`
RemainingAmount string `json:"remaining_amount"`
ExecutedAmount string `json:"executed_amount"`
}
type Balance struct {
Currency string
Amount string
Balance string
Description string
Timestamp string
}
type BalancesService struct {
}
func (b *BalancesService) All() ([]WalletBalance, error)
GET balances
type BankAccount struct {
AccountName string // Account name
AccountNumber string // Account number or IBAN
BankName string // Bank Name
BankAddress string // Bank Address
BankCity string // Bank City
BankCountry string // Bank Country
SwiftCode string // SWIFT Code
}
type Client struct {
// Base URL for API requests.
BaseURL *url.URL
WebSocketURL string
WebSocketTLSSkipVerify bool
// Auth data
APIKey string
APISecret string
// Services
Pairs *PairsService
Stats *StatsService
Ticker *TickerService
Account *AccountService
Balances *BalancesService
Offers *OffersService
Credits *CreditsService
Deposit *DepositService
Lendbook *LendbookService
MarginInfo *MarginInfoService
MarginFunding *MarginFundingService
OrderBook *OrderBookService
Orders *OrderService
Trades *TradesService
Positions *PositionsService
History *HistoryService
WebSocket *WebSocketService
Wallet *WalletService
}
Client manages all the communication with the Bitfinex API.
func NewClient() *Client
NewClient creates new Bitfinex.com API client.
func (c *Client) Auth(key string, secret string) *Client
Auth sets api key and secret for usage is requests that requires authentication.
type Credit struct {
Id int
Currency string
Status string
Rate float64 `json:",string"`
Period float64
Amount float64 `json:",string"`
Timestamp string
}
type CreditsService struct {
}
func (c *CreditsService) All() ([]Credit, error)
Returns an array of Credit
type DepositResponse struct {
Result string
Method string
Currency string
Address string
}
func (d *DepositResponse) Success() (bool, error)
type DepositService struct {
}
func (s *DepositService) New(method, walletName string, renew int) (DepositResponse, error)
type ErrorResponse struct {
Response *Response
Message string `json:"message"`
}
ErrorResponse is the custom error type that is returned if the API returns an error.
func (r *ErrorResponse) Error() string
type HistoryService struct {
}
func (s *HistoryService) Balance(currency, wallet string, since, until time.Time, limit int) ([]Balance, error)
func (s *HistoryService) Movements(currency, method string, since, until time.Time, limit int) ([]Movement, error)
func (s *HistoryService) Trades(pair string, since, until time.Time, limit int, reverse bool) ([]PastTrade, error)
type KeyPerm struct {
Read bool
Write bool
}
type Lend struct {
Rate string
Amount string
Period int
Timestamp string
Frr string
}
func (el *Lend) ParseTime() (*time.Time, error)
type Lendbook struct {
Bids []Lend
Asks []Lend
}
type LendbookService struct {
}
func (s *LendbookService) Get(currency string, limitBids, limitAsks int) (Lendbook, error)
GET /lendbook/:currency
func (s *LendbookService) Lends(currency string) ([]Lends, error)
GET /lends/:currency
type Lends struct {
Rate string
AmountLent string `json:"amount_lent"`
AmountUsed string `json:"amount_used"`
Timestamp int64
}
func (el *Lends) Time() *time.Time
type MarginFundingService struct {
}
func (s *MarginFundingService) Cancel(offerId int64) (MarginOffer, error)
func (s *MarginFundingService) Credits() ([]ActiveOffer, error)
func (s *MarginFundingService) NewLend(currency string, amount, rate float64, period int) (MarginOffer, error)
func (s *MarginFundingService) NewLoan(currency string, amount, rate float64, period int) (MarginOffer, error)
func (s *MarginFundingService) Offers() ([]ActiveOffer, error)
func (s *MarginFundingService) Status(offerId int64) (MarginOffer, error)
type MarginInfo struct {
MarginBalance float64 `json:"margin_balance,string"`
TradableBalance float64 `json:"tradable_balance,string"`
UnrealizedPl float64 `json:"unrealized_pl,string"`
UnrealizedSwap float64 `json:"unrealized_swap,string"`
NetValue float64 `json:"net_value,string"`
RequiredMargin float64 `json:"required_margin,string"`
Leverage float64 `json:"leverage,string"`
MarginRequirement float64 `json:"margin_requirement,string"`
MarginLimits []MarginLimit `json:"margin_limits,string"`
Message string `json:"message"`
}
type MarginInfoService struct {
}
func (s *MarginInfoService) All() ([]MarginInfo, error)
GET /margin_infos
type MarginLimit struct {
OnPair string `json:"on_pair"`
InitialMargin float64 `json:"initial_margin,string"`
MarginRequirement float64 `json:"margin_requirement,string"`
TradableBalance float64 `json:"tradable_balance,string"`
}
type MarginOffer struct {
ID int64
Currency string
Rate string
Period int
Direction string
Timestamp string
IsLive bool `json:"is_live"`
IsCancelled bool `json:"is_cancelled"`
OriginalAmount string `json:"original_amount"`
RemainingAmount string `json:"remaining_amount"`
ExecutedAmount string `json:"executed_amount"`
OfferId int
}
type Movement struct {
ID int64 `json:",int"`
Currency string
Method string
Type string
Amount string
Description string
Status string
Timestamp string
}
type MultipleOrderResponse struct {
Orders []Order `json:"order_ids"`
Status string
}
MultipleOrderResponse bundles orders returned by the CreateMulti method.
type Offer struct {
Id int64
Currency string
Rate string
Period int64
Direction string
Timestamp string
IsLive bool `json:"is_live"`
IsCancelled bool `json:"is_cancelled"`
OriginalAmount string `json:"original_amount:string"`
RemainingAmount string `json:"remaining_amount:string"`
ExecutedAmount string `json:"executed_amount:string"`
OfferId int64 `json:"offer_id"`
}
type OffersService struct {
}
func (s *OffersService) Cancel(offerId int64) (Offer, error)
func (s *OffersService) New(currency string, amount, rate float64, period int64, direction string) (Offer, error)
Create new offer for LEND or LOAN a currency, use LEND or LOAN constants as direction
func (s *OffersService) Status(offerId int64) (Offer, error)
type Order struct {
ID int64
Symbol string
Exchange string
Price string
AvgExecutionPrice string `json:"avg_execution_price"`
Side string
Type string
Timestamp string
IsLive bool `json:"is_live"`
IsCanceled bool `json:"is_cancelled"`
IsHidden bool `json:"is_hidden"`
WasForced bool `json:"was_forced"`
OriginalAmount string `json:"original_amount"`
RemainingAmount string `json:"remaining_amount"`
ExecutedAmount string `json:"executed_amount"`
}
Order represents one order on the bitfinex platform.
type OrderBook struct {
Bids []OrderBookEntry
Asks []OrderBookEntry
}
type OrderBookEntry struct {
Price string
Rate string
Amount string
Period int
Timestamp string
Frr string
}
func (el *OrderBookEntry) ParseTime() (*time.Time, error)
type OrderBookService struct {
}
func (s *OrderBookService) Get(pair string, limitBids, limitAsks int, noGroup bool) (OrderBook, error)
GET /book
type OrderService struct {
}
OrderService manages the Order endpoint.
func (s *OrderService) All() ([]Order, error)
All returns all orders for the authenticated account.
func (s *OrderService) Cancel(orderID int64) error
Cancel the order with id orderID
.
func (s *OrderService) CancelAll() error
CancelAll active orders for the authenticated account.
func (s *OrderService) CancelMulti(orderIDS []int64) (string, error)
CancelMulti allows batch cancellation of orders.
func (s *OrderService) Create(symbol string, amount float64, price float64, orderType string) (*Order, error)
Create a new order.
func (s *OrderService) CreateMulti(orders []SubmitOrder) (MultipleOrderResponse, error)
CreateMulti allows batch creation of orders.
func (s *OrderService) Replace(orderID int64, useRemaining bool, newOrder SubmitOrder) (Order, error)
Replace an Order
func (s *OrderService) Status(orderID int64) (Order, error)
Status retrieves the given order from the API.
type Pair struct {
Pair string
PricePrecision int `json:"price_precision,int"`
InitialMargin float64 `json:"initial_margin,string"`
MinimumMargin float64 `json:"minimum_margin,string"`
MaximumOrderSize float64 `json:"maximum_order_size,string"`
MinimumOrderSize float64 `json:"minimum_order_size,string"`
Expiration string
Margin bool
}
Detailed Pair
type PairsService struct {
}
func (p *PairsService) All() ([]string, error)
Get all Pair names as array of strings
func (p *PairsService) AllDetailed() ([]Pair, error)
Return a list of detailed pairs
type PastTrade struct {
Price string
Amount string
Timestamp string
Exchange string
Type string
FeeCurrency string `json:"fee_currency"`
FeeAmount string `json:"fee_amount"`
TID int64
OrderId int64 `json:"order_id,int"`
}
type Permissions struct {
Account KeyPerm
History KeyPerm
Orders KeyPerm
Positions KeyPerm
Funding KeyPerm
Wallets KeyPerm
Withdraw KeyPerm
}
type Position struct {
ID int
Symbol string
Amount string
Status string
Base string
Timestamp string
Swap string
Pl string
}
Position structure
func (p *Position) ParseTime() (*time.Time, error)
type PositionsService struct {
}
PositionsService structure
func (b *PositionsService) All() ([]Position, error)
All - gets all positions
func (b *PositionsService) Claim(positionId int, amount string) (Position, error)
Claim a position
type Response struct {
Response *http.Response
Body []byte
}
Response is wrapper for standard http.Response and provides more methods.
func (r *Response) String() string
String converts response body to string. An empty string will be returned if error.
type Stats struct {
Period int64
Volume float64 `json:"volume,string"`
}
type StatsService struct {
}
func (s *StatsService) All(pair string, period, volume string) ([]Stats, error)
All(pair) - Volume stats for specified pair
type SubmitOrder struct {
Symbol string
Amount float64
Price float64
Type string
}
SubmitOrder is an order to be created on the bitfinex platform.
type Summary struct {
TradeVolume SummaryVolume `json:"trade_vol_30d"`
FundingProfit SummaryProfit `json:"funding_profit_30d"`
MakerFee string `json:"maker_fee"`
TakerFee string `json:"taker_fee"`
}
type SummaryProfit struct {
Currency string `json:"curr"`
Volume string `json:"amount"`
}
type SummaryVolume struct {
Currency string `json:"curr"`
Volume string `json:"vol"`
}
type TermData struct {
// Data term. E.g: ps, ws, ou, etc... See official documentation for more details.
Term string
// Data will contain different number of elements for each term.
// Examples:
// Term: ws, Data: ["exchange","BTC",0.01410829,0]
// Term: oc, Data: [0,"BTCUSD",0,-0.01,"","CANCELED",270,0,"2015-10-15T11:26:13Z",0]
Data []interface{}
Error string
}
func (c *TermData) HasError() bool
type Tick struct {
Mid string
Bid string
Ask string
LastPrice string `json:"last_price"`
Low string
High string
Volume string
Timestamp string
}
func (el *Tick) ParseTime() (*time.Time, error)
ParseTime - return Timestamp in time.Time format
type TickerService struct {
}
func (s *TickerService) Get(pair string) (Tick, error)
Get(pair) - return last Tick for specified pair
type Trade struct {
Price string
Amount string
Exchange string
Type string
Timestamp int64
TradeId int64 `json:"tid,int"`
}
func (el *Trade) Time() *time.Time
type TradesService struct {
}
func (s *TradesService) All(pair string, timestamp time.Time, limitTrades int) ([]Trade, error)
type TransferStatus struct {
Status string
Message string
}
type WalletBalance struct {
Type string
Currency string
Amount string
Available string
}
type WalletService struct {
}
func (c *WalletService) Transfer(amount float64, currency, from, to string) ([]TransferStatus, error)
Transfer funds between wallets
func (c *WalletService) WithdrawCrypto(amount float64, currency, wallet, destinationAddress string) ([]WithdrawStatus, error)
Withdraw a cryptocurrency to a digital wallet
func (c *WalletService) WithdrawWire(amount float64, expressWire bool, wallet string, beneficiaryBank, intermediaryBank BankAccount, message string) ([]WithdrawStatus, error)
type WebSocketService struct {
}
WebSocketService allow to connect and receive stream data from bitfinex.com ws service. nolint:megacheck,structcheck
func NewWebSocketService(c *Client) *WebSocketService
NewWebSocketService returns a WebSocketService using the given client.
func (w *WebSocketService) AddSubscribe(channel string, pair string, c chan []float64)
func (w *WebSocketService) ClearSubscriptions()
func (w *WebSocketService) Close()
Close web socket connection
func (w *WebSocketService) Connect() error
Connect create new bitfinex websocket connection
func (w *WebSocketService) ConnectPrivate(ch chan TermData)
func (w *WebSocketService) Subscribe() error
Subscribe allows to subsribe to channels and watch for new updates. This method supports next channels: book, trade, ticker.
type WithdrawStatus struct {
Status string
Message string
WithdrawalID int `json:"withdrawal_id"`
}