forked from thrasher-corp/gocryptotrader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig_types.go
374 lines (335 loc) · 17 KB
/
config_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
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
package config
import (
"errors"
"sync"
"time"
"github.com/thrasher-corp/gocryptotrader/communications/base"
"github.com/thrasher-corp/gocryptotrader/currency"
"github.com/thrasher-corp/gocryptotrader/database"
"github.com/thrasher-corp/gocryptotrader/exchanges/protocol"
"github.com/thrasher-corp/gocryptotrader/exchanges/subscription"
gctscript "github.com/thrasher-corp/gocryptotrader/gctscript/vm"
"github.com/thrasher-corp/gocryptotrader/log"
"github.com/thrasher-corp/gocryptotrader/portfolio"
"github.com/thrasher-corp/gocryptotrader/portfolio/banking"
)
// Constants declared here are filename strings and test strings
const (
FXProviderFixer = "fixer"
EncryptedFile = "config.dat"
File = "config.json"
TestFile = "../testdata/configtest.json"
fileEncryptionPrompt = 0
fileEncryptionEnabled = 1
fileEncryptionDisabled = -1
pairsLastUpdatedWarningThreshold = 30 // 30 days
defaultHTTPTimeout = time.Second * 15
defaultWebsocketOrderbookBufferLimit = 5
DefaultConnectionMonitorDelay = time.Second * 2
maxAuthFailures = 3
defaultNTPAllowedDifference = 50000000
defaultNTPAllowedNegativeDifference = 50000000
DefaultAPIKey = "Key"
DefaultAPISecret = "Secret"
DefaultAPIClientID = "ClientID"
defaultDataHistoryMonitorCheckTimer = time.Minute
defaultCurrencyStateManagerDelay = time.Minute
defaultMaxJobsPerCycle = 5
DefaultOrderbookPublishPeriod = time.Second * 10
// DefaultSyncerWorkers limits the number of sync workers
DefaultSyncerWorkers = 15
// DefaultSyncerTimeoutREST the default time to switch from REST to websocket protocols without a response
DefaultSyncerTimeoutREST = time.Second * 15
// DefaultSyncerTimeoutWebsocket the default time to switch from websocket to REST protocols without a response
DefaultSyncerTimeoutWebsocket = time.Minute
// DefaultWebsocketResponseCheckTimeout is the default timeout for
// websocket responses.
DefaultWebsocketResponseCheckTimeout = time.Millisecond * 30
// DefaultWebsocketResponseMaxLimit is the default maximum time for
// websocket responses.
DefaultWebsocketResponseMaxLimit = time.Second * 7
// DefaultWebsocketTrafficTimeout is the default timeout for websocket
// traffic.
DefaultWebsocketTrafficTimeout = time.Second * 30
)
// Constants here hold some messages
const (
warningExchangeAuthAPIDefaultOrEmptyValues = "exchange %s authenticated API support disabled due to default/empty APIKey/Secret/ClientID values"
warningPairsLastUpdatedThresholdExceeded = "exchange %s last manual update of available currency pairs has exceeded %d days. Manual update required!"
)
// Constants here define unset default values displayed in the config.json
// file
const (
APIURLNonDefaultMessage = "NON_DEFAULT_HTTP_LINK_TO_EXCHANGE_API"
WebsocketURLNonDefaultMessage = "NON_DEFAULT_HTTP_LINK_TO_WEBSOCKET_EXCHANGE_API"
DefaultUnsetAPIKey = "Key"
DefaultUnsetAPISecret = "Secret"
DefaultUnsetAccountPlan = "accountPlan"
)
// Public errors exported by this package
var (
ErrExchangeNotFound = errors.New("exchange not found")
ErrFailureOpeningConfig = errors.New("fatal error opening file")
)
var (
cfg Config
m sync.Mutex
errNoEnabledExchanges = errors.New("no exchanges enabled")
errCheckingConfigValues = errors.New("fatal error checking config values")
errExchangeNameEmpty = errors.New("exchange name is empty")
)
// Config is the overarching object that holds all the information for
// prestart management of Portfolio, Communications, Webserver and Enabled Exchanges
type Config struct {
Name string `json:"name"`
Version int `json:"version"`
DataDirectory string `json:"dataDirectory"`
EncryptConfig int `json:"encryptConfig"`
GlobalHTTPTimeout time.Duration `json:"globalHTTPTimeout"`
Database database.Config `json:"database"`
Logging log.Config `json:"logging"`
SyncManagerConfig SyncManagerConfig `json:"syncManager"`
ConnectionMonitor ConnectionMonitorConfig `json:"connectionMonitor"`
OrderManager OrderManager `json:"orderManager"`
DataHistoryManager DataHistoryManager `json:"dataHistoryManager"`
CurrencyStateManager CurrencyStateManager `json:"currencyStateManager"`
Profiler Profiler `json:"profiler"`
NTPClient NTPClientConfig `json:"ntpclient"`
GCTScript gctscript.Config `json:"gctscript"`
Currency currency.Config `json:"currencyConfig"`
Communications base.CommunicationsConfig `json:"communications"`
RemoteControl RemoteControlConfig `json:"remoteControl"`
Portfolio portfolio.Base `json:"portfolioAddresses"`
Exchanges []Exchange `json:"exchanges"`
BankAccounts []banking.Account `json:"bankAccounts"`
// Deprecated config settings, will be removed at a future date
Webserver *WebserverConfig `json:"webserver,omitempty"`
CurrencyPairFormat *currency.PairFormat `json:"currencyPairFormat,omitempty"`
FiatDisplayCurrency *currency.Code `json:"fiatDispayCurrency,omitempty"`
Cryptocurrencies *currency.Currencies `json:"cryptocurrencies,omitempty"`
SMS *base.SMSGlobalConfig `json:"smsGlobal,omitempty"`
// encryption session values
storedSalt []byte
sessionDK []byte
EncryptionKeyProvider EncryptionKeyProvider `json:"-"`
}
// EncryptionKeyProvider is a function config can use to prompt the user for an encryption key
type EncryptionKeyProvider func(confirmKey bool) ([]byte, error)
// OrderManager holds settings used for the order manager
type OrderManager struct {
Enabled *bool `json:"enabled"`
Verbose bool `json:"verbose"`
ActivelyTrackFuturesPositions bool `json:"activelyTrackFuturesPositions"`
FuturesTrackingSeekDuration time.Duration `json:"futuresTrackingSeekDuration"`
RespectOrderHistoryLimits *bool `json:"respectOrderHistoryLimits"`
CancelOrdersOnShutdown bool `json:"cancelOrdersOnShutdown"`
}
// DataHistoryManager holds all information required for the data history manager
type DataHistoryManager struct {
Enabled bool `json:"enabled"`
CheckInterval time.Duration `json:"checkInterval"`
MaxJobsPerCycle int64 `json:"maxJobsPerCycle"`
MaxResultInsertions int64 `json:"maxResultInsertions"`
Verbose bool `json:"verbose"`
}
// CurrencyStateManager defines a set of configuration options for the currency
// state manager
type CurrencyStateManager struct {
Enabled *bool `json:"enabled"`
Delay time.Duration `json:"delay"`
}
// SyncManagerConfig stores the currency pair synchronization manager config
type SyncManagerConfig struct {
Enabled bool `json:"enabled"`
SynchronizeTicker bool `json:"synchronizeTicker"`
SynchronizeOrderbook bool `json:"synchronizeOrderbook"`
SynchronizeTrades bool `json:"synchronizeTrades"`
SynchronizeContinuously bool `json:"synchronizeContinuously"`
TimeoutREST time.Duration `json:"timeoutREST"`
TimeoutWebsocket time.Duration `json:"timeoutWebsocket"`
NumWorkers int `json:"numWorkers"`
FiatDisplayCurrency currency.Code `json:"fiatDisplayCurrency"`
PairFormatDisplay *currency.PairFormat `json:"pairFormatDisplay,omitempty"`
// log events
Verbose bool `json:"verbose"`
LogSyncUpdateEvents bool `json:"logSyncUpdateEvents"`
LogSwitchProtocolEvents bool `json:"logSwitchProtocolEvents"`
LogInitialSyncEvents bool `json:"logInitialSyncEvents"`
}
// ConnectionMonitorConfig defines the connection monitor variables to ensure
// that there is internet connectivity
type ConnectionMonitorConfig struct {
DNSList []string `json:"preferredDNSList"`
PublicDomainList []string `json:"preferredDomainList"`
CheckInterval time.Duration `json:"checkInterval"`
}
// Exchange holds all the information needed for each enabled Exchange.
type Exchange struct {
Name string `json:"name"`
Enabled bool `json:"enabled"`
Verbose bool `json:"verbose"`
UseSandbox bool `json:"useSandbox,omitempty"`
HTTPTimeout time.Duration `json:"httpTimeout"`
HTTPUserAgent string `json:"httpUserAgent,omitempty"`
HTTPDebugging bool `json:"httpDebugging,omitempty"`
WebsocketResponseCheckTimeout time.Duration `json:"websocketResponseCheckTimeout"`
WebsocketResponseMaxLimit time.Duration `json:"websocketResponseMaxLimit"`
WebsocketTrafficTimeout time.Duration `json:"websocketTrafficTimeout"`
ConnectionMonitorDelay time.Duration `json:"connectionMonitorDelay"`
ProxyAddress string `json:"proxyAddress,omitempty"`
BaseCurrencies currency.Currencies `json:"baseCurrencies"`
CurrencyPairs *currency.PairsManager `json:"currencyPairs"`
API APIConfig `json:"api"`
Features *FeaturesConfig `json:"features"`
BankAccounts []banking.Account `json:"bankAccounts,omitempty"`
Orderbook Orderbook `json:"orderbook"`
// Deprecated settings which will be removed in a future update
AuthenticatedAPISupport *bool `json:"authenticatedApiSupport,omitempty"`
AuthenticatedWebsocketAPISupport *bool `json:"authenticatedWebsocketApiSupport,omitempty"`
APIKey *string `json:"apiKey,omitempty"`
APISecret *string `json:"apiSecret,omitempty"`
APIAuthPEMKeySupport *bool `json:"apiAuthPemKeySupport,omitempty"`
APIAuthPEMKey *string `json:"apiAuthPemKey,omitempty"`
APIURL *string `json:"apiUrl,omitempty"`
APIURLSecondary *string `json:"apiUrlSecondary,omitempty"`
ClientID *string `json:"clientId,omitempty"`
SupportsAutoPairUpdates *bool `json:"supportsAutoPairUpdates,omitempty"`
Websocket *bool `json:"websocket,omitempty"`
WebsocketURL *string `json:"websocketUrl,omitempty"`
}
// Profiler defines the profiler configuration to enable pprof
type Profiler struct {
Enabled bool `json:"enabled"`
MutexProfileFraction int `json:"mutex_profile_fraction"`
}
// NTPClientConfig defines a network time protocol configuration to allow for
// positive and negative differences
type NTPClientConfig struct {
Level int `json:"enabled"`
Pool []string `json:"pool"`
AllowedDifference *time.Duration `json:"allowedDifference"`
AllowedNegativeDifference *time.Duration `json:"allowedNegativeDifference"`
}
// GRPCConfig stores the gRPC settings
type GRPCConfig struct {
Enabled bool `json:"enabled"`
ListenAddress string `json:"listenAddress"`
GRPCProxyEnabled bool `json:"grpcProxyEnabled"`
GRPCProxyListenAddress string `json:"grpcProxyListenAddress"`
GRPCAllowBotShutdown bool `json:"grpcAllowBotShutdown"`
TimeInNanoSeconds bool `json:"timeInNanoSeconds"`
}
// DepcrecatedRPCConfig stores the deprecatedRPCConfig settings
type DepcrecatedRPCConfig struct {
Enabled bool `json:"enabled"`
ListenAddress string `json:"listenAddress"`
}
// WebsocketRPCConfig stores the websocket config info
type WebsocketRPCConfig struct {
Enabled bool `json:"enabled"`
ListenAddress string `json:"listenAddress"`
ConnectionLimit int `json:"connectionLimit"`
MaxAuthFailures int `json:"maxAuthFailures"`
AllowInsecureOrigin bool `json:"allowInsecureOrigin"`
}
// RemoteControlConfig stores the RPC services config
type RemoteControlConfig struct {
Username string `json:"username"`
Password string `json:"password"`
GRPC GRPCConfig `json:"gRPC"`
DeprecatedRPC DepcrecatedRPCConfig `json:"deprecatedRPC"`
WebsocketRPC WebsocketRPCConfig `json:"websocketRPC"`
}
// WebserverConfig stores the old webserver config
type WebserverConfig struct {
Enabled bool `json:"enabled"`
AdminUsername string `json:"adminUsername"`
AdminPassword string `json:"adminPassword"`
ListenAddress string `json:"listenAddress"`
WebsocketConnectionLimit int `json:"websocketConnectionLimit"`
WebsocketMaxAuthFailures int `json:"websocketMaxAuthFailures"`
WebsocketAllowInsecureOrigin bool `json:"websocketAllowInsecureOrigin"`
}
// Post holds the bot configuration data
type Post struct {
Data Config `json:"data"`
}
// CurrencyPairFormatConfig stores the users preferred currency pair display
type CurrencyPairFormatConfig struct {
Uppercase bool `json:"uppercase"`
Delimiter string `json:"delimiter,omitempty"`
Separator string `json:"separator,omitempty"`
Index string `json:"index,omitempty"`
}
// BankTransaction defines a related banking transaction
type BankTransaction struct {
ReferenceNumber string `json:"referenceNumber"`
TransactionNumber string `json:"transactionNumber"`
PaymentInstructions string `json:"paymentInstructions"`
}
// FeaturesSupportedConfig stores the exchanges supported features
type FeaturesSupportedConfig struct {
REST bool `json:"restAPI"`
RESTCapabilities protocol.Features `json:"restCapabilities,omitempty"`
Websocket bool `json:"websocketAPI"`
WebsocketCapabilities protocol.Features `json:"websocketCapabilities,omitempty"`
}
// FeaturesEnabledConfig stores the exchanges enabled features
type FeaturesEnabledConfig struct {
AutoPairUpdates bool `json:"autoPairUpdates"`
Websocket bool `json:"websocketAPI"`
SaveTradeData bool `json:"saveTradeData"`
TradeFeed bool `json:"tradeFeed"`
FillsFeed bool `json:"fillsFeed"`
}
// FeaturesConfig stores the exchanges supported and enabled features
type FeaturesConfig struct {
Supports FeaturesSupportedConfig `json:"supports"`
Enabled FeaturesEnabledConfig `json:"enabled"`
Subscriptions subscription.List `json:"subscriptions,omitempty"`
}
// APIEndpointsConfig stores the API endpoint addresses
type APIEndpointsConfig struct {
URL string `json:"url"`
URLSecondary string `json:"urlSecondary"`
WebsocketURL string `json:"websocketURL"`
}
// APICredentialsConfig stores the API credentials
type APICredentialsConfig struct {
Key string `json:"key,omitempty"`
Secret string `json:"secret,omitempty"`
ClientID string `json:"clientID,omitempty"`
Subaccount string `json:"subaccount,omitempty"`
PEMKey string `json:"pemKey,omitempty"`
OTPSecret string `json:"otpSecret,omitempty"`
TradePassword string `json:"tradePassword,omitempty"`
PIN string `json:"pin,omitempty"`
}
// APICredentialsValidatorConfig stores the API credentials validator settings
type APICredentialsValidatorConfig struct {
// For Huobi (optional)
RequiresPEM bool `json:"requiresPEM,omitempty"`
RequiresKey bool `json:"requiresKey,omitempty"`
RequiresSecret bool `json:"requiresSecret,omitempty"`
RequiresClientID bool `json:"requiresClientID,omitempty"`
RequiresBase64DecodeSecret bool `json:"requiresBase64DecodeSecret,omitempty"`
}
// APIConfig stores the exchange API config
type APIConfig struct {
AuthenticatedSupport bool `json:"authenticatedSupport"`
AuthenticatedWebsocketSupport bool `json:"authenticatedWebsocketApiSupport"`
PEMKeySupport bool `json:"pemKeySupport,omitempty"`
Credentials APICredentialsConfig `json:"credentials"`
CredentialsValidator *APICredentialsValidatorConfig `json:"credentialsValidator,omitempty"`
OldEndPoints *APIEndpointsConfig `json:"endpoints,omitempty"`
Endpoints map[string]string `json:"urlEndpoints"`
}
// Orderbook stores the orderbook configuration variables
type Orderbook struct {
VerificationBypass bool `json:"verificationBypass"`
WebsocketBufferLimit int `json:"websocketBufferLimit"`
WebsocketBufferEnabled bool `json:"websocketBufferEnabled"`
// PublishPeriod here is a pointer because we want to distinguish
// between zeroed out and missing.
PublishPeriod *time.Duration `json:"publishPeriod"`
}