bitso

package
v0.0.0-...-9833547 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2023 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CurrencyNone Currency = ""

	AAVE = "aave"
	ARS  = "ars"
	AXS  = "axs"
	BAT  = "bat"
	BCH  = "bch"
	BRL  = "brl"
	BTC  = "btc"
	CHZ  = "chz"
	COMP = "comp"
	DAI  = "dai"
	DYDX = "dydx"
	ETH  = "eth"
	LINK = "link"
	LTC  = "ltc"
	MANA = "mana"
	MXN  = "mxn"
	SAND = "sand"
	TUSD = "tusd"
	UNI  = "uni"
	USD  = "usd"
	USDT = "usdt"
	XRP  = "xrp"
	YFI  = "yfi"
)

Currencies

Variables

View Source
var DefaultClient = NewClient(http.DefaultClient)

DefaultClient is the default Bitso API client to use.

Functions

This section is empty.

Types

type Balance

type Balance struct {
	Currency  Currency `json:"currency"`
	Total     Monetary `json:"total"`
	Locked    Monetary `json:"locked"`
	Available Monetary `json:"available"`
}

Balance represents the balance of a given currency.

type Book

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

Book represents an exchange book.

func NewBook

func NewBook(major Currency, minor Currency) *Book

NewBook returns a new exchange book from the given currencies.

func (Book) Major

func (b Book) Major() Currency

Major returns the major currency in the book.

func (Book) MarshalJSON

func (b Book) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (Book) Minor

func (b Book) Minor() Currency

Minor returns the minor currency in the book.

func (*Book) Scan

func (b *Book) Scan(value interface{}) error

func (Book) String

func (b Book) String() string

func (*Book) UnmarshalJSON

