-
Notifications
You must be signed in to change notification settings - Fork 5
/
types.go
353 lines (318 loc) · 8.73 KB
/
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
package common
import (
"crypto/rsa"
"net/http"
"time"
"github.com/shopspring/decimal"
)
const (
APPNAME = "tradebot"
APPVERSION = "0.0.1"
TIME_FORMAT = time.RFC3339
TIME_DISPLAY_FORMAT = "01-02-2006 15:04:05 MST"
BUFFERED_CHANNEL_SIZE = 256
WEBSOCKET_KEEPALIVE = 10 * time.Second
HTTP_CLIENT_TIMEOUT = 10 * time.Second
CANDLESTICK_MIN_LOAD = 250
INDICATOR_PLUGIN_TYPE = "indicator"
STRATEGY_PLUGIN_TYPE = "strategy"
EXCHANGE_PLUGIN_TYPE = "exchange"
WALLET_PLUGIN_TYPE = "wallet"
BUY_ORDER_TYPE = "buy"
SELL_ORDER_TYPE = "sell"
DEPOSIT_ORDER_TYPE = "deposit"
WITHDRAWAL_ORDER_TYPE = "withdrawal"
TX_CATEGORY_DEPOSIT = "deposit"
TX_CATEGORY_WITHDRAWAL = "withdrawal"
TX_CATEGORY_TRADE = "trade"
TX_CATEGORY_INCOME = "income"
TX_CATEGORY_GIFT = "gift"
TX_CATEGORY_MINING = "mining"
TX_CATEGORY_SPEND = "spend"
TX_CATEGORY_DONATION = "donation"
TX_CATEGORY_LOST = "lost"
TX_CATEGORY_TRANSFER = "transfer"
)
type Transaction interface {
GetId() string
GetDate() time.Time
GetMarketPair() *CurrencyPair
GetCurrencyPair() *CurrencyPair
GetType() string
GetCategory() string
GetNetwork() string
GetNetworkDisplayName() string
GetQuantity() string
GetQuantityCurrency() string
GetFiatQuantity() string
GetFiatQuantityCurrency() string
GetPrice() string
GetPriceCurrency() string
GetFiatPrice() string
GetFiatPriceCurrency() string
GetQuoteFiatPrice() string
GetQuoteFiatPriceCurrency() string
GetFee() string
GetFeeCurrency() string
GetTotal() string
GetTotalCurrency() string
GetFiatFee() string
GetFiatFeeCurrency() string
GetFiatTotal() string
GetFiatTotalCurrency() string
IsDeleted() bool
String() string
}
type EthereumToken interface {
GetName() string
GetSymbol() string
GetDecimals() uint8
GetBalance() decimal.Decimal
GetWalletAddress() string
GetContractAddress() string
GetValue() decimal.Decimal
}
type EthereumContract interface {
GetAddress() string
GetSource() string
GetBin() string
GetABI() string
GetCreationDate() time.Time
}
type Plugin interface {
GetName() string
GetFilename() string
GetVersion() string
GetType() string
}
type Chart interface {
GetId() uint
GetBase() string
GetQuote() string
GetExchange() string
GetPeriod() int
GetPrice() float64
GetAutoTrade() uint
IsAutoTrade() bool
GetIndicators() []ChartIndicator
GetStrategies() []ChartStrategy
GetTrades() []Trade
ToJSON() (string, error)
}
type ChartIndicator interface {
GetId() uint
GetChartId() uint
GetName() string
GetParameters() string
GetFilename() string
}
type ChartStrategy interface {
GetId() uint
GetChartId() uint
GetName() string
GetParameters() string
GetFilename() string
}
type Trade interface {
GetId() uint
GetChartId() uint
GetUserId() uint
GetBase() string
GetQuote() string
GetExchange() string
GetDate() time.Time
GetType() string
GetPrice() decimal.Decimal
GetAmount() decimal.Decimal
GetChartData() string
}
type Profit interface {
GetUserId() uint
GetTradeId() uint
GetQuantity() decimal.Decimal
GetBought() decimal.Decimal
GetSold() decimal.Decimal
GetFee() decimal.Decimal
GetTax() decimal.Decimal
GetTotal() decimal.Decimal
}
type FinancialIndicator interface {
GetDefaultParameters() []string
GetParameters() []string
GetDisplayName() string
GetName() string
PeriodListener
}
type TradingStrategy interface {
GetRequiredIndicators() []string
Analyze() (bool, bool, map[string]string, error)
CalculateFeeAndTax(price decimal.Decimal) (decimal.Decimal, decimal.Decimal)
GetTradeAmounts() (decimal.Decimal, decimal.Decimal)
GetParameters() *TradingStrategyParams
}
type ChartTradingStrategy interface {
GetId() uint
GetChartId() uint
GetName() string
GetParameters() string
GetDefaultParameters() string
GetRequiredIndicators() string
}
type PriceListener interface {
OnPriceChange(priceChange *PriceChange)
}
type PeriodListener interface {
OnPeriodChange(candlestick *Candlestick)
}
type FiatPriceService interface {
GetPriceAt(currency string, date time.Time) (*Candlestick, error)
}
type Exchange interface {
GetName() string
GetDisplayName() string
GetBalances() ([]Coin, decimal.Decimal)
GetSummary() CryptoExchangeSummary
GetNetWorth() decimal.Decimal
GetTradingFee() decimal.Decimal
//GetCurrencies() []string
SubscribeToLiveFeed(currencyPair *CurrencyPair, price chan PriceChange)
GetPrice(currencyPair *CurrencyPair) decimal.Decimal
GetPriceHistory(currencyPair *CurrencyPair, start, end time.Time, granularity int) ([]Candlestick, error)
GetOrderHistory(currencyPair *CurrencyPair) []Transaction
GetDepositHistory() ([]Transaction, error)
GetWithdrawalHistory() ([]Transaction, error)
GetCurrencies() (map[string]*Currency, error)
FormattedCurrencyPair(currencyPair *CurrencyPair) string
ParseImport(file string) ([]Transaction, error)
}
type KeyPair interface {
GetDirectory() string
GetPrivateKey() *rsa.PrivateKey
GetPrivateBytes() []byte
GetPublicKey() *rsa.PublicKey
GetPublicBytes() []byte
}
type UserContext interface {
GetId() uint
GetUsername() string
GetLocalCurrency() string
GetFiatExchange() string
GetEtherbase() string
GetKeystore() string
}
type UserCryptoExchange interface {
GetUserID() uint
GetName() string
GetKey() string
GetURL() string
GetSecret() string
GetExtra() string
}
type Coin interface {
GetCurrency() string
GetPrice() decimal.Decimal
GetExchange() string
GetBalance() decimal.Decimal
GetAvailable() decimal.Decimal
GetPending() decimal.Decimal
GetAddress() string
GetTotal() decimal.Decimal
GetBTC() decimal.Decimal
GetUSD() decimal.Decimal
IsBitcoin() bool
}
type CryptoExchangeSummary interface {
GetName() string
GetURL() string
GetTotal() decimal.Decimal
GetSatoshis() decimal.Decimal
GetCoins() []Coin
}
type UserCryptoWallet interface {
GetAddress() string
GetBalance() decimal.Decimal
GetCurrency() string
GetValue() decimal.Decimal
}
type Portfolio interface {
GetUser() UserContext
GetNetWorth() decimal.Decimal
GetExchanges() []CryptoExchangeSummary
GetWallets() []UserCryptoWallet
GetTokens() []EthereumToken
}
type HttpWriter interface {
Write(w http.ResponseWriter, status int, response interface{})
}
type MarketCapService interface {
GetMarkets() []MarketCap
GetMarket(symbol string) MarketCap
GetGlobalMarket(currency string) *GlobalMarketCap
GetMarketsByPrice(order string) []MarketCap
GetMarketsByPercentChange1H(order string) []MarketCap
GetMarketsByPercentChange24H(order string) []MarketCap
GetMarketsByPercentChange7D(order string) []MarketCap
GetMarketsByTopPerformers(order string) []MarketCap
GetTrendingMarkets(order string) []MarketCap
}
type Wallet interface {
GetPrice() decimal.Decimal
GetWallet() (UserCryptoWallet, error)
GetTransactions() ([]Transaction, error)
}
type WalletParams struct {
Context Context
Address string
WalletUser string
WalletSecret string
WalletExtra string
MarketCapService MarketCapService
FiatPriceService FiatPriceService
}
type TradingStrategyParams struct {
CurrencyPair *CurrencyPair
Balances []Coin
Indicators map[string]FinancialIndicator
NewPrice decimal.Decimal
LastTrade Trade
TradeFee decimal.Decimal
Config []string
}
type PriceChange struct {
Exchange string `json:"exchange"`
CurrencyPair *CurrencyPair `json:"currencyPair"`
Satoshis decimal.Decimal `json:"satoshis"`
Price decimal.Decimal `json:"price"`
}
type ChartData struct {
CurrencyPair CurrencyPair `json:"currency"`
Exchange string `json:"exchange"`
Price float64 `json:"price"`
Satoshis float64 `json:"satoshis"`
Indicators map[string]string `json:"indicators"`
}
type GlobalMarketCap struct {
TotalMarketCapUSD float64 `json:"total_market_cap_usd"`
Total24HVolumeUSD float64 `json:"total_24h_volume_usd"`
BitcoinDominance float64 `json:"bitcoin_percentage_of_market_cap"`
ActiveCurrencies float64 `json:"active_currencies"`
ActiveMarkets float64 `json:"active_markets"`
LastUpdated int64 `json:"last_updated"`
}
type MarketCap struct {
Id string `json:"id"`
Name string `json:"name"`
Symbol string `json:"symbol"`
Rank string `json:"rank"`
PriceUSD string `json:"price_usd"`
PriceBTC string `json:"price_btc"`
VolumeUSD24h string `json:"24h_volume_usd"`
MarketCapUSD string `json:"market_cap_usd"`
AvailableSupply string `json:"available_supply"`
TotalSupply string `json:"total_supply"`
MaxSupply string `json:"max_supply"`
PercentChange1h string `json:"percent_change_1h"`
PercentChange24h string `json:"percent_change_24h"`
PercentChange7d string `json:"percent_change_7d"`
LastUpdated string `json:"last_updated"`
}