bitfinex

package
v0.0.0-...-b79666c Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2017 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package bitfinex is the official client to access to bitfinex.com API

Index

Constants

View Source
const (
	// BaseURL is the v2 REST endpoint.
	BaseURL = "https://api.bitfinex.com/v2/"

	// WebSocketURL is the v2 Websocket endpoint.
	WebSocketURL = "wss://api.bitfinex.com/ws/2"
)
View Source
const (
	OrderTypeMarket               = "MARKET"
	OrderTypeExchangeMarket       = "EXCHANGE MARKET"
	OrderTypeLimit                = "LIMIT"
	OrderTypeExchangeLimit        = "EXCHANGE LIMIT"
	OrderTypeStop                 = "STOP"
	OrderTypeExchangeStop         = "EXCHANGE STOP"
	OrderTypeTrailingStop         = "TRAILING STOP"
	OrderTypeExchangeTrailingStop = "EXCHANGE TRAILING STOP"
	OrderTypeFOK                  = "FOK"
	OrderTypeExchangeFOK          = "EXCHANGE FOK"
	OrderTypeStopLimit            = "STOP LIMIT"
)
View Source
const (
	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"
)

Available pairs

View Source
const (
	ChanBook    = "book"
	ChanTrades  = "trades"
	ChanTicker  = "ticker"
	ChanCandles = "candles"
)

Available channels

View Source
const (
	FundingPrefix = "f"
	TradingPrefix = "t"
)

Prefixes for available pairs

Variables

View Source
var (
	ErrNotFound = errors.New("not found")
)
View Source
var ErrWSNotConnected = fmt.Errorf("websocket connection not established")

Functions

This section is empty.

Types

type AuthEvent

type AuthEvent struct {
	Event   string       `json:"event"`
	Status  string       `json:"status"`
	ChanID  int64        `json:"chanId,omitempty"`
	UserID  int64        `json:"userId,omitempty"`
	SubID   string       `json:"subId"`
	AuthID  string       `json:"auth_id,omitempty"`
	Message string       `json:"msg,omitempty"`
	Caps    Capabilities `json:"caps"`
}

type BalanceInfo

type BalanceInfo struct {
	TotalAUM   float64
	NetAUM     float64
	WalletType string
	Currency   string
}

type BalanceUpdate

type BalanceUpdate BalanceInfo

type Capabilities

type Capabilities struct {
	Orders    Capability `json:"orders"`
	Account   Capability `json:"account"`
	Funding   Capability `json:"funding"`
	History   Capability `json:"history"`
	Wallets   Capability `json:"wallets"`
	Withdraw  Capability `json:"withdraw"`
	Positions Capability `json:"positions"`
}

type Capability

type Capability struct {
	Read  int `json:"read"`
	Write int `json:"write"`
}

type Client

type Client struct {
	// Base URL for API requests.
	BaseURL *url.URL

	HTTPClient *http.Client

	// Auth data
	APIKey    string
	APISecret string

	// Services
	Websocket *bfxWebsocket
	Orders    *OrderService
	Platform  *PlatformService
	Positions *PositionService
	Trades    *TradeService
}

func NewClient

func NewClient() *Client

func NewClientWithHTTP

func NewClientWithHTTP(h *http.Client) *Client

func (*Client) Credentials

func (c *Client) Credentials(key string, secret string) *Client

Credentials sets api key and secret for usage is requests that requires authentication

type ConfEvent

type ConfEvent struct {
	Flags int `json:"flags"`
}

type Credit

type Credit struct {
	ID            int64
	Symbol        string
	Side          string
	MTSCreated    int64
	MTSUpdated    int64
	Amout         float64
	Flags         interface{}
	Status        CreditStatus
	Rate          float64
	Period        int64
	MTSOpened     int64
	MTSLastPayout int64
	Notify        bool
	Hidden        bool
	Insure        bool
	Renew         bool
	RateReal      float64
	NoClose       bool
	PositionPair  string
}

type CreditStatus

