forked from rodrigo-brito/ninjabot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
order.go
60 lines (50 loc) · 2.06 KB
/
order.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
48
49
50
51
52
53
54
55
56
57
58
59
60
package model
import (
"fmt"
"time"
)
type SideType string
type OrderType string
type OrderStatusType string
var (
SideTypeBuy SideType = "BUY"
SideTypeSell SideType = "SELL"
OrderTypeLimit OrderType = "LIMIT"
OrderTypeMarket OrderType = "MARKET"
OrderTypeLimitMaker OrderType = "LIMIT_MAKER"
OrderTypeStopLoss OrderType = "STOP_LOSS"
OrderTypeStopLossLimit OrderType = "STOP_LOSS_LIMIT"
OrderTypeTakeProfit OrderType = "TAKE_PROFIT"
OrderTypeTakeProfitLimit OrderType = "TAKE_PROFIT_LIMIT"
OrderStatusTypeNew OrderStatusType = "NEW"
OrderStatusTypePartiallyFilled OrderStatusType = "PARTIALLY_FILLED"
OrderStatusTypeFilled OrderStatusType = "FILLED"
OrderStatusTypeCanceled OrderStatusType = "CANCELED"
OrderStatusTypePendingCancel OrderStatusType = "PENDING_CANCEL"
OrderStatusTypeRejected OrderStatusType = "REJECTED"
OrderStatusTypeExpired OrderStatusType = "EXPIRED"
)
type Order struct {
ID int64 `db:"id" json:"id" gorm:"primaryKey,autoIncrement"`
ExchangeID int64 `db:"exchange_id" json:"exchange_id"`
Pair string `db:"pair" json:"pair"`
Side SideType `db:"side" json:"side"`
Type OrderType `db:"type" json:"type"`
Status OrderStatusType `db:"status" json:"status"`
Price float64 `db:"price" json:"price"`
Quantity float64 `db:"quantity" json:"quantity"`
CreatedAt time.Time `db:"created_at" json:"created_at"`
UpdatedAt time.Time `db:"updated_at" json:"updated_at"`
// OCO Orders only
Stop *float64 `db:"stop" json:"stop"`
GroupID *int64 `db:"group_id" json:"group_id"`
// Internal use (Plot)
RefPrice float64 `json:"ref_price" gorm:"-"`
Profit float64 `json:"profit" gorm:"-"`
ProfitValue float64 `json:"profit_value" gorm:"-"`
Candle Candle `json:"-" gorm:"-"`
}
func (o Order) String() string {
return fmt.Sprintf("[%s] %s %s | ID: %d, Type: %s, %f x $%f (~$%.f)",
o.Status, o.Side, o.Pair, o.ID, o.Type, o.Quantity, o.Price, o.Quantity*o.Price)
}