-
Notifications
You must be signed in to change notification settings - Fork 5
/
periodic.php
53 lines (38 loc) · 1.27 KB
/
periodic.php
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
<?php
/* * *
* Do not edit this unless you know what you're doing
* Do check the file config.php
*/
require_once(__DIR__ . '/config.php'); // configuration
require_once(__DIR__ . '/functions.php'); // global functions
$ch = curl_init(); // web browser
if(!checkLogin($ch)){
// login
$login = webLogin($ch);
if($login != 200)
die("login failed\n");
// get session stuff
getDegiroConfig($ch);
}
$portfolio = updatePortfolio($ch); // check what we have to sell
// portfolio checks
foreach($portfolio as $k => $p){
if($p['qtyAvail'] == 0) // skip if there are none available to sell
unset($portfolio[$k]);
}
$count = count($portfolio);
if($count < 1){
echo date('Y-m-d H:i:s') . "|nothing to sell\n";
die();
}
echo date('Y-m-d H:i:s') . "|found $count orders to check...\n";
/**** real stuff happening here ****/
foreach($portfolio as $k => $v){
$qty = $v['qtyAvail'];
$cost = $v['breakEvenPrice'];
$comission = abs($v['realizedProductPl']);
$totalCost = (float)($cost * $qty) + ($comission *2); // add another commission for the selling transaction
$trySell = $totalCost * 1.35; // 35% LUCRO
$trySell = normalizeFloat($trySell, 4); // round
trySell($ch, $v, $trySell);
}