Skip to content

Commit

Permalink
Merge pull request #17 from aopoltorzhicky/time-float
Browse files Browse the repository at this point in the history
time.Time -> float64
  • Loading branch information
aopoltorzhicky authored Oct 13, 2019
2 parents 032709a + 6d0daa7 commit 820d385
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 40 deletions.
18 changes: 9 additions & 9 deletions websocket/factories.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ func (f *candlesFactory) Parse(data interface{}, pair string) (interface{}, erro
return CandleUpdate{Pair: pair}, fmt.Errorf("Can't parse data %#v", data)
}
return CandleUpdate{
Time: valToTime(body[0]),
EndTime: valToTime(body[1]),
Time: valToFloat64(body[0]),
EndTime: valToFloat64(body[1]),
Open: valToFloat64(body[2]),
High: valToFloat64(body[3]),
Low: valToFloat64(body[4]),
Expand Down Expand Up @@ -87,7 +87,7 @@ func (f *tradesFactory) Parse(data interface{}, pair string) (interface{}, error
trade := TradeUpdate{
Price: valToFloat64(entity[0]),
Volume: valToFloat64(entity[1]),
Time: valToTime(entity[2]),
Time: valToFloat64(entity[2]),
Side: parseSide(entity[3].(string)),
OrderType: parseOrderType(entity[4].(string)),
Misc: entity[5].(string),
Expand All @@ -112,7 +112,7 @@ func (f *spreadFactory) Parse(data interface{}, pair string) (interface{}, error
return SpreadUpdate{
Bid: valToFloat64(body[0]),
Ask: valToFloat64(body[1]),
Time: valToTime(body[2]),
Time: valToFloat64(body[2]),
BidVolume: valToFloat64(body[3]),
AskVolume: valToFloat64(body[4]),
Pair: pair,
Expand Down Expand Up @@ -142,7 +142,7 @@ func (f *bookFactory) Parse(data interface{}, pair string) (interface{}, error)
orderBookItem := OrderBookItem{
Price: valToFloat64(entity[0]),
Volume: valToFloat64(entity[1]),
Time: valToTime(entity[2]),
Time: valToFloat64(entity[2]),
}
orderBookItem.Republish = (len(entity) == 4 && entity[3] == "r")
items = append(items, orderBookItem)
Expand Down Expand Up @@ -194,7 +194,7 @@ func (f *ownTradesFactory) Parse(data interface{}, pair string) (interface{}, er
Pair: value["pair"].(string),
PosTxID: value["postxid"].(string),
Price: valToFloat64(value["price"]),
Time: valToTime(value["time"]),
Time: valToFloat64(value["time"]),
Type: value["type"].(string),
Vol: valToFloat64(value["vol"]),
}
Expand Down Expand Up @@ -230,9 +230,9 @@ func (f *openOrdersFactory) Parse(data interface{}, pair string) (interface{}, e
LimitPrice: valToFloat64(value["limitprice"]),
Misc: value["misc"].(string),
Oflags: value["oflags"].(string),
OpenTime: valToTime(value["opentm"]),
StartTime: valToTime(value["starttm"]),
ExpireTime: valToTime(value["expiretm"]),
OpenTime: valToFloat64(value["opentm"]),
StartTime: valToFloat64(value["starttm"]),
ExpireTime: valToFloat64(value["expiretm"]),
Price: valToFloat64(value["price"]),
Refid: value["refid"].(string),
Status: value["status"].(string),
Expand Down
22 changes: 11 additions & 11 deletions websocket/factories_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ func Test_candlesFactory_Parse(t *testing.T) {
},
},
want: CandleUpdate{
Time: t1.UTC(),
EndTime: t2.UTC(),
Time: float64(t1.Unix()),
EndTime: float64(t2.Unix()),
Open: 3586.7,
High: 3586.7,
Low: 3586.6,
Expand Down Expand Up @@ -248,7 +248,7 @@ func Test_tradesFactory_Parse(t *testing.T) {
want: []TradeUpdate{
TradeUpdate{
Pair: BTCCAD,
Time: t1.UTC(),
Time: float64(t1.Unix()),
Price: 5541.2,
Volume: 0.15850568,
Side: Sell,
Expand All @@ -257,7 +257,7 @@ func Test_tradesFactory_Parse(t *testing.T) {
},
TradeUpdate{
Pair: BTCCAD,
Time: t2.UTC(),
Time: float64(t2.Unix()),
Price: 6060.,
Volume: 0.02455000,
Side: Buy,
Expand Down Expand Up @@ -326,7 +326,7 @@ func Test_spreadFactory_Parse(t *testing.T) {
Pair: BTCCAD,
Bid: 5698.4,
Ask: 5700,
Time: t1.UTC(),
Time: float64(t1.Unix()),
BidVolume: 1.01234567,
AskVolume: 0.98765432,
},
Expand Down Expand Up @@ -418,27 +418,27 @@ func Test_bookFactory_Parse(t *testing.T) {
OrderBookItem{
Price: 5541.3,
Volume: 2.50700000,
Time: t1.UTC(),
Time: float64(t1.Unix()),
Republish: false,
},
OrderBookItem{
Price: 5541.8,
Volume: 0.33000000,
Time: t2.UTC(),
Time: float64(t2.Unix()),
Republish: false,
},
},
Bids: []OrderBookItem{
OrderBookItem{
Price: 5541.2,
Volume: 1.52900000,
Time: t1.UTC(),
Time: float64(t1.Unix()),
Republish: false,
},
OrderBookItem{
Price: 5539.9,
Volume: 0.30000000,
Time: t2.UTC(),
Time: float64(t2.Unix()),
Republish: false,
},
},
Expand Down Expand Up @@ -475,15 +475,15 @@ func Test_bookFactory_Parse(t *testing.T) {
OrderBookItem{
Price: 5541.3,
Volume: 2.50700000,
Time: t1.UTC(),
Time: float64(t1.Unix()),
Republish: true,
},
},
Bids: []OrderBookItem{
OrderBookItem{
Price: 5541.2,
Volume: 1.52900000,
Time: t1.UTC(),
Time: float64(t1.Unix()),
Republish: false,
},
},
Expand Down
39 changes: 19 additions & 20 deletions websocket/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"fmt"
"math/big"
"time"
)

// EventType - data structure for parsing events
Expand Down Expand Up @@ -132,8 +131,8 @@ type Values struct {

// CandleUpdate - data structure for candles update
type CandleUpdate struct {
Time time.Time
EndTime time.Time
Time float64
EndTime float64
Open float64
High float64
Low float64
Expand All @@ -148,7 +147,7 @@ type CandleUpdate struct {
type TradeUpdate struct {
Price float64
Volume float64
Time time.Time
Time float64
Side string
OrderType string
Misc string
Expand All @@ -161,15 +160,15 @@ type SpreadUpdate struct {
Bid float64
AskVolume float64
BidVolume float64
Time time.Time
Time float64
Pair string
}

// OrderBookItem - data structure for order book item
type OrderBookItem struct {
Price float64
Volume float64
Time time.Time
Time float64
Republish bool
}

Expand All @@ -195,17 +194,17 @@ type AuthSubscriptionRequest struct {

// OwnTrade - Own trades.
type OwnTrade struct {
Cost float64 `json:"cost,string"`
Fee float64 `json:"fee,string"`
Margin float64 `json:"margin,string"`
OrderID string `json:"ordertxid"`
OrderType string `json:"ordertype"`
Pair string `json:"pair"`
PosTxID string `json:"postxid"`
Price float64 `json:"price,string"`
Time time.Time `json:"time"`
Type string `json:"type"`
Vol float64 `json:"vol,string"`
Cost float64 `json:"cost,string"`
Fee float64 `json:"fee,string"`
Margin float64 `json:"margin,string"`
OrderID string `json:"ordertxid"`
OrderType string `json:"ordertype"`
Pair string `json:"pair"`
PosTxID string `json:"postxid"`
Price float64 `json:"price,string"`
Time float64 `json:"time"`
Type string `json:"type"`
Vol float64 `json:"vol,string"`
}

// OpenOrderDescr -
Expand All @@ -228,9 +227,9 @@ type OpenOrder struct {
LimitPrice float64 `json:"limitprice,string"`
Misc string `json:"misc"`
Oflags string `json:"oflags"`
OpenTime time.Time `json:"opentm"`
StartTime time.Time `json:"starttm"`
ExpireTime time.Time `json:"expiretm"`
OpenTime float64 `json:"opentm"`
StartTime float64 `json:"starttm"`
ExpireTime float64 `json:"expiretm"`
Price float64 `json:"price,string"`
Refid string `json:"refid"`
Status string `json:"status"`
Expand Down

0 comments on commit 820d385

Please sign in to comment.