Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V1 REST PUBLIC ENDPOINTS - SYMBOLS & SYMBOLS DETAILS #235

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 22 additions & 18 deletions v1/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,26 @@ type Client struct {
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
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
Symbols *SymbolsService
SymbolsDetails *SymbolsDetailsService
}

// NewClient creates new Bitfinex.com API client.
Expand All @@ -76,6 +78,8 @@ func NewClient() *Client {
c.Trades = &TradesService{client: c}
c.Positions = &PositionsService{client: c}
c.Wallet = &WalletService{client: c}
c.Symbols = &SymbolsService{client: c}
c.SymbolsDetails = &SymbolsDetailsService{client: c}
c.WebSocket = NewWebSocketService(c)
c.WebSocketTLSSkipVerify = false

Expand Down
26 changes: 26 additions & 0 deletions v1/symbols.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package bitfinex

import (
"net/url"
)

type SymbolsService struct {
client *Client
}

func (s *SymbolsService) GetSymbols() ([]string, error) {
params := url.Values{}
req, err := s.client.newRequest("GET", "symbols", params)
if err != nil {
return nil, err
}

var v []string

_, err = s.client.do(req, &v)
if err != nil {
return nil, err
}

return v, nil
}
36 changes: 36 additions & 0 deletions v1/symbols_details.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package bitfinex

import (
"net/url"
)

type SymbolsDetailsService struct {
client *Client
}

type SymbolDetail struct {
Pair string `json:"pair"`
PricePrecision int `json:"price_precision"`
InitialMargin string `json:"initial_margin"`
MinimumMargin string `json:"minimum_margin"`
MaximumOrderSize string `json:"maximum_order_size"`
MinimumOrderSize string `json:"minimum_order_size"`
Expiration string `json:"expiration"`
}

func (s *SymbolsDetailsService) GetSymbolsDetails() ([]SymbolDetail, error) {
params := url.Values{}
req, err := s.client.newRequest("GET", "symbols_details", params)
if err != nil {
return nil, err
}

var v []SymbolDetail

_, err = s.client.do(req, &v)
if err != nil {
return nil, err
}

return v, nil
}
36 changes: 36 additions & 0 deletions v1/symbols_details_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package bitfinex

import (
"bytes"
"io/ioutil"
"net/http"
"testing"
)

func TestSymbolsDetailsGet(t *testing.T) {
httpDo = func(req *http.Request) (*http.Response, error) {
msg := `{
"pair":"btcusd",
"price_precision":5,
"initial_margin":"30.0",
"minimum_margin":"15.0",
"maximum_order_size":"2000.0",
"minimum_order_size":"0.01",
"expiration":"NA"
}`
resp := http.Response{
Body: ioutil.NopCloser(bytes.NewBufferString(msg)),
StatusCode: 200,
}
return &resp, nil
}

symbolsDetails, err := NewClient().SymbolsDetails.GetSymbolsDetails()
if err != nil {
t.Error(err)
}
if len(symbolsDetails) != 1 {
t.Error("Expected", 1)
t.Error("Actual ", len(symbolsDetails))
}
}
32 changes: 32 additions & 0 deletions v1/symbols_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package bitfinex

import (
"bytes"
"io/ioutil"
"net/http"
"testing"
)

func TestSymbolsGet(t *testing.T) {
httpDo = func(req *http.Request) (*http.Response, error) {
msg := `[
"btcusd",
"ltcusd",
"ltcbtc",
]`
resp := http.Response{
Body: ioutil.NopCloser(bytes.NewBufferString(msg)),
StatusCode: 200,
}
return &resp, nil
}

symbols, err := NewClient().Symbols.GetSymbols()
if err != nil {
t.Error(err)
}
if len(symbols) != 3 {
t.Error("Expected", 3)
t.Error("Actual ", len(symbols))
}
}