Documentation ¶
Overview ¶
Coincross is a collection of cryptocurrency trading APIs.
This is the base package that defines the unified interface, as well as some common data structures. API implementations should live in their own package.
However, as the APIs vary a lot from exchange to exchange, it is difficult to include all the functionalities of the APIs. This package should aim to provide the minimalist interface for common exchanges, while fixing some broken APIs in the hidden layer. For example, some API does not return the order id when you place an order (i.e. BTCChina), implementations should fix this. Well, to their best.
As more and more exchanges are being supported, this interface may subject to changes.
Index ¶
- Constants
- Variables
- func List() []string
- func Register(name string, newfunc newClientFunc)
- func TimeoutTransport(connectTimeout time.Duration, totalTimeout time.Duration) *http.Transport
- type Client
- type Order
- type Orderbook
- type Pair
- type Streamer
- type Symbol
- type Ticker
- type Trade
- type TradeError
- type TradeType
- type Transaction
Constants ¶
const ( BTC Symbol = "BTC" LTC = "LTC" CNY = "CNY" USD = "USD" )
Some predefined Symbols. You are not limited to use these.
Variables ¶
var ( ALL = Pair{"", ""} BTC_CNY = Pair{CNY, BTC} BTC_USD = Pair{USD, BTC} LTC_CNY = Pair{CNY, LTC} LTC_USD = Pair{USD, LTC} LTC_BTC = Pair{BTC, LTC} )
Some predefined pairs.
var ( ErrInvalidCredential = NewTradeError("Invalid Credential") ErrInsufficientPermission = NewTradeError("Insufficient Permissions") ErrInsufficientBalance = NewTradeError("Insufficient Balance") )
Functions ¶
Types ¶
type Client ¶
type Client interface { // Should return the balance of current account. Balance() (map[Symbol]float64, error) // Use with caution: this method is for real trading. Trade(tradeType TradeType, pair Pair, price, amount float64) (int64, error) // Cancel an active order. Cancel(orderId int64) (bool, error) // Returns active orders. Orders() ([]Order, error) // Returns the transaction history of current account. Transactions(limit int) ([]Transaction, error) // Returns the orderbook (or market depth) of the given pair. // Usually this is a public API. Orderbook(pair Pair, limit int) (*Orderbook, error) // Returns the trade history of the given pair, as well as a cursor for next since. // Usually this is a public API. History(pair Pair, since int64) ([]Trade, int64, error) // Returns the ticker of the given pair. // Usually this is a public API. Ticker(pair Pair) (*Ticker, error) // History streaming. Stream(pair Pair, since int64) *Streamer }
This is the interface that every API implementation should use.
type Order ¶
type Order struct { Id int64 Timestamp int64 Type TradeType Price float64 Remain, Amount float64 Pair Pair }
An active order.
type Orderbook ¶
type Orderbook struct {
Asks, Bids []struct {
Price, Amount float64
}
}
Well, the order book, or the market depth.
type Pair ¶
type Pair struct {
Base, Target Symbol
}
Pair is for a trading pair, such as {USD, BTC}
func (Pair) LowerString ¶
LowerString returns "btc_usd" for {USD, BTC}.
func (*Pair) MarshalJSON ¶
MarshalJSON to "btc_usd" from {USD, BTC}.
func (*Pair) UnmarshalJSON ¶
UnmarshalJSON from "btc_usd" to {USD, BTC}.
type Ticker ¶
type Ticker struct {
Buy, Sell, High, Low, Last, Volume float64
}
Ticker represents for the result of Ticker APIs.
type Trade ¶
type Trade struct { Id int64 Timestamp int64 Type TradeType Price float64 Amount float64 Pair Pair }
A historical trade instance. As you can see Trade is a special case of Transaction. It's just special enough to make it a unique type.
type TradeError ¶
type TradeError error
func NewTradeError ¶
func NewTradeError(text string) TradeError
type TradeType ¶
type TradeType int
TradeType is the direction of a trade.
const ( Sell TradeType Buy )
func (*TradeType) MarshalJSON ¶
func (*TradeType) UnmarshalJSON ¶
type Transaction ¶
A transaction is an operation to your account's balance. All the historical transactions should add up to your current balance.
func (Transaction) String ¶
func (t Transaction) String() string
Directories ¶
Path | Synopsis |
---|---|
This is a meta package to include all supported exchanges.
|
This is a meta package to include all supported exchanges. |
Client implementation for BTCChina.
|
Client implementation for BTCChina. |
Client implementation for BTC-E.
|
Client implementation for BTC-E. |
A simple tool for trading on CLI.
|
A simple tool for trading on CLI. |