-
Notifications
You must be signed in to change notification settings - Fork 78
/
database.sql
292 lines (243 loc) · 8.5 KB
/
database.sql
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
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
-- --------------------------------------------------------
--
-- Table structure for table `alerts`
--
CREATE TABLE IF NOT EXISTS `alerts` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`created` int(11) NOT NULL,
`type` ENUM('stuck-transfer', 'poloniex-withdrawal-limit','duplicate-withdrawal') NOT NULL,
`message` text NOT NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
-- --------------------------------------------------------
--
-- Table structure for table `balances`
--
CREATE TABLE IF NOT EXISTS `balances` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`created` int(11) NOT NULL,
`coin` char(10) NOT NULL,
`value` varchar(18) NOT NULL,
`raw` varchar(18) NOT NULL,
`ID_exchange` int(11) NOT NULL,
PRIMARY KEY (`ID`),
KEY `coin` (`coin`),
KEY `ID_exchange` (`ID_exchange`),
INDEX `coin_ID_exchange` (`coin`, `ID_exchange`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
-- --------------------------------------------------------
--
-- Table structure for table `exchange_trades`
--
CREATE TABLE `exchange_trades` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`created` int(11) NOT NULL,
`ID_exchange` int(11) NOT NULL,
`type` ENUM('buy', 'sell') NOT NULL,
`coin` char(10) NOT NULL,
`currency` char(10) NOT NULL,
`raw_trade_ID` varchar(255) NOT NULL,
`trade_ID` varchar(255) NOT NULL,
`rate` varchar(18) NOT NULL,
`amount` varchar(18) NOT NULL,
`fee` varchar(18) NOT NULL,
`total` varchar(18) NOT NULL,
PRIMARY KEY (`ID`),
UNIQUE KEY (`ID_exchange`, `raw_trade_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
-- --------------------------------------------------------
--
-- Table structure for table `log`
--
CREATE TABLE IF NOT EXISTS `log` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`created` int(11) NOT NULL,
`message` text NOT NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
-- --------------------------------------------------------
--
-- Table structure for table `management`
--
CREATE TABLE IF NOT EXISTS `management` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`created` int(11) NOT NULL,
`ID_exchange` int(11) NOT NULL,
`coin` char(10) NOT NULL,
`amount` varchar(18) NOT NULL,
`rate` varchar(18) NOT NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
-- --------------------------------------------------------
--
--
-- Table structure for table `profits`
--
CREATE TABLE IF NOT EXISTS `profits` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`created` int(11) NOT NULL,
`currency` char(10) NOT NULL,
`amount` varchar(18) NOT NULL,
`cash_restock_percent` varchar(18) NOT NULL,
`cash_restock_amount` varchar(18) NOT NULL,
`address` text NOT NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
-- --------------------------------------------------------
--
-- Table structure for table `profit_loss`
--
CREATE TABLE `profit_loss` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`created` int(11) NOT NULL,
`ID_exchange_source` int(11) NOT NULL,
`ID_exchange_target` int(11) NOT NULL,
`coin` char(10) NOT NULL,
`currency` char(10) NOT NULL,
`raw_trade_IDs_buy` varchar(4096) NOT NULL,
`trade_IDs_buy` varchar(4096) NOT NULL,
`raw_trade_IDs_sell` varchar(4096) NOT NULL,
`trade_IDs_sell` varchar(4096) NOT NULL,
`rate_buy` varchar(18) NOT NULL,
`rate_sell` varchar(18) NOT NULL,
`tradeable_bought` varchar(18) NOT NULL,
`tradeable_sold` varchar(18) NOT NULL,
`currency_bought` varchar(18) NOT NULL,
`currency_sold` varchar(18) NOT NULL,
`currency_revenue` varchar(18) NOT NULL,
`currency_pl` varchar(18) NOT NULL,
`tradeable_tx_fee` varchar(18) NOT NULL,
`currency_tx_fee` varchar(18) NOT NULL,
`buy_fee` varchar(18) NOT NULL,
`sell_fee` varchar(18) NOT NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
-- --------------------------------------------------------
--
-- Table structure for table `snapshot`
--
CREATE TABLE IF NOT EXISTS `snapshot` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`created` int(11) NOT NULL,
`coin` char(10) NOT NULL,
`balance` varchar(18) NOT NULL,
`desired_balance` varchar(18) DEFAULT NULL,
`uses` int(11) NOT NULL,
`trades` int(11) NOT NULL,
`rate` varchar(18) NOT NULL,
`ID_exchange` int(11) NOT NULL,
PRIMARY KEY (`ID`),
KEY `created` (`created`),
KEY `coin` (`coin`),
KEY `ID_exchange` (`ID_exchange`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
-- --------------------------------------------------------
--
-- Table structure for table `stats`
--
CREATE TABLE IF NOT EXISTS `stats` (
`keyy` varchar(255) NOT NULL,
`value` varchar(255) NOT NULL,
PRIMARY KEY (`keyy`),
KEY `key` (`keyy`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- --------------------------------------------------------
--
-- Table structure for table `track`
--
CREATE TABLE IF NOT EXISTS `track` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`created` int(11) NOT NULL,
`coin` char(10) NOT NULL,
`currency` char(10) NOT NULL,
`amount` varchar(18) NOT NULL,
`profit` varchar(18) NOT NULL,
`ID_exchange_source` int(11) NOT NULL,
`ID_exchange_target` int(11) NOT NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
-- --------------------------------------------------------
--
-- Table structure for table `trade`
--
CREATE TABLE IF NOT EXISTS `trade` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`created` int(11) NOT NULL,
`coin` char(10) NOT NULL,
`currency` char(10) NOT NULL,
`amount` varchar(18) NOT NULL,
`ID_exchange_source` int(11) NOT NULL,
`ID_exchange_target` int(11) NOT NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
-- --------------------------------------------------------
--
-- Table structure for table `wallets`
--
CREATE TABLE IF NOT EXISTS `wallets` (
`ID_exchange` int(11) NOT NULL,
`coin` char(10) NOT NULL,
`created` int(11) NOT NULL,
`amount` varchar(18) NOT NULL,
PRIMARY KEY (`ID_exchange`, `coin`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ;
-- --------------------------------------------------------
--
-- Table structure for table `withdrawal`
--
CREATE TABLE IF NOT EXISTS `withdrawal` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`created` int(11) NOT NULL,
`ID_exchange_source` int(11) NOT NULL,
`ID_exchange_target` int(11) NOT NULL,
`coin` char(10) NOT NULL,
`amount` varchar(18) NOT NULL,
`address` text NOT NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
-- --------------------------------------------------------
--
-- Table structure for table `pending_deposits`
--
CREATE TABLE IF NOT EXISTS `pending_deposits` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`ID_withdrawal` int(11) NULL,
`created` int(11) NOT NULL,
`ID_exchange` int(11) NOT NULL,
`coin` char(10) NOT NULL,
`amount` varchar(18) NOT NULL,
PRIMARY KEY (`ID`),
FOREIGN KEY (`ID_withdrawal`) REFERENCES `withdrawal`(`ID`)
ON DELETE SET NULL
ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
-- --------------------------------------------------------
--
-- View structure for view `current_snapshot`
--
CREATE OR REPLACE VIEW `current_snapshot` AS
SELECT * FROM snapshot WHERE created = (SELECT MAX(created) FROM snapshot);
-- --------------------------------------------------------
--
-- View structure for view `current_simulated_profit_rate_raw`
--
CREATE OR REPLACE VIEW `current_simulated_profit_rate_raw` AS
SELECT MAX(t.`created`) AS `created`, t.`coin`, t.`currency`, SUM(t.`amount`) * MAX(`rate`) AS `price`,
SUM(t.`profit`) AS `profit`, SUM(`profit`) / (SUM(t.`amount`) * MAX(`rate`)) AS `ratio`, `ID_exchange_source`, `ID_exchange_target`
FROM `track` AS t INNER JOIN `current_snapshot` AS s ON
t.`coin` = s.`coin` AND t.`ID_exchange_target` = s.`ID_exchange`
WHERE UNIX_TIMESTAMP() - t.`created` < 24 * 60 * 60
GROUP BY t.`coin`, t.`currency`, `ID_exchange_source`, `ID_exchange_target`
ORDER BY SUM(`profit`) / (SUM(t.`amount`) * MAX(`rate`)) DESC;
-- --------------------------------------------------------
--
-- View structure for view `current_simulated_profit_rate`
--
CREATE OR REPLACE VIEW `current_simulated_profit_rate` AS
SELECT `created`, `coin`, `currency`, `price`, `profit`,
FLOOR(`ratio` / (SELECT ratio FROM `current_simulated_profit_rate_raw` ORDER BY `ratio` ASC LIMIT 1)) AS `ratio`,
`ID_exchange_source`, `ID_exchange_target`
FROM `current_simulated_profit_rate_raw`
ORDER BY `ratio` DESC;