This repository has been archived by the owner on Oct 11, 2023. It is now read-only.
/
fill.go
72 lines (61 loc) · 1.55 KB
/
fill.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
package gobacktest
// Fill declares a basic fill event
type Fill struct {
Event
direction Direction // BOT for buy, SLD for sell, HLD for hold
Exchange string // exchange symbol
qty int64
price float64
commission float64
exchangeFee float64
cost float64 // the total cost of the filled order incl commission and fees
}
// Direction returns the direction of a Fill
func (f Fill) Direction() Direction {
return f.direction
}
// SetDirection sets the Directions field of a Fill
func (f *Fill) SetDirection(dir Direction) {
f.direction = dir
}
// Qty returns the qty field of a fill
func (f Fill) Qty() int64 {
return f.qty
}
// SetQty sets the Qty field of a Fill
func (f *Fill) SetQty(i int64) {
f.qty = i
}
// Price returns the Price field of a fill
func (f Fill) Price() float64 {
return f.price
}
// Commission returns the Commission field of a fill.
func (f Fill) Commission() float64 {
return f.commission
}
// ExchangeFee returns the ExchangeFee Field of a fill
func (f Fill) ExchangeFee() float64 {
return f.exchangeFee
}
// Cost returns the Cost field of a Fill
func (f Fill) Cost() float64 {
return f.cost
}
// Value returns the value without cost.
func (f Fill) Value() float64 {
value := float64(f.qty) * f.price
return value
}
// NetValue returns the net value including cost.
func (f Fill) NetValue() float64 {
if f.direction == BOT {
// qty * price + cost
netValue := float64(f.qty)*f.price + f.cost
return netValue
}
// SLD
//qty * price - cost
netValue := float64(f.qty)*f.price - f.cost
return netValue
}