coincross

package module
v0.0.0-...-706aa27 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2014 License: MIT Imports: 8 Imported by: 0

README

Coincross

Build Status

Coincross is a collection of APIs for trading on various cryptocurrency exchanges, with a unified interface.

Supported Exchanges:

Coincross was once called "gocoins", but renamed to "coincross" to prevent name collisions.

Disclaimer

Use this code at your own risk. The contributors of this project is not responsible for your profit or loss.

License

This project is licensed under MIT License.

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

View Source
const (
	BTC Symbol = "BTC"
	LTC        = "LTC"
	CNY        = "CNY"
	USD        = "USD"
)

Some predefined Symbols. You are not limited to use these.

Variables

View Source
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.

View Source
var (
	ErrInvalidCredential      = NewTradeError("Invalid Credential")
	ErrInsufficientPermission = NewTradeError("Insufficient Permissions")
	ErrInsufficientBalance    = NewTradeError("Insufficient Balance")
)

Functions

func List

func List() []string

List returns all registered client types.

func Register

func Register(name string, newfunc newClientFunc)

Register a new client to the default registry.

func TimeoutTransport

func TimeoutTransport(connectTimeout time.Duration, totalTimeout time.Duration) *http.Transport

TimeoutTransport returns a http transport with given connect and total timeout.

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.

func New

func New(name string, apikey, secret string, transport *http.Transport) Client

New creates a client instance with given parameters.

type Order

type Order struct {
	Id             int64
	Timestamp      int64
	Type           TradeType
	Price          float64
	Remain, Amount float64
	Pair           Pair
}

An active order.

func (Order) String

func (o Order) String() string

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

func (p Pair) LowerString() string

LowerString returns "btc_usd" for {USD, BTC}.

func (*Pair) MarshalJSON

func (p *Pair) MarshalJSON() ([]byte, error)

MarshalJSON to "btc_usd" from {USD, BTC}.

func (*Pair) Set

func (p *Pair) Set(s string) error

Set sets the pair to {USD, BTC} from "BTC/USD".

func (Pair) String

func (p Pair) String() string

String returns "BTC/USD" for {USD, BTC}.

func (*Pair) UnmarshalJSON

func (p *Pair) UnmarshalJSON(b []byte) (err error)

UnmarshalJSON from "btc_usd" to {USD, BTC}.

type Streamer

type Streamer struct {
	C       <-chan Trade
	Closing chan<- bool
}

func Tail

func Tail(c Client, pair Pair, since int64, interval time.Duration) *Streamer

Tail follows Client.History.

type Symbol

type Symbol string

Symbol represents a currency, such as USD, CNY, BTC etc.

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.

func (Trade) String

func (t Trade) String() string

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 (t *TradeType) MarshalJSON() ([]byte, error)

func (*TradeType) Set

func (t *TradeType) Set(s string) error

func (TradeType) String

func (t TradeType) String() string

func (*TradeType) UnmarshalJSON

func (t *TradeType) UnmarshalJSON(b []byte) (err error)

type Transaction

type Transaction struct {
	Id          int64
	Timestamp   int64
	Amounts     map[Symbol]float64
	Descritpion string
}

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.

Jump to

Keyboard shortcuts

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