bitfinex

package module
v0.0.0-...-053ae90 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2016 License: MIT Imports: 14 Imported by: 0

README

Bitfinex api for golang

Installation

go get github.com/bitfinexcom/bitfinex-api-go

Usage

Basic requests
package main

import (
	"fmt"
	"github.com/bitfinexcom/bitfinex-api-go"
)

func main() {
	client := bitfinex.NewClient().Auth("api-key", "api-secret")
	info, err := client.Account.Info()

	if err != nil {
		fmt.Println(err)
	} else {
		fmt.Println(info)
	}
}
Authentication
func main() {
	client := bitfinex.NewClient().Auth("api-key", "api-secret")
}
Order create
order, err := client.Orders.Create(bitfinex.BTCUSD, -0.01, 260.99, bitfinex.ORDER_TYPE_EXCHANGE_LIMIT)

if err != nil {
    return err
} else {
    return order
}

See examples and doc.go for more examples.

Testing

All integration tests are stored in tests/integration directory. Because these tests are running using live data, there is a much higher probability of false positives in test failures due to network issues, test data having been changed, etc.

Run tests using:

export BFX_API_KEY="api-key"
export BFX_API_SECRET="api-secret"
go test -v ./tests/integration

Contributing

  1. Fork it (https://github.com/bitfinexcom/bitfinex-api-go/fork)
  2. Create your feature branch (`git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Documentation

Index

Constants

View Source
const (
	BaseURL      = "https://api.bitfinex.com/v1/"
	WebSocketURL = "wss://api2.bitfinex.com:3000/ws"
)

TODO: use var instead of const

View Source
const (
	ORDER_TYPE_MARKET                 = "market"
	ORDER_TYPE_LIMIT                  = "limit"
	ORDER_TYPE_STOP                   = "stop"
	ORDER_TYPE_TRAILING_STOP          = "trailing-stop"
	ORDER_TYPE_FILL_OR_KILL           = "fill-or-kill"
	ORDER_TYPE_EXCHANGE_MARKET        = "exchange market"
	ORDER_TYPE_EXCHANGE_LIMIT         = "exchange limit"
	ORDER_TYPE_EXCHANGE_STOP          = "exchange stop"
	ORDER_TYPE_EXCHANGE_TRAILING_STOP = "exchange trailing-stop"
	ORDER_TYPE_EXCHANGE_FILL_OR_KILL  = "exchange fill-or-kill"
)
View Source
const (
	// Pairs
	BTCUSD = "BTCUSD"
	LTCUSD = "LTCUSD"
	LTCBTC = "LTCBTC"

	// Channels
	CHAN_BOOK   = "book"
	CHAN_TRADE  = "trade"
	CHAN_TICKER = "ticker"
)

Pairs available

Variables

This section is empty.

Functions

This section is empty.

Types

type AccountService

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

func (*AccountService) Info

func (a *AccountService) Info() (string, error)

TODO return struct GET account_infos

type BalancesService

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

func (*BalancesService) All

func (b *BalancesService) All() ([]WalletBalance, error)

GET balances

type Client

type Client struct {

	// Base URL for API requests.
	BaseURL *url.URL

	// Auth data
	ApiKey    string
	ApiSecret string

	// Services
	Pairs      *PairsService
	Account    *AccountService
	Balances   *BalancesService
	Credits    *CreditsService
	Lendbook   *LendbookService
	MarginInfo *MarginInfoService
	OrderBook  *OrderBookServive
	Orders     *OrderService
	WebSocket  *WebSocketService
	// contains filtered or unexported fields
}

func NewClient

func NewClient() *Client

NewClient creates new Bitfinex.com API http client

func (*Client) Auth

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

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

func (*Client) Do

func (c *Client) Do(req *http.Request, v interface{}) (*Response, error)

Do executes API request created by NewRequest method or custom *http.Request.

func (*Client) NewAuthenticatedRequest

func (c *Client) NewAuthenticatedRequest(m string, refUrl string, data map[string]interface{}) (*http.Request, error)

NewAuthenticatedRequest creates new http request for authenticated routes

func (*Client) NewRequest

func (c *Client) NewRequest(method string, refUrl string) (*http.Request, error)

NewRequest create new API request. Relative url can be provided in refUrl.

func (*Client) SignPayload

func (c *Client) SignPayload(payload string) string

type Credit

type Credit struct {
	Id        int
	Currency  string
	Status    string
	Rate      float64
	Period    float64
	Amount    float64
	Timestamp string
}

type CreditsService

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

func (*CreditsService) All

func (c *CreditsService) All() ([]Credit, error)

GET /credits

type ErrorResponse

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

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

func (*ErrorResponse) Error

func (r *ErrorResponse) Error() string

type Lendbook

type Lendbook struct {
	Bids []struct {
		Rate      string
		Amount    string
		Period    float64
		Timestamp string
		Frr       string
	}
	Asks []struct {
		Rate      string
		Amount    string
		Period    float64
		Timestamp string
		Frr       string
	}
}

type LendbookService

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

func (*LendbookService) Get

func (s *LendbookService) Get(currency string) (Lendbook, error)

TODO: Convert Rate and Amount to float64 currency: BTC LTC DRK USD GET /lendbook/:currency

func (*LendbookService) Lends

func (s *LendbookService) Lends(currency string) ([]Lends, error)

currency: BTC LTC DRK USD GET /lends/:currency

type Lends

type Lends struct {
	Rate       string
	AmountLent string `json:"amount_lent"`
	AmountUsed string `json:"amount_used"`
	Timestamp  float64
}

type MarginInfo

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

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

func (*MarginInfoService) All

func (s *MarginInfoService) All() ([]MarginInfo, error)

GET /margin_infos

type MarginLimit

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 Order

type Order struct {
	Id                int
	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"`
}

type OrderBook

type OrderBook struct {
	Bids []struct {
		Price     string
		Amount    string
		Timestamp string
	}
	Asks []struct {
		Price     string
		Amount    string
		Timestamp string
	}
}

type OrderBookServive

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

func (*OrderBookServive) Get

func (s *OrderBookServive) Get(currency string) (OrderBook, error)

TODO Convert price, amount to float64 GET /book

type OrderService

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

func (*OrderService) All

func (s *OrderService) All() ([]Order, error)

GET orders

func (*OrderService) Cancel

func (s *OrderService) Cancel(order_id int) error

POST order/cancel

func (*OrderService) CancelAll

func (s *OrderService) CancelAll() error

POST order/cancel/all

func (*OrderService) Create

func (s *OrderService) Create(symbol string, amount float64, price float64, orderType string) (*Order, error)

POST order/new symbol # The name of the symbol (see `/symbols`). price # Price to buy or sell at. May omit if a market order. amount # Order size: how much to buy or sell. Use negative amount to create sell order. side # Either "buy" or "sell". type # Either "market" / "limit" / "stop" / "trailing-stop" / "fill-or-kill" /

"exchange market" / "exchange limit" / "exchange stop" /
"exchange trailing-stop" / "exchange fill-or-kill"

type Pairs

type Pairs []string

type PairsService

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

func (*PairsService) All

func (p *PairsService) All() (*Pairs, error)

GET /symbols

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 SubscribeMsg

type SubscribeMsg struct {
	Event   string  `json:"event"`
	Channel string  `json:"channel"`
	Pair    string  `json:"pair"`
	ChanId  float64 `json:"chanId,omitempty"`
}

type TermData

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 (*TermData) HasError

func (c *TermData) HasError() bool

type WalletBalance

type WalletBalance struct {
	Type      string
	Currency  string
	Amount    string
	Available string
}

type WebSocketService

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

WebSocketService allow to connect and receive stream data from bitfinex.com ws service.

func NewWebSocketService

func NewWebSocketService(c *Client) *WebSocketService

func (*WebSocketService) AddSubscribe

func (w *WebSocketService) AddSubscribe(channel string, pair string, c chan []float64)

func (*WebSocketService) ClearSubscriptions

func (w *WebSocketService) ClearSubscriptions()

func (*WebSocketService) Close

func (w *WebSocketService) Close()

Close web socket connection

func (*WebSocketService) Connect

func (w *WebSocketService) Connect() error

Connect create new bitfinex websocket connection

func (*WebSocketService) ConnectPrivate

func (w *WebSocketService) ConnectPrivate(ch chan TermData)

func (*WebSocketService) Subscribe

func (w *WebSocketService) Subscribe()

Watch allows to subsribe to channels and watch for new updates. This method supports next channels: book, trade, ticker.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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