func (b *Book) UnmarshalJSON(in []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (Book) Value

func (b Book) Value() (driver.Value, error)

type Client

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

A Client is a Bitso API consumer

func NewClient

func NewClient(httpClient *http.Client) *Client

NewClient creates and returns a new Bitso API client.

func (*Client) APIPrefix

func (c *Client) APIPrefix() string

APIPrefix returns the API prefix

func (*Client) AvailableBooks

func (c *Client) AvailableBooks() ([]ExchangeOrderBook, error)

AvailableBooks returns a list of existing exchange order books and their respective order placement limits.

func (*Client) Balances

func (c *Client) Balances(params url.Values) ([]Balance, error)

Balances returns information concerning the user’s balances for all supported currencies.

func (*Client) BurstRate

func (c *Client) BurstRate() time.Duration

BurstRate returns the current burst-rate limit.

func (*Client) CancelOrder

func (c *Client) CancelOrder(oid string) ([]string, error)

CancelOrder cancels an open order

func (*Client) CancelOrders

func (c *Client) CancelOrders(oids []string) ([]string, error)

CancelOrders cancels open order(s)

func (*Client) Fees

func (c *Client) Fees(params url.Values) (*CustomerFees, error)

Fees returns information on customer fees for all available order books, and withdrawal fees for applicable currencies.

func (*Client) Fundings

func (c *Client) Fundings(params url.Values) ([]Funding, error)

Fundings returns detailed info on a user's fundings.

func (*Client) Ledger

func (c *Client) Ledger(params url.Values) ([]Transaction, error)

Ledger returns a list of all the user's registered operations.

func (*Client) LedgerByOperation

func (c *Client) LedgerByOperation(op Operation, params url.Values) ([]Transaction, error)

LedgerByOperation returns a list of all the user's registered operations.

func (*Client) LookupOrder

func (c *Client) LookupOrder(oid string) (*UserOrder, error)

LookupOrder returns details of an order given its order ID.

func (*Client) LookupOrders

func (c *Client) LookupOrders(oids []string) ([]UserOrder, error)

LookupOrders returns a list of details for 1 or more orders

func (*Client) MyOpenOrders

func (c *Client) MyOpenOrders(params url.Values) ([]UserOrder, error)

MyOpenOrders a list of the user's open orders.

func (*Client) MyTrades

func (c *Client) MyTrades(params url.Values) ([]UserTrade, error)

MyTrades returns a list of the user's trades.

func (*Client) OrderBook

func (c *Client) OrderBook(params url.Values) (*OrderBook, error)

OrderBook returns a list of all open orders in the specified book.

func (*Client) OrderTrades

func (c *Client) OrderTrades(oid string, params url.Values) ([]UserOrderTrade, error)

OrderTrades returns a list of the user's order trades on a given order.

func (*Client) PlaceOrder

func (c *Client) PlaceOrder(order *OrderPlacement) (string, error)

PlaceOrder places a buy or sell order (both limit and market orders are available)

func (*Client) SetAPIKey

func (c *Client) SetAPIKey(key string)

SetAPIKey sets the user key to use for private API calls.

func (*Client) SetAPIPrefix

func (c *Client) SetAPIPrefix(prefix string)

SetAPIPrefix sets the API prefix

func (*Client) SetAPISecret

func (c *Client) SetAPISecret(secret string)

SetAPISecret sets the user secret to use for private API calls.

func (*Client) SetBurstRate

func (c *Client) SetBurstRate(burstRate time.Duration)

SetBurstRate sets the amount of time the client should wait in between requests.

func (*Client) Ticker

func (c *Client) Ticker(book *Book) (*Ticker, error)

Ticker returns trading information from the specified book.

func (*Client) Tickers

func (c *Client) Tickers() ([]Ticker, error)

Tickers returns trading information from all books.

func (*Client) Trades

func (c *Client) Trades(params url.Values) ([]Trade, error)

Trades returns a list of recent trades from the specified book.

func (*Client) Withdraw

func (c *Client) Withdraw(withdrawal *WithdrawalPlacement) (string, error)

Withdraw places a buy or sell order (both limit and market orders are available)

func (*Client) Withdrawals

func (c *Client) Withdrawals(params url.Values) ([]Withdrawal, error)

Withdrawals returns detailed info on user's withdrawals

type Currency

type Currency string

Currency represents currencies

func ToCurrency

func ToCurrency(name string) Currency

func (Currency) MarshalJSON

func (c Currency) MarshalJSON() ([]byte, error)

func (*Currency) Scan

func (c *Currency) Scan(value interface{}) error

func (Currency) String

func (c Currency) String() string

func (*Currency) UnmarshalJSON

func (c *Currency) UnmarshalJSON(in []byte) error

func (Currency) Value

func (c Currency) Value() (driver.Value, error)

type CustomerFees

type CustomerFees struct {
	Fees           []Fee               `json:"fees"`
	WithdrawalFees map[string]Monetary `json:"withdrawal_fees"`
}

CustomerFees represents a list of fees that Bitso charges the user.

type Envelope

type Envelope struct {
	Success bool `json:"success"`
	Error   struct {
		Code    interface{} `json:"code"`
		Message string      `json:"message"`
	} `json:"error,omitempty"`
}

Envelope represents a common response envelope from Bitso API.

type Error

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

Error represents an API error

func (Error) Code

func (e Error) Code() int

Code returns the error code.

func (Error) Error

func (e Error) Error() string

Error returns the error message.

type ExchangeOrderBook

type ExchangeOrderBook struct {

	// Order book symbol
	Book Book `json:"book"`

	// Minimum amount of major when placing orders
	MinimumAmount Monetary `json:"minimum_amount"`
	// Maximum amount of major when placing orders
	MaximumAmount Monetary `json:"maximum_amount"`

	// Minimum price when placing orders
	MinimumPrice Monetary `json:"minimum_price"`
	// Maximum price when placing orders
	MaximumPrice Monetary `json:"maximum_price"`

	// Minimum value amount (amount*price) when placing orders
	MinimumValue Monetary `json:"minimun_value"`

	// Maximum value amount (amount*price) when placing orders
	MaximumValue Monetary `json:"maximum_value"`
}

ExchangeOrderBook represents order placement limits on books.

type Fee

type Fee struct {
	Book       Book     `json:"book"`
	FeeDecimal Monetary `json:"fee_decimal"`
	FeePercent Monetary `json:"fee_percent"`
}

Fee represents a Bitso fee.

type Funding

type Funding struct {
	FID       string                 `json:"fid"`
	Currency  Currency               `json:"currency"`
	Method    string                 `json:"method"`
	Amount    Monetary               `json:"amount"`
	Status    string                 `json:"status"`
	CreatedAt Time                   `json:"created_at"`
	Details   map[string]interface{} `json:"details"`
}

Funding represents the fundings of the user

type Monetary

type Monetary string

Monetary represents a monetary value

func ToMonetary

func ToMonetary(in float64) Monetary

ToMonetary converts a float64 value into Monetary

func (*Monetary) Decimal

func (m *Monetary) Decimal() (decimal.Decimal, error)

func (*Monetary) Float64

func (m *Monetary) Float64() float64

Float64 returns the monetary value as a float64

type Operation

type Operation uint8

Operation represents the type of a transaction operation.

const (
	OperationNone Operation = iota

	OperationFunding
	OperationWithdrawal
	OperationTrade
	OperationFee
)

List of operation types.

func (Operation) MarshalJSON

func (o Operation) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler

func (*Operation) Scan

func (o *Operation) Scan(value interface{}) error

func (Operation) String

func (o Operation) String() string

func (*Operation) UnmarshalJSON

func (o *Operation) UnmarshalJSON(in []byte) error

UnmarshalJSON implements json.Unmarshaler

func (Operation) Value

func (o Operation) Value() (driver.Value, error)

type Order

type Order struct {
	// Order book symbol
	Book Book `json:"book"`
	// Price per unit of major
	Price Monetary `json:"price"`
	// Major amount in order
	Amount Monetary `json:"amount"`
	// Order ID	(only for unaggregated order)
	OID string `json:"oid"`
}

Order represents a public order.

type OrderBook

type OrderBook struct {
	Asks      []Order `json:"asks"`
	Bids      []Order `json:"bids"`
	UpdatedAt Time    `json:"updated_at"`
	Sequence  string  `json:"sequence"`
}

OrderBook represents a response from /v3/order_book

type OrderPlacement

type OrderPlacement struct {
	Book Book `json:"book"`

	Side OrderSide `json:"side"`
	Type OrderType `json:"type"`

	Major Monetary `json:"major,omitempty"`
	Minor Monetary `json:"minor,omitempty"`
	Price Monetary `json:"price,omitempty"`
}

OrderPlacement represents an order that can be set by the user.

type OrderSide

type OrderSide uint8

OrderSide tells whether an order is a buy or a sell.

const (
	OrderSideNone OrderSide = iota

	OrderSideBuy
	OrderSideSell
)

List of order sides.

func (OrderSide) MarshalJSON

func (s OrderSide) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler

func (*OrderSide) Scan

func (s *OrderSide) Scan(value interface{}) error

func (*OrderSide) String

func (s *OrderSide) String() string

func (*OrderSide) UnmarshalJSON

func (s *OrderSide) UnmarshalJSON(in []byte) error

UnmarshalJSON implements json.Unmarshaler

func (OrderSide) Value

func (s OrderSide) Value() (driver.Value, error)

type OrderStatus

type OrderStatus uint8

OrderStatus represents the status of open orders.

const (
	OrderStatusNone OrderStatus = iota

	OrderStatusOpen
	OrderStatusQueued
	OrderStatusPartialFill
	OrderStatusCancelled
	OrderStatusCompleted
)

List of order statuses.

func (OrderStatus) MarshalJSON

func (s OrderStatus) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler

func (*OrderStatus) Scan

func (s *OrderStatus) Scan(value interface{}) error

func (*OrderStatus) String

func (s *OrderStatus) String() string

func (*OrderStatus) UnmarshalJSON

func (s *OrderStatus) UnmarshalJSON(in []byte) error

UnmarshalJSON implements json.Unmarshaler

func (OrderStatus) Value

func (s OrderStatus) Value() (driver.Value, error)

type OrderType

type OrderType uint8

OrderType tells whether the order is a market or limit order.

const (
	OrderTypeNone OrderType = iota

	OrderTypeMarket
	OrderTypeLimit
)

List of order types.

func (OrderType) MarshalJSON

func (o OrderType) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler

func (OrderType) String

func (o OrderType) String() string

func (*OrderType) UnmarshalJSON

func (o *OrderType) UnmarshalJSON(in []byte) error

UnmarshalJSON implements json.Unmarshaler

type TID

type TID uint64

TID respresents a transaction ID

func (*TID) Uint64

func (t *TID) Uint64() uint64

func (*TID) UnmarshalJSON

func (t *TID) UnmarshalJSON(in []byte) error

UnmarshalJSON implements json.Unmarshaler

type Ticker

type Ticker struct {
	// Order book symbol
	Book Book `json:"book"`

	// Last 24 hours volume
	Volume Monetary `json:"volume"`

	// Last 24 hours price high
	High Monetary `json:"high"`

	// Last traded price
	Last Monetary `json:"last"`

	// Last 24 hours price low
	Low Monetary `json:"low"`

	// Last 24 hours volume weighted average price
	Vwap Monetary `json:"vwap"`

	// Lowest sell order
	Ask Monetary `json:"ask"`

	// Highest buy order
	Bid Monetary `json:"bid"`

	// When this ticker was generated
	CreatedAt Time `json:"created_at"`
}

Ticker holds trading information from an specific book.

type Time

type Time time.Time

Time represents a ISO8601 encoded time value.

func (Time) String

func (t Time) String() string

String implements fmt.Stringer

func (*Time) Time

func (t *Time) Time() time.Time

func (*Time) UnmarshalJSON

func (t *Time) UnmarshalJSON(in []byte) error

UnmarshalJSON implements json.Unmarshal

type Trade

type Trade struct {
	Book      Book      `json:"book"`
	CreatedAt Time      `json:"created_at"`
	Amount    Monetary  `json:"amount"`
	MakerSide OrderSide `json:"maker_side"`
	Price     Monetary  `json:"price"`
	TID       TID       `json:"tid"`
}

Trade represents a recent trade from the specified book

type Transaction

type Transaction struct {
	EID            string    `json:"eid"`
	Operation      Operation `json:"operation"`
	CreatedAt      Time      `json:"created_at"`
	BalanceUpdates []struct {
		Currency Currency `json:"currency"`
		Amount   Monetary `json:"amount"`
	} `json:"balance_updates"`
	Details map[string]interface{} `json:"details"`
}

Transaction represents a transaction on the ledger.

type UserOrder

type UserOrder struct {
	Book Book `json:"book"`

	OriginalAmount Monetary `json:"original_amount"`
	UnfilledAmount Monetary `json:"unfilled_amount"`
	OriginalValue  Monetary `json:"original_value"`

	CreatedAt Time `json:"created_at"`
	UpdatedAt Time `json:"updated_at"`

	Price Monetary `json:"price"`
	OID   string   `json:"oid"`

	Side   OrderSide   `json:"side"`
	Status OrderStatus `json:"status"`
	Type   string      `json:"type"`
}

UserOrder represents an order from the current user.

type UserOrderTrade

type UserOrderTrade struct {
	Book         Book      `json:"book"`
	Major        Monetary  `json:"major"`
	CreatedAt    Time      `json:"created_at"`
	Minor        Monetary  `json:"minor"`
	FeesAmount   Monetary  `json:"fees_amount"`
	FeesCurrency Currency  `json:"currency"`
	Price        Monetary  `json:"price"`
	TID          TID       `json:"tid"`
	OID          string    `json:"oid"`
	Side         OrderSide `json:"side"`
}

UserOrderTrade represents a trade made by the user

type UserTrade

type UserTrade struct {
	Book         Book      `json:"book"`
	Major        Monetary  `json:"major"`
	CreatedAt    Time      `json:"created_at"`
	Minor        Monetary  `json:"minor"`
	FeesAmount   Monetary  `json:"fees_amount"`
	FeesCurrency Currency  `json:"fees_currency"`
	Price        Monetary  `json:"price"`
	TID          TID       `json:"tid"`
	OID          string    `json:"oid"`
	Side         OrderSide `json:"side"`
}

UserTrade represents a trade made by the user

type Websocket

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

A Websocket establishes a connection with Bitso's websocket service to send and receive messages over the ws protocol.

func NewWebsocket

func NewWebsocket() (*Websocket, error)

NewWebsocket creates a websocket handler and establishes a connection with Bitso's websocket servers.

func (*Websocket) Close

func (ws *Websocket) Close() error

Close closes the active connection with Bitso's websocket servers.

func (*Websocket) Receive

func (ws *Websocket) Receive() chan interface{}

Receive returns a channel where received messages are sent.

func (*Websocket) Subscribe

func (ws *Websocket) Subscribe(book *Book, channelName string) error

Subscribe subscribes to a messages channel.

type WebsocketDiffOrder

type WebsocketDiffOrder struct {
	Book    Book
	Payload []struct {
		Timestamp uint64   `json:"d"`
		Price     Monetary `json:"r"`
		Position  int      `json:"t"`
		Amount    Monetary `json:"a"`
		Value     Monetary `json:"v"`
		OrderID   string   `json:"o"`
	}
}

WebsocketDiffOrder represents a message from the "diff-orders" channel.

type WebsocketMessage

type WebsocketMessage struct {
	Action string `json:"action"`
	Book   *Book  `json:"book"`
	Type   string `json:"type"`
}

WebsocketMessage represents a message that can be sent to channel.

type WebsocketOrder

type WebsocketOrder struct {
	Book    Book
	Payload struct {
		Bids []struct {
			Price     float64 `json:"r"`
			Amount    float64 `json:"a"`
			Position  int     `json:"t"`
			Value     float64 `json:"v"`
			Timestamp uint64  `json:"d"`
		} `json:"bids"`
		Asks []struct {
			Price     float64 `json:"r"`
			Amount    float64 `json:"a"`
			Position  int     `json:"t"`
			Value     float64 `json:"v"`
			Timestamp uint64  `json:"d"`
		} `json:"asks"`
	} `json:"payload"`
}

WebsocketOrder represents a message from the "diff-orders" channel.

type WebsocketReply

type WebsocketReply struct {
	Action   string      `json:"action"`
	Response string      `json:"response"`
	Time     uint64      `json:"time"`
	Type     string      `json:"type"`
	Payload  interface{} `json:"payload,omitempty"`
}

WebsocketReply represents a generic reply from a channel.

type WebsocketTrade

type WebsocketTrade struct {
	Book    Book
	Payload []struct {
		TID          uint64   `json:"i"`
		Amount       Monetary `json:"a"`
		Price        Monetary `json:"r"`
		Value        Monetary `json:"v"`
		MakerOrderID string   `json:"mo"`
		TakerOrderID string   `json:"to"`
	}
}

WebsocketTrade represents a message from the "trades" channel.

type Withdrawal

type Withdrawal struct {
	WID       string                 `json:"wid"`
	Status    string                 `json:"status"`
	CreatedAt Time                   `json:"created_at"`
	Currency  Currency               `json:"currency"`
	Method    string                 `json:"method"`
	Amount    Monetary               `json:"amount"`
	Details   map[string]interface{} `json:"details"`
}

Funding represents the withdrawals of the user

type WithdrawalPlacement

type WithdrawalPlacement struct {
	Method      string   `json:"method"`
	Network     string   `json:"network"`
	Protocol    string   `json:"protocol"`
	Currency    Currency `json:"currency"`
	Amount      string   `json:"amount"`
	Beneficiary string   `json:"beneficiary"`
	Clabe       string   `json:"clabe"`
}

Jump to

Keyboard shortcuts

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