iamravisankar

tt

Aug 28th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.19 KB | None | 0 0
  1.  
  2. <?php
  3. date_default_timezone_set("Asia/Kolkata");
  4. //if( (date('H') >= 10) && (date('H') < 15) ){
  5. if ( time() > strtotime( '08:30AM' ) && time() < strtotime( '03:25PM' ) ) {
  6. $servername = "localhost";
  7. $username = "root";
  8. $password = "ravi";
  9. $dbname = "kite";
  10. $name=$_GET['stock'];
  11. // Create connection
  12. $conn = mysqli_connect($servername, $username, $password, $dbname);
  13. // Check connection
  14. if (!$conn) {
  15. die("Connection failed: " . mysqli_connect_error());
  16. }
  17.  
  18. $sql = "SELECT * FROM minute WHERE name= '$name' ORDER BY id DESC LIMIT 0 , 1";
  19. $result = mysqli_query($conn, $sql);
  20.  
  21. if (mysqli_num_rows($result) > 0) {
  22. // output data of each row
  23. while($row = mysqli_fetch_assoc($result)) {
  24.  
  25. $old=$row["ratio"];
  26.  
  27. }
  28. } else {
  29. echo "no results";
  30. }
  31.  
  32.  
  33. mysqli_close($conn);
  34.  
  35. $servername = "localhost";
  36. $username = "root";
  37. $password = "ravi";
  38. $dbname = "kite";
  39. $name=$_GET['stock'];
  40. // Create connection
  41. $conn = mysqli_connect($servername, $username, $password, $dbname);
  42. // Check connection
  43. if (!$conn) {
  44. die("Connection failed: " . mysqli_connect_error());
  45. }
  46.  
  47. $sql = "SELECT * FROM minute WHERE name= '$name' ORDER BY id DESC LIMIT 0 , 1";
  48. $result = mysqli_query($conn, $sql);
  49.  
  50. if (mysqli_num_rows($result) > 0) {
  51. // output data of each row
  52. while($row = mysqli_fetch_assoc($result)) {
  53.  
  54. $oldpos=$row["pos"];
  55. echo $oldpos;
  56. }
  57. } else {
  58. echo "no results";
  59. }
  60.  
  61.  
  62. mysqli_close($conn);
  63.  
  64. include 'token.php';
  65. $market=$_GET['market'];
  66. $name=$_GET['stock'];
  67.  
  68.  
  69.  
  70. $json = file_get_contents("https://api.kite.trade/instruments/$market/$name?api_key=$api_key&access_token=$access_token");
  71.  
  72.  
  73. //echo $json;
  74. $tt=json_decode($json);
  75. var_dump(json_decode($json, true));
  76.  
  77. //data
  78. echo "<br>lp" . $last_price=$tt->data->last_price;
  79. echo "<br>change pr " . $change_percent=$tt->data->change_percent;
  80. echo "<br>change " . $change=$tt->data->change;
  81. echo "<br>volume" . $volume=$tt->data->volume;
  82. echo "<br>buy_quantity" .$buy_quantity=$tt->data->buy_quantity;
  83. echo "<br>sell_quantity" .$sell_quantity=$tt->data->sell_quantity;
  84. echo "<br>open_interest" .$open_interest=$tt->data->open_interest;
  85. echo "<br>last_quantity" .$last_quantity=$tt->data->last_quantity;
  86. echo "<br>last_time" .$last_time=$tt->data->last_time;
  87.  
  88.  
  89. //ohlc
  90.  
  91. echo "<br>open" . $open=$tt->data->ohlc->open;
  92. echo "<br>high" . $high=$tt->data->ohlc->high;
  93. echo "<br>low" . $low=$tt->data->ohlc->low;
  94. echo "<br>cose" . $close=$tt->data->ohlc->close;
  95. //depth
  96. //buy
  97.  
  98.  
  99. echo "<br>buy 0";
  100. echo "<br>price" . $b0price=$tt->data->depth->buy[0]->price;
  101. echo "<br>order" . $b0order=$tt->data->depth->buy[0]->orders;
  102. echo "<br>quantity" . $b0quantity=$tt->data->depth->buy[0]->quantity;
  103.  
  104.  
  105. echo "<br>buy 1";
  106. echo "<br>price" . $b1price=$tt->data->depth->buy[1]->price;
  107. echo "<br>order" . $b1order=$tt->data->depth->buy[1]->orders;
  108. echo "<br>quantity" . $b1quantity=$tt->data->depth->buy[1]->quantity;
  109.  
  110.  
  111.  
  112. echo "<br>buy 2";
  113. echo "<br>price" . $b2price=$tt->data->depth->buy[2]->price;
  114. echo "<br>order" . $b2order=$tt->data->depth->buy[2]->orders;
  115. echo "<br>quantity" . $b2quantity=$tt->data->depth->buy[2]->quantity;
  116.  
  117.  
  118. echo "<br>buy 3";
  119. echo "<br>price" . $b3price=$tt->data->depth->buy[3]->price;
  120. echo "<br>order" . $b3order=$tt->data->depth->buy[3]->orders;
  121. echo "<br>quantity" . $b3quantity=$tt->data->depth->buy[3]->quantity;
  122.  
  123. echo "<br>buy 4";
  124. echo "<br>price" . $b4price=$tt->data->depth->buy[4]->price;
  125. echo "<br>order" . $b4order=$tt->data->depth->buy[4]->orders;
  126. echo "<br>quantity" . $b4quantity=$tt->data->depth->buy[4]->quantity;
  127.  
  128.  
  129.  
  130. //sell
  131. echo "<br>sell 0";
  132. echo "<br>price" . $s0price=$tt->data->depth->sell[0]->price;
  133. echo "<br>order" . $s0order=$tt->data->depth->sell[0]->orders;
  134. echo "<br>quantity" . $s0quantity=$tt->data->depth->sell[0]->quantity;
  135.  
  136.  
  137.  
  138. echo "<br>sell 1";
  139. echo "<br>price" . $s1price=$tt->data->depth->sell[1]->price;
  140. echo "<br>order" . $s1order=$tt->data->depth->sell[1]->orders;
  141. echo "<br>quantity" . $s1quantity=$tt->data->depth->sell[1]->quantity;
  142.  
  143.  
  144.  
  145. echo "<br>sell 2";
  146. echo "<br>price" . $s2price=$tt->data->depth->sell[2]->price;
  147. echo "<br>order" . $s2order=$tt->data->depth->sell[2]->orders;
  148. echo "<br>quantity" . $s2quantity=$tt->data->depth->sell[2]->quantity;
  149.  
  150.  
  151. echo "<br>sell 3";
  152. echo "<br>price" . $s3price=$tt->data->depth->sell[3]->price;
  153. echo "<br>order" . $s3order=$tt->data->depth->sell[3]->orders;
  154. echo "<br>quantity" . $s3quantity=$tt->data->depth->sell[3]->quantity;
  155.  
  156. echo "<br>sell 4";
  157. echo "<br>price" . $s4price=$tt->data->depth->sell[4]->price;
  158. echo "<br>order" . $s4order=$tt->data->depth->sell[4]->orders;
  159. echo "<br>quantity" . $s4quantity=$tt->data->depth->sell[4]->quantity;
  160.  
  161. if ( time() > strtotime( '09:35AM' ) && time() < strtotime( '03:20PM' ) ) {
  162. if (strpos($tt->status, 'success') !== false) {
  163.  
  164.  
  165. $ratio=round($buy_quantity/$sell_quantity,2);
  166. //$ratio=3;
  167. $diff=$ratio-$old;
  168.  
  169. $action=none;
  170. if($diff>=0){
  171. $pos=$oldpos+$diff;
  172. //$pos=10;
  173. if($pos>0.19){
  174.  
  175.  
  176. if($b0price/$s0price>1.4){
  177. if($s0price<10){
  178. $sellnow=$s0price+0.05;
  179. }
  180. if($s0price<20 && $s0price>10){
  181. $sellnow=$s0price+0.15;
  182. }
  183. if($s0price<30 && $s0price>20){
  184. $sellnow=$s0price+0.30;
  185. }
  186.  
  187. //buy($s0price);
  188. $action=$s0price;
  189. $req = curl_init();
  190. curl_setopt($req, CURLOPT_URL,"http://ec2-18-220-209-112.us-east-2.compute.amazonaws.com/buysell.php?n=$name&m=$market&t=BUY&ml=LIMIT&qn=1&p=$b0price");
  191. curl_exec($req);
  192. sleep(5);
  193. $req = curl_init();
  194. curl_setopt($req, CURLOPT_URL,"http://ec2-18-220-209-112.us-east-2.compute.amazonaws.com/buysell.php?n=$name&m=$market&t=SELL&ml=LIMIT&qn=1&p=$sellnow");
  195. curl_exec($req);
  196.  
  197. $pos=0;
  198. }
  199. else{
  200. $sellnow=$s0price+0.05;
  201. //buy($b0price);
  202. $action=$b0price;
  203. $req = curl_init();
  204. curl_setopt($req, CURLOPT_URL,"http://ec2-18-220-209-112.us-east-2.compute.amazonaws.com/buysell.php?n=$name&m=$market&t=BUY&ml=MARKET&qn=1&p=$b0price");
  205. curl_exec($req);
  206. sleep(5);
  207. $req = curl_init();
  208. curl_setopt($req, CURLOPT_URL,"http://ec2-18-220-209-112.us-east-2.compute.amazonaws.com/buysell.php?n=$name&m=$market&t=SELL&ml=LIMIT&qn=1&p=$sellnow");
  209. curl_exec($req);
  210. $pos=0;
  211. }
  212.  
  213.  
  214. }
  215. }
  216. elseif($diff<0){
  217. $pos=0;
  218. }
  219.  
  220.  
  221. }
  222.  
  223. }
  224.  
  225. //database
  226.  
  227. $servername = "localhost";
  228. $username = "root";
  229. $password = "ravi";
  230. $dbname = "kite";
  231.  
  232.  
  233. // Create connection
  234. $conn = mysqli_connect($servername, $username, $password, $dbname);
  235. // Check connection
  236. if (!$conn) {
  237. die("Connection failed: " . mysqli_connect_error());
  238. }
  239.  
  240. $sql = "INSERT INTO minute(ratio,pos,difference,action,last_price,buy_quantity,sell_quantity,name,b0price,s0price)
  241. VALUES ('$ratio','$pos','$diff','$action','$last_price','$buy_quantity','$sell_quantity','$name','$b0price','$s0price')";
  242.  
  243. if (mysqli_query($conn, $sql)) {
  244. echo "New record created successfully";
  245. echo $old;
  246.  
  247. } else {
  248. echo "Error: " . $sql . "<br>" . mysqli_error($conn);
  249. }
  250.  
  251. mysqli_close($conn);
  252.  
  253. }
  254.  
  255.  
  256. else{
  257. echo "market closed";
  258. }
  259.  
  260.  
  261.  
  262. ?>
Add Comment
Please, Sign In to add comment