-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathorder_future.php
85 lines (56 loc) · 2.08 KB
/
order_future.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
<?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
$symbol = $_GET['future_symbol'];
$quantity = $_GET['lot_size'];
$s = $_GET['s'];
$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
$final_amount = round($last_price, 1);
$date = date('d-m-Y');
//Place Order
$end_point = "https://api.kite.trade/orders/regular";
$res = $client->request('POST', $end_point, [
'form_params' => [
'tradingsymbol' => $symbol,
'exchange' => 'NFO',
'transaction_type' => "BUY",
'order_type' => 'MARKET',
'quantity' => $quantity,
'price' => $final_amount,
'product' => 'NRML',
'validity' => 'DAY'
]
]);
$response = $res->getBody()->getContents();
$response = (json_decode($response,true));
//Fetching order id
$order_id = $response['data']['order_id'];
//Fetch Average 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
$price = $response['data'][$length]['average_price'];
//Update for AMO
$query = "INSERT INTO futureAmo(symbol, order_id, quanity, price, created_date) VALUES ('$symbol','$order_id','$quantity','$price','$date')";
$result = mysqli_query($GLOBALS['mysqlConnect'],$query);
header("location:stock_future_orders.php?s=$s");
exit;
?>