-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsource code
More file actions
617 lines (514 loc) · 16.8 KB
/
source code
File metadata and controls
617 lines (514 loc) · 16.8 KB
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
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
// JavaScript code to fetch current cryptocurrency prices
// API endpoint to fetch prices
const API_URL = "https://api.coinmarketcap.com/v1/ticker/?limit=10";
// Fetch data from API
fetch(API_URL)
.then(response => response.json())
.then(data => {
// Iterate through the data and extract the desired information
data.forEach(coin => {
console.log(`${coin.name} - ${coin.price_usd}`);
});
});
// JavaScript code to fetch the current value of user's holdings
// API endpoint to fetch prices
const API_URL = "https://api.coinmarketcap.com/v1/ticker/";
// Get the current value of the user's holdings
function getHoldingsValue(holdings) {
let totalValue = 0;
// Iterate through the holdings and fetch the current price for each coin
for (let i = 0; i < holdings.length; i++) {
let coin = holdings[i];
fetch(API_URL + coin.symbol)
.then(response => response.json())
.then(data => {
totalValue += data[0].price_usd * coin.amount;
});
}
return totalValue;
}
// Example usage
let myHoldings = [
{ symbol: "BTC", amount: 2.5 },
{ symbol: "ETH", amount: 10 },
{ symbol: "XRP", amount: 5000 }
];
let value = getHoldingsValue(myHoldings);
console.log("Current value of my holdings: $" + value);
// JavaScript code to track user's portfolio of cryptocurrencies
const API_URL = "https://api.coinmarketcap.com/v1/ticker/";
// Portfolio class to store and track user's holdings
class Portfolio {
constructor() {
this.holdings = [];
}
// Add a new holding to the portfolio
addHolding(symbol, amount) {
this.holdings.push({ symbol: symbol, amount: amount });
}
// Remove a holding from the portfolio
removeHolding(symbol) {
this.holdings = this.holdings.filter(holding => holding.symbol !== symbol);
}
// Get the current value of the portfolio
getValue() {
let totalValue = 0;
for (let i = 0; i < this.holdings.length; i++) {
let coin = this.holdings[i];
fetch(API_URL + coin.symbol)
.then(response => response.json())
.then(data => {
totalValue += data[0].price_usd * coin.amount;
});
}
return totalValue;
}
}
// Example usage
let myPortfolio = new Portfolio();
myPortfolio.addHolding("BTC", 2.5);
myPortfolio.addHolding("ETH", 10);
myPortfolio.addHolding("XRP", 5000);
console.log("Current value of my portfolio: $" + myPortfolio.getValue());
myPortfolio.removeHolding("XRP");
console.log("Current value of my portfolio after removing XRP: $" + myPortfolio.getValue());
// JavaScript code to track user's portfolio of cryptocurrencies
const API_URL = "https://api.coinmarketcap.com/v1/ticker/";
// Portfolio class to store and track user's holdings
class Portfolio {
constructor() {
this.holdings = [];
}
// Add a new holding to the portfolio
addHolding(symbol, amount) {
this.holdings.push({ symbol: symbol, amount: amount });
this.storeHoldings();
}
// Remove a holding from the portfolio
removeHolding(symbol) {
this.holdings = this.holdings.filter(holding => holding.symbol !== symbol);
this.storeHoldings();
}
// Store the current holdings in local storage
storeHoldings() {
localStorage.setItem("portfolio", JSON.stringify(this.holdings));
}
// Retrieve the holdings from local storage
retrieveHoldings() {
let storedHoldings = localStorage.getItem("portfolio");
if (storedHoldings) {
this.holdings = JSON.parse(storedHoldings);
}
}
// Get the current value of the portfolio
getValue() {
let totalValue = 0;
for (let i = 0; i < this.holdings.length; i++) {
let coin = this.holdings[i];
fetch(API_URL + coin.symbol)
.then(response => response.json())
.then(data => {
totalValue += data[0].price_usd * coin.amount;
});
}
return totalValue;
}
// Set an alert for a specific coin
setAlert(symbol, price, alertType) {
if (alertType !== "price" && alertType !== "percentage") {
console.log("Invalid alert type. Please use 'price' or 'percentage'.");
return;
}
let coin = this.holdings.find(holding => holding.symbol === symbol);
if (!coin) {
console.log("Coin not found in portfolio.");
return;
}
let alert = {
symbol: symbol,
alertType: alertType,
alertPrice: price
};
coin.alert = alert;
this.storeHoldings();
}
// Remove an alert for a specific coin
removeAlert(symbol) {
let coin = this.holdings.find(holding => holding.symbol === symbol);
if (!coin) {
console.log("Coin not found in portfolio.");
return;
}
if (!coin.alert) {
console.log("Coin does not have an alert set.");
return;
}
delete coin.alert;
this.storeHoldings();
}
// Check alerts and notify user
checkAlerts() {
for (let i = 0; i < this.holdings.length; i++) { let coin = this.holdings[i];
if (coin.alert) {
fetch(API_URL + coin.symbol)
.then(response => response.json())
.then(data => {
let currentPrice = data[0].price_usd;
if (coin.alert.alertType === "price" && currentPrice >= coin.alert.alertPrice) {
alert(`Coin ${coin.symbol} has reached ${coin.alert.alertPrice}`);
} else if (coin.alert.alertType === "percentage") {
let percentageChange = ((currentPrice - coin.alert.alertPrice) / coin.alert.alertPrice) * 100;
if (percentageChange >= 0) {
alert(`Coin ${coin.symbol} has increased by ${percentageChange}%`);
} else {
alert(`Coin ${coin.symbol} has decreased by ${percentageChange}%`);
}
}
});
}
}
// Initialize the portfolio object and retrieve any stored holdings
let portfolio = new Portfolio();
portfolio.retrieveHoldings();
// Example usage:
// Add a holding of 1 Bitcoin to the portfolio
portfolio.addHolding("bitcoin", 1);
// Set an alert for when Bitcoin reaches $50,000
portfolio.setAlert("bitcoin", 50000, "price");
// Remove the alert for Bitcoin
portfolio.removeAlert("bitcoin");
// Check the current value of the portfolio
console.log(`Total portfolio value: ${portfolio.getValue()}`);
// Check alerts and notify user
portfolio.checkAlerts();
class Portfolio {
constructor() {
this.holdings = [];
this.API_URL = 'https://api.coinmarketcap.com/v1/ticker/';
}
addHolding(symbol, amount) {
// code to add a holding to the portfolio
}
removeHolding(symbol) {
// code to remove a holding from the portfolio
}
setAlert(symbol, alertPrice, alertType) {
// code to set an alert for a holding
}
removeAlert(symbol) {
// code to remove an alert for a holding
}
retrieveHoldings() {
// code to retrieve stored holdings from a database or local storage
}
getValue() {
// code to calculate the total value of the portfolio
}
checkAlerts() {
// code to check alerts and notify the user
}
}
class Portfolio {
constructor() {
this.holdings = [];
this.API_URL = 'https://api.coinmarketcap.com/v1/ticker/';
}
addHolding(symbol, amount) {
if (!symbol || !amount) {
alert("Please enter a valid symbol and amount.");
return;
}
if (isNaN(amount) || amount <= 0) {
alert("Please enter a valid number for the amount.");
return;
}
// code to add a holding to the portfolio
}
removeHolding(symbol) {
if (!symbol) {
alert("Please enter a valid symbol.");
return;
}
// code to remove a holding from the portfolio
}
setAlert(symbol, alertPrice, alertType) {
if (!symbol || !alertPrice || !alertType) {
alert("Please enter a valid symbol, price, and alert type.");
return;
}
if (isNaN(alertPrice) || alertPrice <= 0) {
alert("Please enter a valid number for the alert price.");
return;
}
if (alertType !== "price" && alertType !== "percentage") {
alert("Please enter a valid alert type (price or percentage).");
return;
}
// code to set an alert for a holding
}
removeAlert(symbol) {
if (!symbol) {
alert("Please enter a valid symbol.");
return;
}
// code to remove an alert for a holding
}
retrieveHoldings() {
// code to retrieve stored holdings from a database or local storage
}
getValue() {
// code to calculate the total value of the portfolio
}
checkAlerts() {
// code to check alerts and notify the user
}
}
class Portfolio {
constructor() {
this.holdings = [];
this.API_URL = "https://api.coinmarketcap.com/v1/ticker/";
}
// Function to add a holding to the portfolio
addHolding(symbol, amount) {
// Validate the symbol and amount input
if (!symbol || !amount) {
throw new Error("Please provide a valid symbol and amount.");
}
if (typeof symbol !== "string") {
throw new Error("Symbol must be a string.");
}
if (typeof amount !== "number") {
throw new Error("Amount must be a number.");
}
// Retrieve the current price of the coin from the API
fetch(this.API_URL + symbol)
.then(response => response.json())
.then(data => {
let currentPrice = data[0].price_usd;
this.holdings.push({ symbol: symbol, amount: amount, price: currentPrice });
})
.catch(error => {
throw new Error("Error retrieving coin data from API: " + error);
});
}
// Other functions (e.g. setAlert, removeAlert, checkAlerts, etc.)...
}
// Example usage:
try {
let portfolio = new Portfolio();
portfolio.addHolding("bitcoin", 1);
console.log(portfolio.holdings);
} catch (error) {
console.error(error);
}
class WalletIntegration {
constructor() {
this.wallets = {};
}
// Add a new wallet to the list of supported wallets
addWallet(name, apiKey) {
this.wallets[name] = apiKey;
}
// Remove a wallet from the list of supported wallets
removeWallet(name) {
delete this.wallets[name];
}
// Get the total value of all holdings in a specific wallet
getWalletValue(name) {
let value = 0;
if (this.wallets[name]) {
// Fetch the current balance of the wallet from the API
fetch(WALLET_API_URL + this.wallets[name])
.then(response => response.json())
.then(data => {
data.forEach(coin => {
value += coin.amount * coin.price_usd;
});
})
.catch(error => {
throw new Error("Error retrieving wallet data from API: " + error);
});
} else {
throw new Error("Wallet not found: " + name);
}
return value;
}
}
let walletIntegration = new WalletIntegration();
// Example usage:
// Add a new wallet "My Wallet" with API key "abcdefg123456"
walletIntegration.addWallet("My Wallet", "abcdefg123456");
// Remove the "My Wallet" from the list of supported wallets
walletIntegration.removeWallet("My Wallet");
// Get the total value of all holdings in "My Wallet"
let walletValue = walletIntegration.getWalletValue("My Wallet");
console.log(Total value of holdings in My Wallet: ${walletValue});
class Portfolio {
constructor() {
this.holdings = [];
this.historicalData = {};
}
// ... other functions ...
retrieveHistoricalData(symbol, startDate, endDate) {
// Validate input
if (!symbol || !startDate || !endDate) {
throw new Error("Missing symbol, start date, or end date for historical data retrieval");
}
// Retrieve historical data from API
fetch(`${API_URL}/historical/${symbol}?start=${startDate}&end=${endDate}`)
.then(response => response.json())
.then(data => {
this.historicalData[symbol] = data;
})
.catch(error => {
throw new Error("Error retrieving historical data from API: " + error);
});
}
analyzeHistoricalData(symbol) {
// Validate input
if (!symbol || !this.historicalData[symbol]) {
throw new Error("Missing symbol or historical data for analysis");
}
// Perform analysis on historical data
let data = this.historicalData[symbol];
let maxPrice = Math.max(...data.map(d => d.price_usd));
let minPrice = Math.min(...data.map(d => d.price_usd));
let averagePrice = data.reduce((a, b) => a + b.price_usd, 0) / data.length;
console.log(`Historical analysis for ${symbol}:`);
console.log(`- Maximum price: $${maxPrice}`);
console.log(`- Minimum price: $${minPrice}`);
console.log(`- Average price: $${averagePrice}`);
}
}
// Example usage:
// Initialize the portfolio object
let portfolio = new Portfolio();
// Retrieve historical data for Bitcoin from January 1, 2020 to December 31, 2020
portfolio.retrieveHistoricalData("bitcoin", "2020-01-01", "2020-12-31");
// Analyze the historical data for Bitcoin
portfolio.analyzeHistoricalData("bitcoin");
class CCE {
constructor() {
this.alerts = {};
}
subscribeToAlerts(coin) {
if (!this.alerts[coin]) {
this.alerts[coin] = [];
}
fetch(NEWS_API_URL + coin)
.then(response => response.json())
.then(data => {
this.alerts[coin] = data;
})
.catch(error => {
console.log("Error subscribing to alerts for " + coin + ": " + error);
});
}
unsubscribeToAlerts(coin) {
if (this.alerts[coin]) {
delete this.alerts[coin];
}
}
getAlerts() {
return this.alerts;
}
}
// Example usage:
// Create an instance of the CCE class
let cce = new CCE();
// Subscribe to alerts for Bitcoin
cce.subscribeToAlerts("bitcoin");
// Unsubscribe from alerts for Bitcoin
cce.unsubscribeToAlerts("bitcoin");
// Get the current alerts
console.log(cce.getAlerts());
class Portfolio {
constructor() {
this.exchanges = {};
}
addExchange(exchangeName, apiKey) {
this.exchanges[exchangeName] = new Exchange(exchangeName, apiKey);
}
removeExchange(exchangeName) {
delete this.exchanges[exchangeName];
}
getExchange(exchangeName) {
return this.exchanges[exchangeName];
}
}
class Exchange {
constructor(exchangeName, apiKey) {
this.exchangeName = exchangeName;
this.apiKey = apiKey;
}
getHoldings() {
// Use the exchange's API to retrieve the user's holdings
// with the provided apiKey
}
placeOrder(symbol, amount, type) {
// Use the exchange's API to place a buy or sell order for the specified symbol and amount
// with the provided apiKey
}
}
// Initialize the portfolio object and add an exchange
let portfolio = new Portfolio();
portfolio.addExchange("Binance", "API_KEY");
portfolio.addExchange("Coinbase", "API_KEY");
// Retrieve holdings from the Binance exchange
let binanceHoldings = portfolio.getExchange("Binance").getHoldings();
console.log(binanceHoldings);
// Place a buy order for 0.1 BTC on Coinbase
portfolio.getExchange("Coinbase").placeOrder("BTC", 0.1, "buy");
class CCE {
constructor() {
this.settings = {
theme: "light",
coinList: ["BTC", "ETH", "XRP"],
sortBy: "price",
sortOrder: "asc"
}
this.portfolio = {};
this.alerts = [];
this.news = [];
}
renderDashboard() {
// code to display the dashboard with portfolio, news and alerts
}
renderTable() {
// code to display the sortable table of coins
}
renderCoinView(symbol) {
// code to display detailed information for a specific coin
}
handleSettingsChange(event) {
// code to handle changes to the settings object
}
handleAlertSubmit(event) {
// code to handle the submission of a new alert
}
handleAlertDelete(id) {
// code to handle the deletion of an alert
}
fetchNews() {
// code to retrieve the latest crypto-related news
}
}
let cce = new CCE();
cce.renderDashboard();
import pandas as pd
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
# Collect and prepare data
data = pd.read_csv("crypto_data.csv")
X = data[['btc_market_price', 'btc_total_bitcoins', 'btc_market_cap']]
y = data['btc_trade_volume']
# Split data into training and test sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=0)
# Train the model
regressor = LinearRegression()
regressor.fit(X_train, y_train)
# Make predictions on test data
y_pred = regressor.predict(X_test)
# Evaluate model performance
score = regressor.score(X_test, y_test)
print("Model R^2 score:", score)