forked from coinrust/crex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
consts.go
151 lines (136 loc) · 3.38 KB
/
consts.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package crex
// TradeMode 策略模式
type TradeMode int
const (
TradeModeBacktest TradeMode = iota
TradeModePaperTrading
TradeModeLiveTrading
)
func (t TradeMode) String() string {
switch t {
case TradeModeBacktest:
return "Backtest"
case TradeModePaperTrading:
return "PaperTrading"
case TradeModeLiveTrading:
return "LiveTrading"
default:
return "None"
}
}
// 回测交易撮合事件类型
const (
SimEventKey = "event"
SimEventOrder = "order" // 委托
SimEventDeal = "deal" // 成交
)
// Direction 委托/持仓方向
type Direction int
const (
Buy Direction = iota // 做多
Sell // 做空
CloseBuy // 平多
CloseSell // 平空
)
func (d Direction) String() string {
switch d {
case Buy:
return "Buy"
case Sell:
return "Sell"
default:
return "None"
}
}
// OrderType 委托类型
type OrderType int
const (
OrderTypeMarket OrderType = iota // 市价单
OrderTypeLimit // 限价单
OrderTypeStopMarket // 市价止损单
OrderTypeStopLimit // 限价止损单
OrderTypeTrailingStopMarket
)
func (t OrderType) String() string {
switch t {
case OrderTypeMarket:
return "Market"
case OrderTypeLimit:
return "Limit"
case OrderTypeStopMarket:
return "StopMarket"
case OrderTypeStopLimit:
return "StopLimit"
case OrderTypeTrailingStopMarket:
return "TrailingStopMarket"
default:
return "None"
}
}
// OrderStatus 委托状态
type OrderStatus int
const (
OrderStatusCreated OrderStatus = iota // 创建委托
OrderStatusRejected // 委托被拒绝
OrderStatusNew // 委托待成交
OrderStatusPartiallyFilled // 委托部分成交
OrderStatusFilled // 委托完全成交
OrderStatusCancelPending // 委托取消
OrderStatusCancelled // 委托被取消
OrderStatusUntriggered // 等待触发条件委托单
OrderStatusTriggered // 已触发条件单
)
func (s OrderStatus) String() string {
switch s {
case OrderStatusCreated:
return "Created"
case OrderStatusRejected:
return "Rejected"
case OrderStatusNew:
return "New"
case OrderStatusPartiallyFilled:
return "PartiallyFilled"
case OrderStatusFilled:
return "Filled"
case OrderStatusCancelPending:
return "CancelPending"
case OrderStatusCancelled:
return "Cancelled"
case OrderStatusUntriggered:
return "Untriggered"
case OrderStatusTriggered:
return "Triggered"
default:
return "None"
}
}
// ContractType 合约类型
const (
ContractTypeNone = "" // Non-delivery contract 非交割合约
ContractTypeW1 = "W1" // week 当周合约
ContractTypeW2 = "W2" // two week 次周合约
ContractTypeM1 = "M1" // month 月合约
ContractTypeQ1 = "Q1" // quarter 季度合约
ContractTypeQ2 = "Q2" // two quarter 次季度合约
)
// K线周期
const (
PERIOD_1MIN = "1m"
PERIOD_3MIN = "3m"
PERIOD_5MIN = "5m"
PERIOD_15MIN = "15m"
PERIOD_30MIN = "30m"
PERIOD_60MIN = "60m"
PERIOD_1H = "1h"
PERIOD_2H = "2h"
PERIOD_3H = "3h"
PERIOD_4H = "4h"
PERIOD_6H = "6h"
PERIOD_8H = "8h"
PERIOD_12H = "12h"
PERIOD_1DAY = "1d"
PERIOD_3DAY = "3d"
PERIOD_1WEEK = "1w"
PERIOD_1MONTH = "1M"
PERIOD_1YEAR = "1y"
)