diff --git a/pkg/types/color.go b/pkg/types/color.go index fa714b5cc..ac8324aa2 100644 --- a/pkg/types/color.go +++ b/pkg/types/color.go @@ -1,4 +1,5 @@ package types -const Green = "#228B22" -const Red = "#800000" +const GreenColor = "#228B22" +const RedColor = "#800000" +const GrayColor = "#f0f0f0" diff --git a/pkg/types/kline.go b/pkg/types/kline.go index b45bb67d0..15e13c827 100644 --- a/pkg/types/kline.go +++ b/pkg/types/kline.go @@ -177,11 +177,11 @@ func (k KLine) String() string { func (k KLine) Color() string { if k.Direction() > 0 { - return Green + return GreenColor } else if k.Direction() < 0 { - return Red + return RedColor } - return "#f0f0f0" + return GrayColor } func (k KLine) SlackAttachment() slack.Attachment { diff --git a/pkg/rbtbook/tree.go b/pkg/types/rbtree.go similarity index 90% rename from pkg/rbtbook/tree.go rename to pkg/types/rbtree.go index a97bbcc2c..6aea02f97 100644 --- a/pkg/rbtbook/tree.go +++ b/pkg/types/rbtree.go @@ -1,27 +1,27 @@ -package rbtbook +package types import ( "github.com/c9s/bbgo/pkg/fixedpoint" ) -type Tree struct { +type RBTree struct { Root, Neel *Node } -func NewTree() *Tree { +func NewRBTree() *RBTree { var neel = &Node{ Color: Black, } var root = neel root.Parent = neel - return &Tree{ + return &RBTree{ Root: root, Neel: neel, } } -func (tree *Tree) Delete(key fixedpoint.Value) bool { +func (tree *RBTree) Delete(key fixedpoint.Value) bool { var del = tree.Search(key) if del == nil { return false @@ -64,7 +64,7 @@ func (tree *Tree) Delete(key fixedpoint.Value) bool { return true } -func (tree *Tree) DeleteFixup(current *Node) { +func (tree *RBTree) DeleteFixup(current *Node) { for current != tree.Root && current.Color == Black { if current == current.Parent.Left { sibling := current.Parent.Right @@ -128,7 +128,7 @@ func (tree *Tree) DeleteFixup(current *Node) { current.Color = Black } -func (tree *Tree) Insert(key, val fixedpoint.Value) { +func (tree *RBTree) Insert(key, val fixedpoint.Value) { var y = tree.Neel var x = tree.Root var node = &Node{ @@ -164,7 +164,7 @@ func (tree *Tree) Insert(key, val fixedpoint.Value) { tree.InsertFixup(node) } -func (tree *Tree) Search(key fixedpoint.Value) *Node { +func (tree *RBTree) Search(key fixedpoint.Value) *Node { var current = tree.Root for current != nil && key != current.Key { if key < current.Key { @@ -176,7 +176,7 @@ func (tree *Tree) Search(key fixedpoint.Value) *Node { return current } -func (tree *Tree) InsertFixup(current *Node) { +func (tree *RBTree) InsertFixup(current *Node) { // A red node can't have a red parent, we need to fix it up for current.Parent.Color == Red { grandParent := current.Parent.Parent @@ -227,7 +227,7 @@ func (tree *Tree) InsertFixup(current *Node) { // 1. move y's left child to the x's right child // 2. change y's parent to x's parent // 3. change x's parent to y -func (tree *Tree) RotateLeft(x *Node) { +func (tree *RBTree) RotateLeft(x *Node) { var y = x.Right x.Right = y.Left @@ -249,7 +249,7 @@ func (tree *Tree) RotateLeft(x *Node) { x.Parent = y } -func (tree *Tree) RotateRight(y *Node) { +func (tree *RBTree) RotateRight(y *Node) { x := y.Left y.Left = x.Right @@ -271,7 +271,7 @@ func (tree *Tree) RotateRight(y *Node) { y.Parent = x } -func (tree *Tree) LeftMost(current *Node) *Node { +func (tree *RBTree) LeftMost(current *Node) *Node { for current.Left != nil { current = current.Left } @@ -279,7 +279,7 @@ func (tree *Tree) LeftMost(current *Node) *Node { return current } -func (tree *Tree) Successor(current *Node) *Node { +func (tree *RBTree) Successor(current *Node) *Node { if current.Right != nil { return tree.LeftMost(current.Right) } diff --git a/pkg/rbtbook/node.go b/pkg/types/rbtree_node.go similarity index 95% rename from pkg/rbtbook/node.go rename to pkg/types/rbtree_node.go index 287d06c80..3a3b28930 100644 --- a/pkg/rbtbook/node.go +++ b/pkg/types/rbtree_node.go @@ -1,4 +1,4 @@ -package rbtbook +package types import "github.com/c9s/bbgo/pkg/fixedpoint" diff --git a/pkg/rbtbook/tree_test.go b/pkg/types/rbtree_test.go similarity index 96% rename from pkg/rbtbook/tree_test.go rename to pkg/types/rbtree_test.go index 41044ef32..7684c7fb2 100644 --- a/pkg/rbtbook/tree_test.go +++ b/pkg/types/rbtree_test.go @@ -1,4 +1,4 @@ -package rbtbook +package types import ( "testing" @@ -8,7 +8,7 @@ import ( ) func TestTree(t *testing.T) { - tree := NewTree() + tree := NewRBTree() tree.Insert(fixedpoint.NewFromFloat(3000.0), fixedpoint.NewFromFloat(10.0)) assert.NotNil(t, tree.Root) diff --git a/pkg/types/side.go b/pkg/types/side.go index 492ebbdda..46c916aed 100644 --- a/pkg/types/side.go +++ b/pkg/types/side.go @@ -74,14 +74,14 @@ func (side SideType) String() string { func (side SideType) Color() string { if side == SideTypeBuy { - return Green + return GreenColor } if side == SideTypeSell { - return Red + return RedColor } - return "#f0f0f0" + return GrayColor } func SideToColorName(side SideType) string {