Documentation
¶
Overview ¶
Package mbc is a simple client for MercadoBitcoin API V3.
MercadoBitcoin Golang API Client ¶
References:
- Trading API (https://www.mercadobitcoin.com.br/trade-api/)
- Public APi (https://www.mercadobitcoin.com.br/api-doc/)
API Key and Secret ¶
You should generate an API key and secret to use the client.
In the examples, replace <ID> and <SECRET> with the generated ones.
Index ¶
- type Balance
- type Client
- func (c Client) Coins(ctx context.Context) ([]string, error)
- func (c Client) GetBalances(ctx context.Context) (map[string]Balance, error)
- func (c Client) GetWithdrawalLimits(ctx context.Context) (map[string]WithdrawalLimit, error)
- func (c *Client) ListOrders(ctx context.Context, base string, quote string, opts ...ListOrdersOption) ([]Order, error)
- func (c Client) Orderbook(ctx context.Context, base string, quote string, opts ...OrderbookOption) (Orderbook, error)
- func (c Client) Ticker(ctx context.Context, base string, quote string) (Ticker, error)
- func (c Client) Trades(ctx context.Context, base string, quote string, opts ...TradesOption) ([]Trade, error)
- type ClientOpt
- type ListOrdersOption
- func FromID(id string) ListOrdersOption
- func FromTimestamp(ts int64) ListOrdersOption
- func HasFills(has bool) ListOrdersOption
- func ToID(id string) ListOrdersOption
- func ToTimestamp(ts int64) ListOrdersOption
- func WithOrderTypes(t OrderType) ListOrdersOption
- func WithStatuses(statuses ...OrderStatus) ListOrdersOption
- type Operation
- type Order
- type OrderStatus
- type OrderType
- type Orderbook
- type OrderbookOption
- type StatusCode
- type Ticker
- type Trade
- type TradesOption
- type WithdrawalLimit
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Balance ¶
type Balance struct { Available string `json:"available,omitempty"` Total string `json:"total,omitempty"` }
Balance represents a balance
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents a MercadoBitcoin API client
func New ¶
New creates a client for an user id/secret
Example ¶
Creates a client for public and private requests
client := New() client.Trades(context.Background(), "btc", "brl")
Output:
func (Client) GetBalances ¶
GetBalances retrieves balances
func (Client) GetWithdrawalLimits ¶
GetWithdrawalLimits retrieves withdrawal limits
func (*Client) ListOrders ¶
func (c *Client) ListOrders(ctx context.Context, base string, quote string, opts ...ListOrdersOption) ([]Order, error)
ListOrders lists user orders
func (Client) Orderbook ¶
func (c Client) Orderbook(ctx context.Context, base string, quote string, opts ...OrderbookOption) (Orderbook, error)
Orderbook retrieves ticker for base/quote
Example ¶
client := New() o, _ := client.Orderbook(context.Background(), "btc", "brl", WithLimit(1)) b, _ := json.MarshalIndent(o, "", " ") fmt.Println(string(b))
Output: { "asks": [ [241671.49, 0.01923905], [241831.86, 0.00205555] ], "bids": [ [241664.97001, 0.05772251], [241664.95, 0.14321774] ], "timestamp":1628561698332025456 }
func (Client) Ticker ¶
Ticker retrieves ticker for base/quote
Example ¶
client := New() o, _ := client.Ticker(context.Background(), "btc", "brl") b, _ := json.MarshalIndent(o, "", " ") fmt.Println(string(b))
Output: { "ticker": { "high": "244900.00000000", "low": "227539.84013000", "vol": "158.76695397", "last": "241671.93011000", "buy": "241671.93011000", "sell": "242021.99998000", "open": "228450.00000000", "date": 1628563357 } }
func (Client) Trades ¶
func (c Client) Trades(ctx context.Context, base string, quote string, opts ...TradesOption) ([]Trade, error)
Trades lists trades
Example ¶
client := New() o, _ := client.Trades(context.Background(), "btc", "brl", FromTid(90000)) b, _ := json.MarshalIndent(o, "", " ") fmt.Println(string(b))
Output: [ { "tid": 90001, "date": 1414274533, "type": "buy", "price": 919.7789, "amount": 0.41666409 }, { "tid": 90002, "date": 1414274533, "type": "buy", "price": 919.9913, "amount": 0.66149665 } ]
type ClientOpt ¶
type ClientOpt func(client *Client)
ClientOpt represents a client option
func WithIdSecret ¶
WithIdSecret adds id/secret auth option to client
type ListOrdersOption ¶
ListOrdersOption represents a request option
func FromTimestamp ¶
func FromTimestamp(ts int64) ListOrdersOption
FromTimestamp adds lower limit for timestamp
func ToTimestamp ¶
func ToTimestamp(ts int64) ListOrdersOption
ToTimestamp adds lower limit for timestamp
func WithOrderTypes ¶
func WithOrderTypes(t OrderType) ListOrdersOption
WithOrderTypes adds order type filter
func WithStatuses ¶
func WithStatuses(statuses ...OrderStatus) ListOrdersOption
WithStatuses adds status filter
type Operation ¶
type Operation struct { ID int `json:"operation_id"` Qty string `json:"quantity"` Price string `json:"price"` FeeRate string `json:"fee_rate"` ExecutedTimestamp string `json:"executed_timestamp"` }
Operation represents an operation
type Order ¶
type Order struct { ID int `json:"order_id"` Pair string `json:"coin_pair"` OrderType OrderType `json:"order_type"` Status int `json:"status"` HasFills bool `json:"has_fills"` Qty string `json:"quantity"` LimitPrice string `json:"limit_price"` ExecutedQuantity string `json:"executed_quantity"` ExecutedPriceAvg string `json:"executed_price_avg"` Fee string `json:"fee"` CreatedAt string `json:"created_timestamp"` UpdatedAt string `json:"updated_timestamp"` Operations []Operation `json:"operations"` }
Order represents an order
type OrderStatus ¶
type OrderStatus int
OrderStatus represents the order status
var ( // Pending pending order status Pending OrderStatus = 1 // Open open order status Open OrderStatus = 2 // Cancelled cancelled order status Cancelled OrderStatus = 3 // Filled filled order status Filled OrderStatus = 4 )
type Orderbook ¶
type Orderbook struct { Asks [][]float64 `json:"asks"` Bids [][]float64 `json:"bids"` Timestamp int64 `json:"timestamp"` }
Orderbook represents the orderbook
type OrderbookOption ¶
OrderbookOption represents orderbook request option
func WithLimit ¶
func WithLimit(limit int) OrderbookOption
WithLimit adds limit to orderbook request
type StatusCode ¶
type StatusCode int
StatusCode represents the response status
const ( // ErrorCode general error code ErrorCode StatusCode = 201 // SuccessCode success error code SuccessCode StatusCode = 100 )
type Ticker ¶
type Ticker struct { High string `json:"high"` Low string `json:"low"` Vol string `json:"vol"` Last string `json:"last"` Buy string `json:"buy"` Sell string `json:"sell"` Open string `json:"open"` Date int64 `json:"date"` }
Ticker represents the ticker
type Trade ¶
type Trade struct { Tid int64 `json:"tid"` Date int64 `json:"date"` Type string `json:"type"` Price float64 `json:"price"` Amount float64 `json:"amount"` }
Trade represents a trade
type TradesOption ¶
TradesOption represents a trades request option
type WithdrawalLimit ¶
type WithdrawalLimit struct { Available string `json:"available,omitempty"` Total string `json:"total,omitempty"` }
WithdrawalLimit represents a withdrawal limit