Documentation ¶
Overview ¶
Package mtgox implements a complete MtGox streaming API client.
Overview ¶
The Client type represents a connection to the Mt.Gox streaming API using WebSockets (Powered by the modern Gorilla WebSocket package). After creating a Client instance, you should call client.Start to begin handling received messages.
client, err := mtgox.New( "KEY", "SECRET", "Currencies"...) if err != nil { // Handle connection error } // Start message receive routine client.Start()
From here all messages will be sent to their respective channels.
Index ¶
- Constants
- type Client
- func (g *Client) CancelOrder(o Order) (string, error)
- func (g *Client) Close()
- func (g *Client) Conn() *websocket.Conn
- func (g *Client) GetHistory(walletID string) []Order
- func (g *Client) PlaceOrder(o Order) (string, error)
- func (g *Client) QueryOrder(orderID string) (Order, error)
- func (g *Client) QuoteOrder(o Order) (string, error)
- func (g *Client) RequestInfo() *Info
- func (g *Client) RequestOrderLag() (time.Duration, error)
- func (g *Client) RequestOrders() (<-chan []Order, error)
- func (c *Client) SetErrorHandler(handlerFunc ErrorHandlerFunc)
- func (g *Client) Start()
- type Config
- type CurrencyValue
- type Depth
- type DepthPayload
- type EpochTime
- type ErrorHandlerFunc
- type Info
- type Order
- type Rate
- type ResultHeader
- type ResultPayload
- type SimpleTime
- type StreamHeader
- type Ticker
- type TickerPayload
- type Trade
- type TradePayload
- type Value
- type Wallet
Constants ¶
const (
// BitcoinDivision represents the current integer division of 1 bitcoin.
BitcoinDivision = 1e8
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct { Ticker chan *TickerPayload Info chan *Info Depth chan *DepthPayload Trades chan *TradePayload Orders chan []Order // contains filtered or unexported fields }
Client represents the public type for interacing with the MtGox streaming API.
func NewWithConnection ¶
NewWithConnection constructs a new client using an existing connection, useful for testing
func (*Client) CancelOrder ¶
CancelOrder will cancel the given order if already added to the market
func (*Client) Close ¶
func (g *Client) Close()
Close disconnects the client from the streaming API.
func (*Client) Conn ¶
Conn returns the raw websocket connection to Mt.Gox (This may be removed in the future)
func (*Client) GetHistory ¶
GetHistory returns the histroy for the given wallet ID
func (*Client) PlaceOrder ¶
PlaceOrder adds the given Order to the market, returning the new ID
func (*Client) QueryOrder ¶
QueryOrder returns updated information for the given order
func (*Client) QuoteOrder ¶
QuoteOrder retrieves a quote for the given Order
func (*Client) RequestInfo ¶
RequestInfo dispatches a request for `private/info`, returning an info payload or timing out after 10 seconds.
func (*Client) RequestOrderLag ¶
RequestOrderLag returns the lag time for executing orders This method will block for up to 5 seconds before timing out
func (*Client) RequestOrders ¶
RequestOrders fetches the open orders for your account
func (*Client) SetErrorHandler ¶
func (c *Client) SetErrorHandler(handlerFunc ErrorHandlerFunc)
type CurrencyValue ¶
func (*CurrencyValue) AsFloat ¶
func (c *CurrencyValue) AsFloat() float64
func (*CurrencyValue) UnmarshalJSON ¶
func (tv *CurrencyValue) UnmarshalJSON(data []byte) error
type Depth ¶
type Depth struct { // Ask or Bid - Corresponds to the Order type OrderType string // The price at which volume change happened Price int64 // The volume change Volume int64 // BTC Instrument string // The currency affected Currency string // Total volume at this price, after applying the depth update, can be used as a starting point before applying subsequent updates. TotalVolume int64 // When the change happened Timestamp time.Time }
Depth represents market order depth
func (*Depth) UnmarshalJSON ¶
UnmarshalJSON handles unmarshalling custom payload from Mt.Gox
type DepthPayload ¶
type DepthPayload struct { StreamHeader Depth Depth `json:"depth"` }
DepthPayload represents a payload structure for market depth
type EpochTime ¶
func (*EpochTime) UnmarshalJSON ¶
type ErrorHandlerFunc ¶
type ErrorHandlerFunc func(error)
ErrorHandlerFunc is a function type to use as an error callback.
type Order ¶
type Order struct { // OrderID is the unique order identifier OrderID string `json:"oid,string"` // Currency represents the external fiat currency Currency string `json:"currency,string"` // Instrument is the object being traded Instrument string `json:"item,string"` // OrderType in the market, one of `bid` or `ask` OrderType string `json:"type,string"` // Amount is the requested trade amount in BTC Amount float64 `json:"amount"` // EffectiveAmount is the actual amount traded in BTC EffectiveAmount float64 `json:"effective_amount"` // InvalidAmount is the amount which could not traded in BTC InvalidAmount float64 `json:"invalid_amount"` // Price is the amount paid in fiat currency Price float64 `json:"price"` // Status is the current status of the order Status string `json:"status,string"` // Timestamp of the order taking place Timestamp time.Time `json:"date,string"` // Priority is a unique microsecond timestamp of the order // (Not sure what the actual use of this is) Priority uint64 `json:"priority,string"` }
Order represents a market order from your account.
func (*Order) UnmarshalJSON ¶
UnmarshalJSON is a custom unmarshaller for Mt.Gox order payloads
type ResultHeader ¶
ResultHeader defines a simple header structure for partially unmarshalling replies from Mt.Gox to determine their type
type ResultPayload ¶
type ResultPayload struct { ResultHeader Result json.RawMessage `json:"result"` }
ResultPayload defines a structure for unmarshalling complete replies with unknown response data formats to be parsed later
type SimpleTime ¶
func (*SimpleTime) UnmarshalJSON ¶
func (t *SimpleTime) UnmarshalJSON(b []byte) error
type StreamHeader ¶
type StreamHeader struct { Channel string `json:"channel"` ChannelName string `json:"channel_name"` Op string `json:"op"` Origin string `json:"origin"` Private string `json:"private"` }
StreamHeader represents the header of a payload message from MtGox before being parsed.
type Ticker ¶
type Ticker struct { High CurrencyValue `json:"high"` Low CurrencyValue `json:"low"` Average CurrencyValue `json:"avg"` Vwap CurrencyValue `json:"vwap"` Volume CurrencyValue `json:"vol"` LastLocal CurrencyValue `json:"last_local"` LastOrigin CurrencyValue `json:"last_orig"` LastAll CurrencyValue `json:"last_all"` Last CurrencyValue `json:"last"` Buy CurrencyValue `json:"buy"` Sell CurrencyValue `json:"sell"` Instrument string `json:"item"` Timestamp EpochTime `json:"now,string"` }
type TickerPayload ¶
type TickerPayload struct { StreamHeader Ticker Ticker `json:"ticker"` }
type Trade ¶
type Trade struct { Type string Tid string Amount float64 Price float64 Instrument string Currency string TradeType string Primary string Properties string Timestamp time.Time }
func (*Trade) UnmarshalJSON ¶
type TradePayload ¶
type TradePayload struct { StreamHeader Trade Trade `json:"trade"` }