-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfetch_stock_future_price.php
88 lines (54 loc) · 2.35 KB
/
fetch_stock_future_price.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
<?php
require_once './include/common.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');
$delete_query = "DELETE FROM stockvaluesbackupfutures WHERE `createdDate` = '$date'";
$delete_result = mysqli_query($GLOBALS['mysqlConnect'],$delete_query);
$query = "Select id,cSymbol from stocklistbackupfutures";
$result = mysqli_query($GLOBALS['mysqlConnect'],$query);
$data = mysqli_fetch_all($result, MYSQLI_ASSOC);
// Read and output the remaining rows
foreach ($data as $value) {
$sid = $value['id'];
$api_symbol = $value['cSymbol'];
$end_point = "https://api.kite.trade/quote?i=NFO:$api_symbol";
$res = $client->request('GET', $end_point);
$response = $res->getBody()->getContents();
$response = (json_decode($response,true));
$fetch = $response['data']["NFO:$api_symbol"]["ohlc"];
$open = $fetch['open'];
$open = str_replace(",","",$open);
$low = $fetch['low'];
$low = str_replace(",","",$low);
$high = $fetch['high'];
$high = str_replace(",","",$high);
$close = $response['data']["NFO:$api_symbol"]['last_price'];
$close = str_replace(",","",$close);
$prev_close = $fetch['close'];
$prev_close = str_replace(",","",$prev_close);
$volume = $response['data']["NFO:$api_symbol"]['volume'];
echo $volume." => Volume";
echo "\n";
$alllow = 0;
$allhigh = 0;
$value = 0;
$chng_percentage = 0;
$chng = $close - $prev_close ;
$chng = number_format($chng,1);
$query = "INSERT INTO stockvaluesbackupfutures(sid, open, high, allHigh, low, allLow, close, schange, schangePercent, volume, stockvaluesbackup, addClear, createdDate)
VALUES ('$sid','$open','$high','$allhigh','$low','$alllow','$close','$chng','$chng_percentage','$volume','$value',2,'$date')";
$result = mysqli_query($GLOBALS['mysqlConnect'],$query);
$query = "UPDATE stocklistbackupfutures SET current_volume='$volume' WHERE id = '$sid'";
$result = mysqli_query($GLOBALS['mysqlConnect'],$query);
echo "$api_symbol Completed - $chng";
echo "\n";
sleep(1);
}
?>