type CreditStatus string
const (
	CreditStatusActive          CreditStatus = "ACTIVE"
	CreditStatusExecuted        CreditStatus = "EXECUTED"
	CreditStatusPartiallyFilled CreditStatus = "PARTIALLY FILLED"
	CreditStatusCanceled        CreditStatus = "CANCELED"
)

type ErrorEvent

type ErrorEvent struct {
	Code    int    `json:"code"`
	Message string `json:"msg"`
}

type ErrorResponse

type ErrorResponse struct {
	Response *Response
	Message  string `json:"message"`
	Code     int    `json:"code"`
}

In case if API will wrong response code ErrorResponse will be returned to caller

func (*ErrorResponse) Error

func (r *ErrorResponse) Error() string

type FundingCreditCancel

type FundingCreditCancel Credit

type FundingCreditNew

type FundingCreditNew Credit

type FundingCreditSnapshot

type FundingCreditSnapshot []Credit

type FundingCreditUpdate

type FundingCreditUpdate Credit

type FundingInfo

type FundingInfo struct {
	Symbol       string
	YieldLoan    float64
	YieldLend    float64
	DurationLoan float64
	DurationLend float64
}

type FundingLoanCancel

type FundingLoanCancel Loan

type FundingLoanNew

type FundingLoanNew Loan

type FundingLoanSnapshot

type FundingLoanSnapshot []Loan

type FundingLoanUpdate

type FundingLoanUpdate Loan

type FundingOfferCancel

type FundingOfferCancel Offer

type FundingOfferNew

type FundingOfferNew Offer

type FundingOfferSnapshot

type FundingOfferSnapshot []Offer

type FundingOfferUpdate

type FundingOfferUpdate Offer

type FundingTrade

type FundingTrade struct {
	ID         int64
	Symbol     string
	MTSCreated int64
	OfferID    int64
	Amount     float64
	Rate       float64
	Period     int64
	Maker      int64
}

type FundingTradeExecution

type FundingTradeExecution FundingTrade

type FundingTradeSnapshot

type FundingTradeSnapshot []FundingTrade

type FundingTradeUpdate

type FundingTradeUpdate FundingTrade

type Heartbeat

type Heartbeat struct {
}

type HistoricalCredit

type HistoricalCredit Credit

type HistoricalFundingTradeSnapshot

type HistoricalFundingTradeSnapshot FundingTradeSnapshot

type HistoricalLoan

type HistoricalLoan Loan

type HistoricalOffer

type HistoricalOffer Offer

type HistoricalTradeSnapshot

type HistoricalTradeSnapshot TradeSnapshot

type InfoEvent

type InfoEvent struct {
	Version int `json:"version"`
}

type Loan

type Loan struct {
	ID            int64
	Symbol        string
	Side          string
	MTSCreated    int64
	MTSUpdated    int64
	Amout         float64
	Flags         interface{}
	Status        LoanStatus
	Rate          float64
	Period        int64
	MTSOpened     int64
	MTSLastPayout int64
	Notify        bool
	Hidden        bool
	Insure        bool
	Renew         bool
	RateReal      float64
	NoClose       bool
}

type LoanStatus

type LoanStatus string
const (
	LoanStatusActive          LoanStatus = "ACTIVE"
	LoanStatusExecuted        LoanStatus = "EXECUTED"
	LoanStatusPartiallyFilled LoanStatus = "PARTIALLY FILLED"
	LoanStatusCanceled        LoanStatus = "CANCELED"
)

type MarginInfoBase

type MarginInfoBase struct {
	UserProfitLoss float64
	UserSwaps      float64
	MarginBalance  float64
	MarginNet      float64
}

type MarginInfoUpdate

type MarginInfoUpdate struct {
	Symbol          string
	TradableBalance float64
}

type Notification

type Notification struct {
	MTS        int64
	Type       string
	MessageID  int64
	NotifyInfo interface{}
	Code       *int64
	Status     string
	Text       string
}

type Offer

type Offer struct {
	ID         int64
	Symbol     string
	MTSCreated int64
	MTSUpdated int64
	Amout      float64
	AmountOrig float64
	Type       string
	Flags      interface{}
	Status     OfferStatus
	Rate       float64
	Period     int64
	Notify     bool
	Hidden     bool
	Insure     bool
	Renew      bool
	RateReal   float64
}

