-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
41 lines (38 loc) · 994 Bytes
/
main.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
package main
import (
"log"
"github.com/rcolombo/tickertock/types"
)
func main() {
h, err := New(*apiKey, *apiSecret)
if err != nil {
log.Fatal("Error creating Huobi client: ", err)
}
bookOrderCh, _ := h.SubscribeForPair(cp)
book := types.NewBook(10)
for o := range bookOrderCh {
newHigh, newLow := book.ProcessBookOrder(*o)
if isBuy && newLow {
la := book.GetLowAsk()
if la.Price.LessThanOrEqual(stopPriceDec) {
newOrder, err := h.PlaceLimitOrder(h.Symbolize(cp), isBuy, amountDec, limitPriceDec)
if err != nil {
log.Fatal("Error placing order: ", err)
}
log.Println("Order Placed: %+v", newOrder)
return
}
}
if !isBuy && newHigh {
hb := book.GetHighBid()
if hb.Price.LessThanOrEqual(stopPriceDec) {
newOrder, err := h.PlaceLimitOrder(h.Symbolize(cp), isBuy, amountDec, limitPriceDec)
if err != nil {
log.Fatal("Error placing order: ", err)
}
log.Println("Order Placed: %+v", newOrder)
return
}
}
}
}