-
Notifications
You must be signed in to change notification settings - Fork 0
/
tick.go
47 lines (43 loc) · 984 Bytes
/
tick.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package exch
import (
"bytes"
"encoding/gob"
"time"
)
// Tick 记录了单笔的交易记录
// 各个具体交易所的交易记录
// 要么直接使用 Tick,
// 要么提供转换到 Tick 函数,
type Tick struct {
// Exchange Name
// Symbol string // like "BTCUSDT"
// Asset string // like "BTC"
ID int64
Date time.Time
Price float64
Volume float64
// Type string
}
// NewTick returns a new tick
func NewTick(id int64, date time.Time, price, volume float64) Tick {
return Tick{
ID: id,
Date: date,
Price: price,
Volume: volume,
}
}
// DecTickFunc 返回的函数会把序列化成 []byte 的 Balances 值转换回来
func DecTickFunc() func(bs []byte) Tick {
var bb bytes.Buffer
dec := gob.NewDecoder(&bb)
return func(bs []byte) Tick {
bb.Reset()
bb.Write(bs)
var tick Tick
// dec.Decode 只有在输入不是指针时候,才会报错
// 显然 &balances 肯定是一个指针
dec.Decode(&tick)
return tick
}
}