-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathorder_future_sell_execute.php
72 lines (41 loc) · 1.42 KB
/
order_future_sell_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
66
67
68
69
70
71
72
<?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 * from futureAmo where order_id='$order_id'";
$result = mysqli_query($GLOBALS['mysqlConnect'],$query);
$data = mysqli_fetch_assoc($result);
$symbol = $data['symbol'];
$quantity = $data['quanity'];
$end_point = "https://api.kite.trade/quote?i=NFO:$symbol";
$res = $client->request('GET', $end_point);
$response = $res->getBody()->getContents();
$response = (json_decode($response, true));
$last_price = $response['data']["NFO:$symbol"]['last_price'];
$last_price = str_replace(",", "", $last_price); //last price
//Place Order
$end_point = "https://api.kite.trade/orders/regular/$order_id";
$res = $client->request('PUT', $end_point, [
'form_params' => [
'order_type' => 'LIMIT',
'quantity' => $quantity,
'price' => $last_price,
'validity' => 'DAY'
]
]);
$response = $res->getBody()->getContents();
$response = (json_decode($response,true));
$query = "UPDATE `optionAmo` SET `target`='$last_price' WHERE order_id='$order_id'";
$result = mysqli_query($GLOBALS['mysqlConnect'],$query);
header("location:stock_futures_execution.php");
exit;
?>