I use json data from hitbtc.com api . I fetch my trade balance from hitbtc server using api and insert data in my mysql database using curl php.
Create database table :
id = int (3) auto_increment
currencry = varchar(20)
available = varchar(20)
reserved = varchar(20)
date = datetime
You need two file first ' index.php ' and second ' data.json '
Create data.json file and leave blank. In this file json data saved when you run your index.php file.
now create index.php file and copy given code and paste in index.php file.
<?php
$data = file_get_contents('data.json'); // http://yourdomain/data.json
$data = json_decode($data, true);
$need = array(
'DOGE',
'BTC',
'XRP',
'BSV'
);
foreach ($data as $key => $value) {
if (in_array($data[$key]['currency'], $need)) {
echo $data[$key]['currency'] . " = " . $data[$key]['available'] . " = " . $data[$key]['reserved'];
echo "<br>";
}
}
?>
<?php
$ch = curl_init('https://api.hitbtc.com/api/2/trading/balance');
curl_setopt($ch, CURLOPT_USERPWD, 'API_KEY : SECRET_KEY'); // API AND KEY
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('accept: application/json'));
$return = curl_exec($ch);
curl_close($ch);
if (time()-filemtime($url) > 10) { // file older than 20 minutes
$decode = json_decode($return, true); //getting the file content as array
$fp = fopen('0json.json', 'w');
fwrite($fp, json_encode($decode));
fclose($fp);
echo $json;
} else {
// file younger than 20 minutes
$json = file_get_contents($url);
// echo the JSON
echo $json;
}
?>
<?php
define('TIMEZONE', 'Asia/kolkata'); // change timezone as per your need
date_default_timezone_set(TIMEZONE);
?>
<div class="container box">
<h3 align="center">Import JSON File Data into Mysql Database in PHP</h3><br />
<?php
$connect = mysqli_connect("localhost", "database_username", "database_password", "database_name"); //Connect PHP to MySQL Database
$sql123 = "TRUNCATE TABLE balance ";
if ($connect->query($sql123) === TRUE) {
echo "Record updated successfully";
} else {
echo "Error updating record: " . $connect->error;
}
$query = '';
$table_data = '';
$date = Date("Y-m-d H:i:s");
foreach ($data as $key => $value) {//Extract the Array Values by using Foreach Loop
if (in_array($data[$key]['currency'], $need)) {
$query .= "INSERT INTO balance(currency, available,reserved,date) VALUES ('".$data[$key]['currency']."', '".$data[$key]['available']."','".$data[$key]['reserved']."','$date'); "; // Make Multiple Insert Query
$table_data .= '
<tr>
<td>'.$data[$key]["currency"].'</td>
<td>'.$data[$key]["available"].'</td>
<td>'.$data[$key]["reserved"].'</td>
</tr>
'; //Data for display on Web page
} }
if(mysqli_multi_query($connect, $query)) //Run Mutliple Insert Query
{
echo '<h3>Imported JSON Data</h3><br />';
echo '
<table class="table table-bordered">
<tr>
<th width="33%">Currency</th>
<th width="33%">Available</th>
<th width="33%">Reserved</th>
</tr>
';
echo $table_data;
echo '</table>';
}
?>
You can also read this page
Friday, 24 January 2020
Sunday, 19 January 2020
DOGEBTC -- DOGEETH -- ETHBTC arbitrage for hitbtc
| <html> | |
| <head> | |
| <meta http-equiv="refresh" content="30; url=#" /> | |
| <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | |
| <title>Free Arbutrage scanner for hitbtc in DOGE-ETH-BTC</title> | |
| <meta name="description" content="scan best arbitrage possibility in hitbtc for DOGE-ETH-BTC " /> | |
| </head> | |
| //bid-ask DOGEbtc price | |
| $url = "https://api.hitbtc.com/api/2/public/ticker/DOGEBTC"; | |
| $dataDOGEBTC = json_decode(file_get_contents($url), true); | |
| $symbol=$dataDOGEBTC['symbol']; | |
| $bid=$dataDOGEBTC['bid']; | |
| $ask=$dataDOGEBTC['ask']; | |
| //bid-ask DOGEeth price | |
| $url1 = "https://api.hitbtc.com/api/2/public/ticker/DOGEETH"; | |
| $dataDOGEETH = json_decode(file_get_contents($url1), true); | |
| $symbol1=$dataDOGEETH['symbol']; | |
| $bid1=$dataDOGEETH['bid']; | |
| $ask1=$dataDOGEETH['ask']; | |
| //bid-ask dogeeth price | |
| $url2 = "https://api.hitbtc.com/api/2/public/ticker/ETHBTC"; | |
| $dataETHBTC = json_decode(file_get_contents($url2), true); | |
| $symbol2=$dataETHBTC['symbol']; | |
| $bid2=$dataETHBTC['bid']; | |
| $ask2=$dataETHBTC['ask']; | |
| ?> | |
| <center>This arbitrage bot work only for DOGEBTC-DOGEETH-ETHBTC ON Hitbtc<br> | |
| This page refrash every 30 second and try to find profit if find profit more then 0.3% then place one order in each market.<br> | |
| You can also use cron for auto refrash in backgroud on cloud.<br> | |
| Default DOGE quantity 20. If have more doge you can replace quantity as per your need.<br> | |
| <table><tr><td width="30%"><h3> | |
| <?php | |
| echo "symbol : "; echo $symbol; echo "<br>"; | |
| echo "DOGEbtc bid : "; echo $bid; echo "<br>"; | |
| echo "DOGEbtc ask :"; echo $ask; echo "<br>"; | |
| ?></h3> | |
| </td><td width="30%"><h3> | |
| <?php | |
| echo "symbol : "; echo $symbol1; echo "<br>"; | |
| echo "DOGEeth bid : "; echo $bid1; echo "<br>"; | |
| echo "DOGEeth ask :"; echo $ask1; echo "<br>"; | |
| ?></h3> | |
| </td><td width="30%"><h3> | |
| <?php | |
| echo "symbol : "; echo $symbol2; echo "<br>"; | |
| echo "ethbtc bid : "; echo $bid2; echo "<br>"; | |
| echo "ethbtc ask :"; echo $ask2; echo "<br>"; | |
| ?></h3></td></tr></table> | |
| <h2>calculate now </h2><br> | |
| <table><tr><td width="50%"> column1<br> | |
| DOGEBTC -- DOGEETH -- ETHBTC <br><font size="4px"> | |
| buy 20 DOGE on ask <?php $a=$ask*20; ?><?php $a1=number_format($a,11); echo "from dogebtc "; echo $a1; ?> <br> | |
| <font color="red"> | |
| <?php $dogebtc=$a1*7/10000; $dogebtc1=number_format($dogebtc,11); $dogebtc2=$a1+$dogebtc1; $dogebtc3=number_format($dogebtc2,11); echo "fee "; echo $dogebtc1; echo " btc spend "; echo $dogebtc3; ?> BTC<br></font> | |
| sell 20 DOGE on bid <?php $b=$bid1*20; ?><?php $b1=number_format($b,9); echo "ETHDOGE after sell "; echo $b1; ?> ETH <br> | |
| <font color="red"> | |
| <?php $beth=$b1*7/10000; $beth1=number_format($beth,8); $beth2=$b1-$beth1; $beth3=number_format($beth2,8); echo "fee "; echo $beth1; echo " Received "; echo $beth3; ?> ETH<br></font> | |
| sell ETH on bid <?php $c=$beth3*$bid2; ?><?php $c1=number_format($c,11); echo "ETHBTC after sell "; echo $c1; ?> BTC<br> | |
| <font color="red"> | |
| <?php $ethbtc=$c1*7/10000; $ethbtc1=number_format($ethbtc,9); $ethbtc2=$c1-$ethbtc1; $ethbtc3=number_format($ethbtc2,8); echo "fee "; echo $ethbtc1; echo " Received "; echo $ethbtc3; ?> BTC<br></font> | |
| <font color="blue"> | |
| <?php $d=$ethbtc3-$dogebtc3; ?><?php $d1=number_format($d,11); echo "total profit with fee "; echo $d1; ?> BTC <br> | |
| <?php //$p0=$a1/100; $p01=$d1/$p0; | |
| $p0=$dogebtc3/100; $p01=$d1/$p0; echo "profit in % " ; echo $p01; ?>% BTC</font><br> | |
| <H3>Result for equation</H3><br> | |
| <?php | |
| $output=$p01; | |
| if ($output >= 0.3) { | |
| echo "<B>buy DOGEBTC -- DOGEETH -- ETHBTC</B>" ; echo"<br><br>"; | |
| echo "<B>buy 20 DOGE in BTC at </B>" ; echo "<b>";echo $ask; echo " ask price</b>"; echo"<br>"; | |
| echo "<B>sell 20 DOGE in ETH at </B>" ; echo "<b>";echo $bid1; echo " bid price</b>"; echo"<br>"; | |
| echo "<B>sell "; echo $b1 ; echo " ETH in BTC at </B>" ; echo "<b>";echo $bid2; echo " bid price </b>"; echo"<br>"; | |
| //DOGEBTC BUY | |
| $symbol = DOGEBTC; | |
| $side = buy; | |
| $type = limit; | |
| $price=$ask; | |
| $quantity=20; | |
| $timeInForce= GTC; | |
| $ch = curl_init(); | |
| //do a post | |
| curl_setopt($ch,CURLOPT_URL,"https://api.hitbtc.com/api/2/order"); | |
| curl_setopt($ch, CURLOPT_USERPWD, 'API_KEY:SECRET_KEY'); // API AND KEY | |
| curl_setopt($ch, CURLOPT_POST,1); | |
| curl_setopt($ch,CURLOPT_POSTFIELDS,"symbol=$symbol&side=$side&price=$price&quantity=$quantity&type=$type&timeInForce=$timeInForce"); | |
| curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); | |
| //return the result of curl_exec,instead | |
| //of outputting it directly | |
| curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded')); | |
| curl_setopt($ch, CURLOPT_HTTPHEADER, array('accept: application/json')); | |
| //curl_setopt($ch,CURLOPT_HTTPHEADER,$header); | |
| $result=curl_exec($ch); | |
| curl_close($ch); | |
| $result=json_decode($result); | |
| echo"<pre>"; | |
| print_r($result); | |
| //order end | |
| //sell DOGEETH | |
| $symbol1 = DOGEETH; | |
| $side1 = sell; | |
| $type1 = limit; | |
| $price1=$bid1; | |
| $quantity1=20; | |
| $timeInForce1= GTC; | |
| $ch1 = curl_init(); | |
| //do a post | |
| curl_setopt($ch1,CURLOPT_URL,"https://api.hitbtc.com/api/2/order"); | |
| curl_setopt($ch1, CURLOPT_USERPWD, 'API_KEY:SECRET_KEY'); // API AND KEY | |
| curl_setopt($ch1, CURLOPT_POST,1); | |
| curl_setopt($ch1,CURLOPT_POSTFIELDS,"symbol=$symbol1&side=$side1&price=$price1&quantity=$quantity1&type=$type1&timeInForce=$timeInForce1"); | |
| curl_setopt($ch1, CURLOPT_RETURNTRANSFER,1); | |
| //return the result of curl_exec,instead | |
| //of outputting it directly | |
| curl_setopt($ch1, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded')); | |
| curl_setopt($ch1, CURLOPT_HTTPHEADER, array('accept: application/json')); | |
| //curl_setopt($ch,CURLOPT_HTTPHEADER,$header); | |
| $result1=curl_exec($ch1); | |
| curl_close($ch1); | |
| $result1=json_decode($result1); | |
| echo"<pre>"; | |
| print_r($result1); | |
| //order end | |
| //sell ETHBTC | |
| $symbol2 = ETHBTC; | |
| $side2 = sell; | |
| $type2 = limit; | |
| $price2=$bid2; | |
| $quantity2=$beth3; | |
| $timeInForce2= GTC; | |
| $ch2 = curl_init(); | |
| //do a post | |
| curl_setopt($ch2,CURLOPT_URL,"https://api.hitbtc.com/api/2/order"); | |
| curl_setopt($ch2, CURLOPT_USERPWD, 'API_KEY:SECRET_KEY'); // API AND KEY | |
| curl_setopt($ch2, CURLOPT_POST,1); | |
| curl_setopt($ch2,CURLOPT_POSTFIELDS,"symbol=$symbol2&side=$side2&price=$price2&quantity=$quantity2&type=$type2&timeInForce=$timeInForce2"); | |
| curl_setopt($ch2, CURLOPT_RETURNTRANSFER,1); | |
| //return the result of curl_exec,instead | |
| //of outputting it directly | |
| curl_setopt($ch2, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded')); | |
| curl_setopt($ch2, CURLOPT_HTTPHEADER, array('accept: application/json')); | |
| //curl_setopt($ch,CURLOPT_HTTPHEADER,$header); | |
| $result2=curl_exec($ch2); | |
| curl_close($ch2); | |
| $result2=json_decode($result2); | |
| echo"<pre>"; | |
| print_r($result2); | |
| //order end | |
| } | |
| else // + | |
| { | |
| echo "<B>NO Arbitrage Match <br> FOR DOGEBTC -- DOGEETH -- ETHBTC</B>"; echo"<br>"; | |
| } | |
| // end DOGEBTC -- DOGEETH -- ETHBTC code | |
| ?> | |
| <br><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> | |
| <!-- achhey --> | |
| <ins class="adsbygoogle" | |
| style="display:inline-block;width:320px;height:100px" | |
| data-ad-client="ca-pub-4305348743992957" | |
| data-ad-slot="3135886125"></ins> | |
| <script> | |
| (adsbygoogle = window.adsbygoogle || []).push({}); | |
| </script> | |
| </td></tr></table> | |
| </center> |
Subscribe to:
Comments (Atom)