type OfferStatus

type OfferStatus string
const (
	OfferStatusActive          OfferStatus = "ACTIVE"
	OfferStatusExecuted        OfferStatus = "EXECUTED"
	OfferStatusPartiallyFilled OfferStatus = "PARTIALLY FILLED"
	OfferStatusCanceled        OfferStatus = "CANCELED"
)

type Order

type Order struct {
	ID            int64
	GID           int64
	CID           int64
	Symbol        string
	MTSCreated    int64
	MTSUpdated    int64
	Amount        float64
	AmountOrig    float64
	Type          string
	TypePrev      string
	Flags         int64
	Status        OrderStatus
	Price         float64
	PriceAvg      float64
	PriceTrailing float64
	PriceAuxLimit float64
	Notify        bool
	Hidden        bool
	PlacedID      int64
}

Order as returned from the bitfinex websocket service.

type OrderCancel

type OrderCancel Order

OrderCancel gets sent out after an Order was cancelled successfully.

type OrderCancelRequest

type OrderCancelRequest struct {
	ID      *int64  `json:"id,omitempty"`
	CID     *int64  `json:"cid,omitempty"`
	CIDDate *string `json:"cid_date,omitempty"`
}

OrderCancelRequest represents an order cancel request. An order can be cancelled using the internal ID or a combination of Client ID (CID) and the daten for the given CID.

func (*OrderCancelRequest) MarshalJSON

func (o *OrderCancelRequest) MarshalJSON() ([]byte, error)

MarshalJSON converts the order cancel object into the format required by the bitfinex websocket service.

type OrderNew

type OrderNew Order

OrderNew gets sent out after an Order was created successfully.

type OrderNewRequest

type OrderNewRequest struct {
	GID           int64   `json:"gid"`
	CID           int64   `json:"cid"`
	Type          string  `json:"type"`
	Symbol        string  `json:"symbol"`
	Amount        float64 `json:"amount,string"`
	Price         float64 `json:"price,string"`
	PriceTrailing float64 `json:"price_trailing,string,omitempty"`
	PriceAuxLimit float64 `json:"price_aux_limit,string,omitempty"`
	Hidden        bool    `json:"hidden,omitempty"`
	PostOnly      bool    `json:"postonly,omitempty"`
}

OrderNewRequest represents an order to be posted to the bitfinex websocket service.

func (*OrderNewRequest) MarshalJSON

func (o *OrderNewRequest) MarshalJSON() ([]byte, error)

MarshalJSON converts the order object into the format required by the bitfinex websocket service.

type OrderService

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

OrderService manages the Order endpoint.

func (*OrderService) All

func (s *OrderService) All(symbol string) (OrderSnapshot, error)

All returns all orders for the authenticated account.

func (*OrderService) History

func (s *OrderService) History(symbol string) (OrderSnapshot, error)

All returns all orders for the authenticated account.

func (*OrderService) Status

func (s *OrderService) Status(orderID int64) (o Order, err error)

Status retrieves the given order from the API. This is just a wrapper around the All() method, since the API does not provide lookup for a single Order.

type OrderSnapshot

type OrderSnapshot []Order

OrderSnapshot is a collection of Orders that would usually be sent on inital connection.

type OrderStatus

type OrderStatus string

OrderStatus represents the possible statuses an order can be in.

const (
	OrderStatusActive          OrderStatus = "ACTIVE"
	OrderStatusExecuted        OrderStatus = "EXECUTED"
	OrderStatusPartiallyFilled OrderStatus = "PARTIALLY FILLED"
	OrderStatusCanceled        OrderStatus = "CANCELED"
)

type OrderType

type OrderType string

OrderType represents the types orders the bitfinex platform can handle.

type OrderUpdate

type OrderUpdate Order

OrderUpdate is an Order that gets sent out after every change to an order.

type PlatformService

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

func (*PlatformService) Status

func (p *PlatformService) Status() (bool, error)

