-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbitvavo.ts
More file actions
53 lines (42 loc) · 2.01 KB
/
bitvavo.ts
File metadata and controls
53 lines (42 loc) · 2.01 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
import fs from 'fs';
import process from 'process'
import accountsData from './.accounts.bitvavo.json'
import validateAccounts from './helpers/validateAccountsBitvavo';
import { StockPosition } from './types/StockPosition'; // Assuming StockPosition type is defined in a separate file
import fetchPositionsAndOrders from './functions/bitvavo/fetchPositionsAndOrders';
process.removeAllListeners('warning')
let PORTO_LABEL = "BITVAVO PORTO";
let OUTPUT_FILE = "porto.bitvavo.pine";
let porto_positions: StockPosition[] = [];
let content = "";
let account = validateAccounts(accountsData);
let leaderboard = false;
(async () => {
const now = new Date()
// TradingView Indicator Header
content += "// @version=5 \n"
content += `indicator("${PORTO_LABEL}", "", true) \n`
content += `// Generated at ${now.toLocaleString()} \n`
content += `// Add to Pine Editor, click Add to Chart\n`
content += `// Ensure "Indicator and financials name labels" is enabled\n`
content += `// AVG = Average share price\n`
content += `\n`
let obj = await fetchPositionsAndOrders(account.APIKEY, account.APISECRET)
porto_positions.push(...obj.porto_positions)
content += obj.content
if (leaderboard) {
content += `\n\nimport MA_PT/easytable/1\n`
content += `var string json_porto = '[`
for (let pos of porto_positions) {
let posPnl = pos.pnlPercentage > 0 ? "+" + pos.pnlPercentage : pos.pnlPercentage
content += `{"ticker": "${pos.tickerId}", "value": "${pos.totalValue}_${pos.currency}", "PNL": "${posPnl}%"}, `
}
content += `]'\n`
content += `var tbl = easytable.json_to_table(json_porto)\n`
content += `easytable.change_table_style(tbl, 3, ${porto_positions.length + 1}, 3)\n`
}
fs.writeFileSync('./' + OUTPUT_FILE, content);
console.log(`[>] ${OUTPUT_FILE} written.\n`)
console.log(`[>] Now open ${OUTPUT_FILE} in: TradingView > Pine Editor, Click "Add to Chart" and open one of your positions.`)
process.exit(0)
})()