forked from schmidthole/techan
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathorder.go
More file actions
68 lines (56 loc) · 1.54 KB
/
Copy pathorder.go
File metadata and controls
68 lines (56 loc) · 1.54 KB
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
package techan
import (
"time"
"github.com/schmidthole/big"
)
// OrderSide is a simple enumeration representing the side of an Order (buy or sell)
type OrderSide string
// BUY and SELL enumerations
const (
BUY OrderSide = "BUY"
SELL OrderSide = "SELL"
)
// OrderType defines common order types accepted by brokers
type OrderType string
// OrderType enumerations, we only support the basics at this time
// there are more complex types such as "stop limit" "trail" etc. that may be added later
const (
MARKET OrderType = "MKT"
LIMIT OrderType = "LMT"
STOP OrderType = "STP"
)
// TimeInForce defines how long an order is good for before it is auto cancelled
type TimeInForce string
// TimeInForce option enumerations
const (
GTC TimeInForce = "GTC"
OPG TimeInForce = "OPG"
DAY TimeInForce = "DAY"
IOC TimeInForce = "IOC"
)
// OrderStatus defines the state of an order with a broker
type OrderStatus string
const (
PENDING OrderStatus = "Pending"
FILLED OrderStatus = "Filled"
CANCELLED OrderStatus = "Cancelled"
OTHER OrderStatus = "Other"
)
// Order represents a trade execution (buy or sell) with associated metadata.
type Order struct {
ID string
Side OrderSide
Security string
ContractID int
Price big.Decimal
Type OrderType
FilledAmount big.Decimal
Amount big.Decimal
TimeInForce TimeInForce
ExecutionTime time.Time
Status OrderStatus
}
// Return the total cost to execute the order.
func (o *Order) CostBasis() big.Decimal {
return o.Amount.Mul(o.Price)
}