-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathexample.php
More file actions
36 lines (28 loc) · 959 Bytes
/
example.php
File metadata and controls
36 lines (28 loc) · 959 Bytes
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
<?php
require_once('finex.php');
require_once('config.php');
$getask = json_decode(file_get_contents("https://api.bitfinex.com/v1/pubticker/BTCUSD"), true);
$ask = $getask['ask'];
$getbid = json_decode(file_get_contents("https://api.bitfinex.com/v1/pubticker/BTCUSD"), true);
$bid = $getbid['bid'];
$getavg = json_decode(file_get_contents("https://api.bitcoinaverage.com/ticker/global/USD/"), true);
$avg = $getavg['24h_avg'];
$diff = $avg - $ask;
$diff2 = $bid - $avg;
if($diff > 2){
//good time to buy
echo "24h Avg: ".$avg."<br>";
echo "Current Ask: ".$ask."<br>";
$trade = new bitfinex($api_key, $api_secret);
$buy = $trade->new_order("BTCUSD", "0.01", "1", "buy", "exchange market");
print_r($buy);
}
if($diff2 > 2){
//good time to sell
echo "24h Avg: ".$avg."<br>";
echo "Current Bid: ".$bid."<br>";
$trade = new bitfinex($api_key, $api_secret);
$sell = $trade->new_order("BTCUSD", "0.01", "1", "sell", "exchange market");
print_r($sell);
}
?>