moonmath/bitcoinity/model.go

102 lines
1.9 KiB
Go

package bitcoinity
import (
"encoding/json"
"fmt"
)
var EmptyPayload json.RawMessage = []byte("{}")
type MessageId string
type Topic string
const TopicAll Topic = "all"
func MarketTopic(e Exchange, c Currency) Topic {
topic := fmt.Sprintf("webs:markets_%s_%s", e, c)
return Topic(topic)
}
type Event string
const (
EventPhxJoin Event = "phx_join"
EventPhxReply Event = "phx_reply"
EventNewMsg Event = "new_msg"
)
type GetTickerRequest struct {
Currency Currency
Exchange Exchange
Span Span
}
type GetTickerResponse struct {
TickerLife int `json:"ticker_life"`
VolumeResolution int `json:"volume_resolution"`
PriceChange string `json:"price_change"`
PriceHigh string `json:"price_high"`
PriceLow string `json:"price_low"`
Buys []Trade `json:"buys"`
Sells []Trade `json:"sells"`
Lasts []Trade `json:"lasts"`
Volume []Volume `json:"volume"`
}
type Currency string
const (
USD Currency = "USD"
EUR Currency = "EUR"
GBP Currency = "GBP"
AUD Currency = "AUD"
JPY Currency = "JPY"
CAD Currency = "CAD"
)
type Exchange string
const (
Coinbase Exchange = "coinbase"
Bitfinex Exchange = "bitfinex"
Bitstamp Exchange = "bitstamp"
Kraken Exchange = "kraken"
Gemini Exchange = "gemini"
)
type Span string
const (
Span10Minutes Span = "10m"
Span1Hour Span = "1h"
Span12Hours Span = "12h"
Span24Hours Span = "24h"
Span3Days Span = "3d"
Span7Days Span = "7d"
Span30Days Span = "30d"
Span6Months Span = "6m"
Span2Years Span = "2y"
SpanAll Span = "all"
)
type Trade struct {
Timestamp int64
Price float64
}
func (t *Trade) UnmarshalJSON(b []byte) error {
a := []interface{}{&t.Timestamp, &t.Price}
return json.Unmarshal(b, &a)
}
type Volume struct {
Timestamp int64
Size float64
}
func (v *Volume) UnmarshalJSON(b []byte) error {
a := []interface{}{&v.Timestamp, &v.Size}
return json.Unmarshal(b, &a)
}