Skip to content

Commit

Permalink
version 0.2.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
marek committed May 8, 2013
1 parent 7b75c55 commit 35b866a
Show file tree
Hide file tree
Showing 16 changed files with 2,376 additions and 33 deletions.
19 changes: 17 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,27 @@ constants in file background.js:
**btcOffset** - amount of BTC that shouldn't be touched by trade (all amount above that will be used)

**btcFiat** - replace with Your currency

**hrInterval** - number of seconds between "ticks" (ie 3600 - one hour)

**bidWithLastPrice** - bid with last price rather than market price


Installation:
---

1. Copy files from github to Your local storage.
2. Configure background.js according to above specs
3. Run Chrome and goto "chrome://extensions/" url
4. Click on "Read extension without package" and choose Your local folder
4. Click on "Read extension without package" and choose Your local folder


Changes:
---

0.2.0.2
- added chart with trends (a link from popup near balance)
- added **hrInterval**
- option to bid with last price rather than market price ()
- different thresholds buy/sell
- other minor fixes
33 changes: 20 additions & 13 deletions background.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
const MaxHoursToKeep = 144;
const btcOffset = 3.2; // this amount will be untouched by trade - bot will play with the rest
const btcFiat = 'PLN'; // change this to Your currency
const btcFiat = 'USD'; // change this to Your currency
const hrInterval = 1800;// interval as number of seconds (ie 3600 - 1 hour)
const bidWithLastPrice = false; // use last price to bid rather than market one

var ApiKey = localStorage.ApiKey || '';
var ApiSec = localStorage.ApiSec || '';

var EmaShortPar = parseInt(localStorage.EmaShortPar || 10);
var EmaLongPar = parseInt(localStorage.EmaLongPar || 21);
var MaxHoursBack = parseInt(localStorage.MaxHoursBack || MaxHoursToKeep);
var MinThreshold = parseFloat(localStorage.MinThreshold || 0.25);
var MinThresholdBuy = parseFloat(localStorage.MinThresholdBuy || 0.25);
var MinThresholdSell = parseFloat(localStorage.MinThresholdSell || 0.25);
var LogLines = parseInt(localStorage.LogLines || 12);

var BTC, USD;
Expand Down Expand Up @@ -64,7 +67,7 @@ function update() {
console.log(e)
chrome.browserAction.setTitle({title: e.toString() });
}
schedupdate(15*60*1000) // Update balance every 15 minutes
schedupdate(5*60*1000) // Update balance every 5 minutes
}
)
}
Expand Down Expand Up @@ -148,23 +151,27 @@ function refreshEMA(reset) {
var dp, dif = getemadif(H1.length-1)
chrome.browserAction.setBadgeText({text: Math.abs(dif).toFixed(2)})

if (dif>MinThreshold) {
if (dif>MinThresholdBuy) {
chrome.browserAction.setBadgeBackgroundColor({color:[0, 128, 0, 200]})
if (USD>=0.01) {
if (getemadif(H1.length-1) > MinThreshold) {
console.log("BUY!!!")
mtgoxpost("buyBTC.php", ['Currency='+btcFiat,'amount=1000'], one, onl)
if (getemadif(H1.length-1) > MinThresholdBuy) {
console.log("BUY!!!");
var inf = ['Currency='+btcFiat,'amount=1000'];
if (bidWithLastPrice) inf.push('price='+H1[H1.length-1].toString());
mtgoxpost("buyBTC.php", inf, one, onl)
}
} else {
console.log("No "+btcFiat+" to exec up-trend")
}
} else if (dif<-MinThreshold) {
} else if (dif<-MinThresholdSell) {
chrome.browserAction.setBadgeBackgroundColor({color:[128, 0, 0, 200]})
if (BTC>=btcOffset) {
var s = BTC - btcOffset;
if (getemadif(H1.length-1) < -MinThreshold) {
if (getemadif(H1.length-1) < -MinThresholdSell) {
console.log("SELL!!!")
mtgoxpost("sellBTC.php", ['Currency='+btcFiat,'amount='+s.toString()], one, onl)
var inf = ['Currency='+btcFiat,'amount='+s.toString()];
if (bidWithLastPrice) inf.push('price='+H1[H1.length-1].toString());
mtgoxpost("sellBTC.php", inf , one, onl)
}
} else {
console.log("No BTC to exec down-trend")
Expand All @@ -185,7 +192,7 @@ function updateH1() {
}
updateinprogress = true

var hour_fetch, hour_now = parseInt( (new Date()).getTime() / 3600000 )
var hour_fetch, hour_now = parseInt( (new Date()).getTime() / (hrInterval*1000) )
if (tim.length>0) {
hour_fetch = tim[tim.length-1] + 1
if (hour_fetch > hour_now) {
Expand All @@ -199,7 +206,7 @@ function updateH1() {

var req = new XMLHttpRequest()

var url = "https://data.mtgox.com/api/0/data/getTrades.php?Currency="+btcFiat+"&since="+(hour_fetch*3600*1000000).toString()
var url = "https://data.mtgox.com/api/0/data/getTrades.php?Currency="+btcFiat+"&since="+(hour_fetch*hrInterval*1000000).toString()

req.onerror = function(e) {
console.log("getTrades error", e, "-repeat")
Expand All @@ -223,7 +230,7 @@ function updateH1() {
H1.push(f)
hour_fetch++
if (hour_fetch <= hour_now) {
url = "https://data.mtgox.com/api/0/data/getTrades.php?Currency="+btcFiat+"&since="+(hour_fetch*3600*1000000).toString()
url = "https://data.mtgox.com/api/0/data/getTrades.php?Currency="+btcFiat+"&since="+(hour_fetch*hrInterval*1000000).toString()
get_url(req, url)
done = false
if (bootstrap) {
Expand Down
35 changes: 35 additions & 0 deletions chart.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>
Chart Performance Example - HTML5 jQuery Chart Plugin by jqChart
</title>
<link rel="stylesheet" type="text/css" href="css/jquery.jqChart.css" />
<link rel="stylesheet" type="text/css" href="css/jquery.jqRangeSlider.css" />
<link rel="stylesheet" type="text/css" href="css/jquery-ui-1.8.20.css" />
<script src="js/jquery-1.7.2.min.js" type="text/javascript"></script>
<script src="js/jquery.jqChart.min.js" type="text/javascript"></script>
<script src="js/jquery.jqRangeSlider.min.js" type="text/javascript"></script>
<!--[if IE]><script lang="javascript" type="text/javascript" src="js/excanvas.js"></script><![endif]-->

<script src="js/chart.js" type="text/javascript"></script>


</head>
<body>
<div>
<div id="jqChart" style="width: 780px; height: 280px;">
</div>
</div>
<!--div>
<form>
<select id="source">
<option value="gox">MtGox</option>
<option value="vcx">Vircurex</option>
</select>
<a href="#" id="formHref">show</a>
</form>
</div-->

</body>
</html>
Loading

0 comments on commit 35b866a

Please sign in to comment.