-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathindex.php
55 lines (50 loc) · 1.94 KB
/
index.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
<?php
//Building A Simple Bittrex Bot
$apikey='2923c158d5754c29a088c4adea5c6f34';
$apisecret='3f29b39ab1be46afb0834fe56c8e4fea';
function bittrexbalance($apikey, $apisecret){
$nonce=time();
$uri='https://bittrex.com/api/v1.1/account/getbalance?apikey='.$apikey.'¤cy=BTC&nonce='.$nonce;
$sign=hash_hmac('sha512',$uri,$apisecret);
$ch = curl_init($uri);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('apisign:'.$sign));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$execResult = curl_exec($ch);
$obj = json_decode($execResult, true);
$balance = $obj["result"]["Available"];
return $balance;
}
function bittrexbuy($apikey, $apisecret, $symbol, $quant, $rate){
$nonce=time();
$uri='https://bittrex.com/api/v1.1/market/buylimit?apikey='.$apikey.'&market=BTC-'.$symbol.'&quantity='.$quant.'&rate='.$rate.'&nonce='.$nonce;
$sign=hash_hmac('sha512',$uri,$apisecret);
$ch = curl_init($uri);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('apisign:'.$sign));
$execResult = curl_exec($ch);
$obj = json_decode($execResult, true);
return $obj;
}
//fetch top 50 cryptos by marketcap
$cnmkt = "https://api.coinmarketcap.com/v1/ticker/?limit=50";
$fgc = json_decode(file_get_contents($cnmkt), true);
$counter = 0;
for($i=0;$i<50;$i++){
if($counter < 3){
//check percentage change over last 7 days
$percCng = $fgc[$i]["percent_change_7d"];
if($percCng < 4 && $percCng > -4){
$symbol = $fgc[$i]["symbol"];
$cost = $fgc[$i]["price_btc"];
//fetch bittrex btc balance
$balance = bittrexbalance($apikey, $apisecret);
//calc 1/5th of available
$fifthBal = $balance / 5;
//calc how much coin to buy
$amounttobuy = $fifthBal / $cost;
$buy = bittrexbuy($apikey, $apisecret, $symbol, $amounttobuy, $cost);
print_r($buy);
$counter++;
}
}
}
?>