This repository has been archived by the owner on Oct 11, 2023. It is now read-only.
/
order.go
99 lines (83 loc) · 1.87 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package gobacktest
// OrderStatus defines an order status
type OrderStatus int
// different types of order status
const (
OrderNone OrderStatus = iota // 0
OrderNew
OrderSubmitted
OrderPartiallyFilled
OrderFilled
OrderCanceled
OrderCancelPending
OrderInvalid
)
// OrderType defines which type an order is
type OrderType int
// different types of orders
const (
MarketOrder OrderType = iota // 0
MarketOnOpenOrder
MarketOnCloseOrder
StopMarketOrder
LimitOrder
StopLimitOrder
)
// Order declares a basic order event.
type Order struct {
Event
id int
orderType OrderType // market or limit
status OrderStatus
direction Direction // buy or sell
assetType string
qty int64 // quantity of the order
qtyFilled int64
avgFillPrice float64
limitPrice float64 // limit for the order
stopPrice float64
}
// ID returns the id of the Order.
func (o Order) ID() int {
return o.id
}
// SetID of the Order.
func (o *Order) SetID(id int) {
o.id = id
}
// Direction returns the Direction of an Order
func (o Order) Direction() Direction {
return o.direction
}
// SetDirection sets the Directions field of an Order
func (o *Order) SetDirection(dir Direction) {
o.direction = dir
}
// Qty returns the Qty field of an Order
func (o Order) Qty() int64 {
return o.qty
}
// SetQty sets the Qty field of an Order
func (o *Order) SetQty(i int64) {
o.qty = i
}
// Status returns the status of an Order
func (o Order) Status() OrderStatus {
return o.status
}
// Limit returns the limit price of an Order
func (o Order) Limit() float64 {
return o.limitPrice
}
// Stop returns the stop price of an Order
func (o Order) Stop() float64 {
return o.stopPrice
}
// Cancel cancels an order
func (o *Order) Cancel() {
o.status = OrderCancelPending
}
// Update updates an order on a fill event
func (o *Order) Update(fill FillEvent) {
// not implemented
}