Skip to content

Commit

Permalink
adding trade feed
Browse files Browse the repository at this point in the history
  • Loading branch information
neofutur committed Sep 10, 2012
1 parent 8270709 commit 8b1a733
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 14 deletions.
10 changes: 5 additions & 5 deletions lib/feedtools.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
function feedheader( $date, $ttl, $format )
function feedheader( $date, $ttl, $format, $title, $link,$description )
{
$feedheader="";
$selflink = "http://p.b.gw.gd/pricefeed/bitcoin_price_feed.php?format=".$format;
Expand All @@ -9,9 +9,9 @@ function feedheader( $date, $ttl, $format )
// $feedheader .= '<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" >';
$feedheader .= '<channel>';
$feedheader .= '<atom:link href="'.$selflink.'" rel="self" type="application/rss+xml" />';
$feedheader .= '<title>Bitcoin Price Feed</title>';
$feedheader .= '<link>http://bitcoin.gw.gd</link>';
$feedheader .= '<description>RSS feed providing the latest bitcoin price, from mtgox API, provided by http://bitcoin.gw.gd</description>';
$feedheader .= '<title>'.$title.'</title>';
$feedheader .= '<link>'.$link.'http://bitcoin.gw.gd</link>';
$feedheader .= '<description>'.$description.'</description>';
$feedheader .= '<language>en-us</language>';
$feedheader .= '<lastBuildDate>'.$date.'</lastBuildDate>';
$feedheader .= '<generator>bitcoin simple php tools</generator>';
Expand All @@ -35,7 +35,7 @@ function addfeeditem($title, $link, $description, $timestamp, $ticker )
$donations = "free service provided by http://bitcoin.gw.gd , donations welcome : 1va4sqj5AFnMYicD7JzhDfxauk5w6Uuug";
$feeditem="";
$feeditem .= "<item>";
$feeditem .= "<title>".$ticker."</title>";
$feeditem .= "<title>".$title."</title>";
$feeditem .= "<link>".$link."</link>";
$feeditem .= "<description>".$description." . ".$donations."</description>";
//<content:encoded><![CDATA[<div><font color="#141414"><span style="font-family: Georgia">Let's see here what we need to do and not do to create good articles for our readers:</span></font><br />
Expand Down
5 changes: 4 additions & 1 deletion pricefeed/bitcoin_price_feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
//addfeedimage(imageurl, imagelink,imagetitle)
//echo $format;

$link="http://bitcoin.gw.gd";
$title="bitcoin price feed";
$description="RSS feed providing the latest bitcoin price, from mtgox API, provided by http://bitcoin.gw.gd";
$rssfeed = feedheader( $date, $ttl, $format, $title, $link,$description);
// add data / RSS items
if ( $format == "short" )
{
Expand All @@ -49,7 +53,6 @@
$description="bitcoin price at date ". $date. " ";
}

$rssfeed = feedheader( $date, $ttl, $format);

$rssfeed .= addfeeditem($title, $link, $description,$timestamp, $ticker);

Expand Down
7 changes: 0 additions & 7 deletions pricefeed/getBitcoinPrice_USD.txt

This file was deleted.

1 change: 0 additions & 1 deletion pricefeed/goxrate_USD.txt

This file was deleted.

76 changes: 76 additions & 0 deletions tradefeed/bitcoin_trade_feed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php


require_once ( dirname(__FILE__) . "/../lib/feedtools.php");

header("Content-Type: application/rss+xml; charset=ISO-8859-1");

// feed parameters , currency, delay, format, image
$currency="USD"; $delay=30; $format="short";$image=false;

if ( isset( $_GET ) )
if ( isset ( $_GET['format'] ) )
if ( $_GET['format'] == "short" or $_GET['format'] == "fullticker" )
$format = $_GET['format'];

$fromcurrency="USD";

// feed date
//const string RFC822 = "D, d M y H:i:s O" ;
$sincefile=dirname(__FILE__) . "/../cache/lasttradeid_".$fromcurrency.".txt";
$since=file_get_contents($sincefile);
//echo $since; exit;
$tid=$since;

$date= date('r');
$ttl=30;
$timestamp = time();
$link="http://p.b.gw.gd/ti/miniticker.php?date=$timestamp";
$grouptrades=false;

// input rss header


//if ( $image == true )
//addfeedimage(imageurl, imagelink,imagetitle)
//echo $format;
$title="bitcoin trade feed";
$link="http://bitcoin.gw.gd";
$description="RSS feed providing the latest bitcoin trades, from mtgox API, feed updated every 30 seconds, provided by http://bitcoin.gw.gd";
$rssfeed = feedheader( $date, $ttl, $format, $title, $link,$description );

// add data / RSS items
if ( $format == "short" )
{
require_once ( dirname(__FILE__) . "/../lib/cachemtgoxtrades.php");
$trades=cachemtGoxTrades($fromcurrency="USD", $grouptrades, $since );
}


//var_dump($trades);exit;
//foreach line
foreach ( $trades as $trade )
{
$timestamp=$trade->{'date'};
$datetrade=date("Md H:i:s" );
$price=$trade->{'price'};
$amount=$trade->{'amount'};
$tid=$trade->{'tid'};
$item=$trade->{'item'};
$currency=$trade->{'price_currency'};
$title= $datetrade." mtgox ".$tid." : ". $amount. " " . $item." traded at ".$price." ".$currency;
$link="http://p.b.gw.gd/ti/miniticker.php?date=$timestamp";
$link .= "&amp;format=short";
$description="bitcoin price at date ". $date. " ";
$rssfeed .= addfeeditem($title, $link, $description,$timestamp, $price );
}
// add RSS footer
$rssfeed .= feedfooter();
//echo $tid;exit;
// update last trade_id
file_put_contents($sincefile, $tid );

// echo the full RSS feed
echo $rssfeed;

?>
8 changes: 8 additions & 0 deletions tradefeed/feedconfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

$providedbyurl="http://bitcoin.gw.gd";
$feeddescription="RSS feed providing the latest bitcoin price, from mtgox API, provided by ".$providedbyurl;
$donations="free service provided by : ".$providedbyurl." , donations welcome : 1va4sqj5AFnMYicD7JzhDfxauk5w6Uuug";
$feedownurl="http://p.b.gw.gd/pricefeed/bitcoin_price_feed.php";

?>

0 comments on commit 8b1a733

Please sign in to comment.