-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathorder_delete_execute.php
65 lines (38 loc) · 1.37 KB
/
order_delete_execute.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
<?php
require_once './include/common.php';
// setting up end headers
$headers = [
'Content-Type' => 'application/json',
'X-Kite-Version' => '3',
'Authorization' => 'token '.KEY.':'.TOKEN
];
$client = new GuzzleHttp\Client([
'headers' => $headers
]);
//Fetching stock Symbol
$order_id = $_GET['id'];
$query = "SELECT `symbol`,`price`,`quanity` FROM `stockAmo` where order_id='$order_id'";
$result = mysqli_query($GLOBALS['mysqlConnect'],$query);
$data = mysqli_fetch_row($result);
$symbol = $data[0];
$order_price = $data[1];
$quanity = $data[2];
//Get Last traded price
$end_point = "https://api.kite.trade/orders/$order_id";
$res = $client->request('GET',$end_point);
$response = $res->getBody()->getContents();
$response = (json_decode($response, true));
$length = count($response['data']);
$length = $length-1;
//Fetching average price
$average_price = $response['data'][$length]['average_price'];
$date = date('d-m-Y');
$tran_price = $average_price - $order_price;
$result_price = $quanity * $tran_price;
$query = "DELETE from stockAmo where order_id='$order_id'";
$result = mysqli_query($GLOBALS['mysqlConnect'],$query);
echo $query = "INSERT INTO `stockIncome` ( `symbol`, `amount`, `createdDate`) VALUES ('$symbol', '$result_price', '$date')";
$result = mysqli_query($GLOBALS['mysqlConnect'],$query);
header("location:stock_execution.php");
exit;
?>