Skip to content

Commit 8361c99

Browse files
author
robaho
committed
fix issue #4 - fix client for api changes
1 parent 9f7e609 commit 8361c99

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

cmd/client/main.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package main
33
import (
44
"flag"
55
"fmt"
6-
"github.com/shopspring/decimal"
6+
"github.com/robaho/fixed"
77
"log"
88
"strings"
99
"sync"
@@ -29,11 +29,11 @@ func (MyCallback) OnBook(book *Book) {
2929

3030
bidPrice, bidQty, askPrice, askQty := "", "", "", ""
3131
if book.HasBids() {
32-
bidPrice = book.Bids[0].Price.StringFixed(2)
32+
bidPrice = book.Bids[0].Price.StringN(2)
3333
bidQty = book.Bids[0].Quantity.String()
3434
}
3535
if book.HasAsks() {
36-
askPrice = book.Asks[0].Price.StringFixed(2)
36+
askPrice = book.Asks[0].Price.StringN(2)
3737
askQty = book.Asks[0].Quantity.String()
3838
}
3939

@@ -45,11 +45,11 @@ func (MyCallback) OnBook(book *Book) {
4545
v.Clear()
4646
v.FgColor = gocui.ColorRed
4747
for i := len(book.Asks) - 1; i >= 0; i-- {
48-
fmt.Fprintf(v, "%5s @ %10s\n", book.Asks[i].Quantity.String(), book.Asks[i].Price.StringFixed(2))
48+
fmt.Fprintf(v, "%5s @ %10s\n", book.Asks[i].Quantity.String(), book.Asks[i].Price.StringN(2))
4949
}
5050
v.FgColor = gocui.ColorGreen
5151
for i := 0; i < len(book.Bids); i++ {
52-
fmt.Fprintf(v, "%5s @ %10s\n", book.Bids[i].Quantity.String(), book.Bids[i].Price.StringFixed(2))
52+
fmt.Fprintf(v, "%5s @ %10s\n", book.Bids[i].Quantity.String(), book.Bids[i].Price.StringN(2))
5353
}
5454
v.FgColor = gocui.ColorDefault
5555
return nil
@@ -116,10 +116,10 @@ func (MyCallback) OnOrderStatus(order *Order) {
116116
v.FgColor = color
117117

118118
qty := order.Remaining.String()
119-
if !order.Remaining.Equals(order.Quantity) {
119+
if !order.Remaining.Equal(order.Quantity) {
120120
qty = qty + " (" + order.Quantity.String() + ")"
121121
}
122-
fmt.Fprintf(v, "%5d %10s %5s %10s @ %10s\n", order.Id, order.Instrument.Symbol(), order.Side, qty, order.Price.StringFixed(2))
122+
fmt.Fprintf(v, "%5d %10s %5s %10s @ %10s\n", order.Id, order.Instrument.Symbol(), order.Side, qty, order.Price.StringN(2))
123123
v.FgColor = gocui.ColorDefault
124124
}
125125
return err
@@ -139,14 +139,14 @@ func (MyCallback) OnFill(fill *Fill) {
139139
}
140140
}
141141

142-
var lastPrice = map[Instrument]decimal.Decimal{}
142+
var lastPrice = map[Instrument]fixed.Fixed{}
143143

144144
func (MyCallback) OnTrade(trade *Trade) {
145145
color := gocui.ColorWhite
146146

147147
lp, ok := lastPrice[trade.Instrument]
148148
if ok {
149-
if trade.Price.Equals(lp) {
149+
if trade.Price.Equal(lp) {
150150
color = gocui.ColorWhite
151151
} else if trade.Price.GreaterThan(lp) {
152152
color = gocui.ColorGreen
@@ -156,7 +156,7 @@ func (MyCallback) OnTrade(trade *Trade) {
156156
}
157157
lastPrice[trade.Instrument] = trade.Price
158158

159-
vlogcf("markets", color, "trade on %s, %s @ %s\n", trade.Instrument.Symbol(), trade.Quantity.String(), trade.Price.StringFixed(2))
159+
vlogcf("markets", color, "trade on %s, %s @ %s\n", trade.Instrument.Symbol(), trade.Quantity.String(), trade.Price.StringN(2))
160160
}
161161

162162
type viewLogger struct{}

0 commit comments

Comments
 (0)