/
order_manager_types.go
76 lines (66 loc) · 2.56 KB
/
order_manager_types.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
package engine
import (
"errors"
"sync"
"time"
"github.com/thrasher-corp/gocryptotrader/currency"
"github.com/thrasher-corp/gocryptotrader/exchanges/futures"
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
)
// OrderManagerName is an exported subsystem name
const OrderManagerName = "orders"
// vars for the fund manager package
var (
// ErrOrdersAlreadyExists occurs when the order already exists in the manager
ErrOrdersAlreadyExists = errors.New("order already exists")
// ErrOrderIDCannotBeEmpty occurs when an order does not have an ID
ErrOrderIDCannotBeEmpty = errors.New("orderID cannot be empty")
// ErrOrderNotFound occurs when an order is not found in the orderstore
ErrOrderNotFound = errors.New("order does not exist")
errNilCommunicationsManager = errors.New("cannot start with nil communications manager")
errNilOrder = errors.New("nil order received")
errFuturesTrackingDisabled = errors.New("tracking futures positions disabled. enable it via config under orderManager activelyTrackFuturesPositions")
orderManagerInterval = time.Second * 10
defaultOrderSeekTime = -time.Hour * 24 * 365
)
type orderManagerConfig struct {
EnforceLimitConfig bool
AllowMarketOrders bool
CancelOrdersOnShutdown bool
LimitAmount float64
AllowedPairs currency.Pairs
AllowedExchanges []string
OrderSubmissionRetries int64
}
// OrderManager processes and stores orders across enabled exchanges
type OrderManager struct {
started int32
processingOrders int32
shutdown chan struct{}
orderStore store
cfg orderManagerConfig
verbose bool
activelyTrackFuturesPositions bool
futuresPositionSeekDuration time.Duration
respectOrderHistoryLimits bool
}
// store holds all orders by exchange
type store struct {
m sync.RWMutex
Orders map[string][]*order.Detail
commsManager iCommsManager
exchangeManager iExchangeManager
wg *sync.WaitGroup
futuresPositionController futures.PositionController
}
// OrderSubmitResponse contains the order response along with an internal order ID
type OrderSubmitResponse struct {
*order.Detail
InternalOrderID string
}
// OrderUpsertResponse contains a copy of the resulting order details and a bool
// indicating if the order details were inserted (true) or updated (false)
type OrderUpsertResponse struct {
OrderDetails order.Detail
IsNewOrder bool
}