-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
129 lines (114 loc) · 3.43 KB
/
index.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
require_once __dir__.'/vendor/autoload.php';
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request;
?>
<table width="500" border="1">
<tbody>
<tr>
<th>Name</th>
<th colspan="4">CALLS</th>
<th colspan="4">PUTS</th>
</tr>
<?php $res = getByType("NIFTY"); ?>
<tr>
<td></td>
<td>Vol</td>
<td>OI</td>
<td>Status</td>
<td>Action</td>
<td>Vol</td>
<td>OI</td>
<td>Status</td>
<td>Action</td>
</tr>
<tr>
<td>NIFTY</td>
<td><?php echo $res['ce_oi']; ?></td>
<td><?php echo $res['ce_vo']; ?></td>
<td></td>
<td></td>
<td><?php echo $res['pe_oi']; ?></td>
<td><?php echo $res['pe_vo']; ?></td>
<td></td>
<td></td>
</tr>
<?php $res = getByType("FINNIFTY"); ?>
<tr>
<td>FIN-NITY</td>
<td><?php echo $res['ce_oi']; ?></td>
<td><?php echo $res['ce_vo']; ?></td>
<td></td>
<td></td>
<td><?php echo $res['pe_oi']; ?></td>
<td><?php echo $res['pe_vo']; ?></td>
<td></td>
<td></td>
</tr>
<?php $res = getByType("BANKNIFTY"); ?>
<tr>
<td>BANKNIFTY</td>
<td><?php echo $res['ce_oi']; ?></td>
<td><?php echo $res['ce_vo']; ?></td>
<td></td>
<td></td>
<td><?php echo $res['pe_oi']; ?></td>
<td><?php echo $res['pe_vo']; ?></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
<?php
function getByType($type="NIFTY"){
$option_chain_ind = "/api/option-chain-indices?symbol=".$type;
$httpClient = new \GuzzleHttp\Client([
'base_uri' => 'https://www.nseindia.com',
'defaults' => [
'exceptions' => false
]
]);
$request = new Request('GET', $option_chain_ind, [
'headers' => [
'Accept' => 'application/json'
]
]);
$response = $httpClient->send($request, [
'headers' => [
'Pragma' => 'no-cache',
'Cache-Control' => 'no-cache',
'Upgrade-Insecure-Requests' => '1',
'User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.75 Safari/537.36',
'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
'Accept-Language' => 'en-US,en;q=0.9',
'Accept-Encoding' => 'gzip, deflate, br'
]
]);
$response_body = $response->getBody();
$response_body = json_decode($response_body);
$ce_oi = 0;
$ce_vo = 0;
$pe_oi = 0;
$pe_vo = 0;
// echo '<pre>'; print_r($response_body->records->data); die;
foreach ($response_body->records->data as $key => $value) {
if(isset($value->CE->openInterest)){
$ce_oi = $ce_oi+$value->CE->openInterest;
}
if(isset($value->CE->totalTradedVolume)){
$ce_vo = $ce_vo+$value->CE->totalTradedVolume;
}
if(isset($value->PE->openInterest)){
$pe_oi = $pe_oi+$value->PE->openInterest;
}
if(isset($value->PE->totalTradedVolume)){
$pe_vo = $pe_vo+$value->PE->totalTradedVolume;
}
}
$res = ["ce_oi"=>$ce_oi, "ce_vo"=>$ce_vo, "pe_oi"=>$pe_oi, "pe_vo"=>$pe_vo];
return $res;
//echo '<pre>'; print_r($ce_vo); die;
}
?>