Status indicates whether the platform is currently operative or not.

type Position

type Position struct {
	Symbol               string
	Status               PositionStatus
	Amount               float64
	BasePrice            float64
	MarginFunding        float64
	MarginFundingType    int64
	ProfitLoss           float64
	ProfitLossPercentage float64
	LiquidationPrice     float64
	Leverage             float64
}

type PositionCancel

type PositionCancel Position

type PositionNew

type PositionNew Position

type PositionService

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

PositionService manages the Position endpoint.

func (*PositionService) All

All returns all positions for the authenticated account.

type PositionSnapshot

type PositionSnapshot []Position

type PositionStatus

type PositionStatus string
const (
	PositionStatusActive PositionStatus = "ACTIVE"
	PositionStatusClosed PositionStatus = "CLOSED"
)

type PositionUpdate

type PositionUpdate Position

type PublicSubscriptionRequest

type PublicSubscriptionRequest struct {
	Event     string `json:"event"`
	Channel   string `json:"channel"`
	Symbol    string `json:"symbol"`
	Precision string `json:"prec,omitempty"`
	Frequency string `json:"freq,omitempty"`
	Key       string `json:"key,omitempty"`
	Len       string `json:"len,omitempty"`
	Pair      string `json:"pair,omitempty"`
	SubID     string `json:"subId,omitempty"`
}

PublicSubscriptionRequest is used to subscribe to one of the public websocket channels. The `Event` field is automatically set to `subscribe` when using the Subscribe method. The `Channel` field is mandatory. For all other fields please consult the officical documentation here: http://docs.bitfinex.com/v2/reference#ws-public-ticker

type Response

type Response struct {
	Response *http.Response
	Body     []byte
}

Response is wrapper for standard http.Response and provides more methods.

func (*Response) String

func (r *Response) String() string

String converts response body to string. An empty string will be returned if error.

type SubscribeEvent

type SubscribeEvent struct {
	SubID     string `json:"subId"`
	Channel   string `json:"channel"`
	ChanID    int64  `json:"chanId"`
	Symbol    string `json:"symbol"`
	Precision string `json:"prec,omitempty"`
	Frequency string `json:"freq,omitempty"`
	Key       string `json:"key,omitempty"`
	Len       string `json:"len,omitempty"`
	Pair      string `json:"pair"`
}

type Ticker

type Ticker struct {
	Symbol          string
	Bid             float64
	BidPeriod       int64
	BidSize         float64
	Ask             float64
	AskPeriod       int64
	AskSize         float64
	DailyChange     float64
	DailyChangePerc float64
	LastPrice       float64
	Volume          float64
	High            float64
	Low             float64
}

type TickerSnapshot

type TickerSnapshot []Ticker

type TickerUpdate

type TickerUpdate Ticker

type Trade

type Trade struct {
	ID          int64
	Pair        string
	MTSCreate   int64
	OrderID     int64
	ExecAmout   float64
	ExecPrice   float64
	OrderType   string
	OrderPrice  float64
	Maker       bool
	Fee         float64
	FeeCurrency string
}

type TradeExecution

type TradeExecution struct {
	ID         int64
	Pair       string
	MTSCreate  int64
	OrderID    int64
	ExecAmout  float64
	ExecPrice  float64
	OrderType  string
	OrderPrice float64
	Maker      bool
}

type TradeService

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

TradeService manages the Trade endpoint.

func (*TradeService) All

func (s *TradeService) All(symbol string) (TradeSnapshot, error)

All returns all orders for the authenticated account.

type TradeSnapshot

type TradeSnapshot []Trade

type TradeUpdate

type TradeUpdate Trade

type UnsubscribeEvent

type UnsubscribeEvent struct {
	Status string `json:"status"`
	ChanID int64  `json:"chanId"`
}

type Wallet

type Wallet struct {
	Type              string
	Currency          string
	Balance           float64
	UnsettledInterest float64
	BalanceAvailable  *float64
}

type WalletSnapshot

type WalletSnapshot []Wallet

type WalletUpdate

type WalletUpdate Wallet

Jump to

Keyboard shortcuts

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