-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathresistance_monitor.php
107 lines (63 loc) · 2.25 KB
/
resistance_monitor.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
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
<?php
//including common files
require_once './include/common.php';
require_once './template/header.php';
$headers = [
'Content-Type' => 'application/json',
'X-Kite-Version' => '3',
'Authorization' => 'token '.KEY.':'.TOKEN
];
$client = new GuzzleHttp\Client([
'headers' => $headers
]);
$date = date('d-m-Y');
//Getting all stocks
$query = "SELECT `cSymbol`,`resistance_value`,`grow`, `resistance_signal`,`id`,`isWatch` from stocklistbackup";
$result = mysqli_query($GLOBALS['mysqlConnect'],$query);
$row = mysqli_fetch_all($result);
$i = 1;
//Concating all stocks at onces
foreach ($row as $record) {
$api_symbol = $record[0];
if (str_contains($api_symbol, "&")) {
$api_symbol = str_replace("&", "%26", $api_symbol);
}
$all_stocks[] = "i=NSE:" . $api_symbol;
}
//Got all data from kite instruments
$all_stocks = implode("&",$all_stocks);
$end_point = "https://api.kite.trade/quote?$all_stocks";
$res = $client->request('GET', $end_point);
$response = $res->getBody()->getContents();
$response = (json_decode($response, true));
//Updating in Database
foreach ($row as $record) {
$api_symbol = $record[0];
$support_value = $record[1];
$grow = $record[2];
$support_signal = $record[3];
$id = $record[4];
$watch_status = $record[5];
if(str_contains($api_symbol,"%26")) {
$api_symbol = str_replace("%26", "&", $api_symbol);
}
$close = $response['data']["NSE:$api_symbol"]['last_price'];
$last_price = str_replace(",", "", $close);
if(!is_null($support_value) || !empty($support_value)) {
if ( ($last_price >= $support_value) || ($support_signal == 1) ) {
$match[$i]['cSymbol'] = $api_symbol;
$match[$i]['last_price'] = $last_price;
$match[$i]['support_value'] = $support_value;
$match[$i]['grow'] = $grow;
$match[$i]['id'] = $id;
$match[$i]['isWatch'] = $watch_status;
$query = "UPDATE `stocklistbackup` SET `resistance_signal`='1' WHERE `cSymbol` = '$api_symbol'";
$result = mysqli_query($GLOBALS['mysqlConnect'],$query);
}
}
$i++;
}
//Rending to tbl file
$smarty->assign("datas",$match);
$smarty->display("resistance_monitor.tpl");
?>