-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
119 lines (98 loc) · 5.73 KB
/
main.js
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
const
DELAY = 500,
URL_LINK_PREEV = 'http://preev.com/xdg/eur',
URL_LINK_CRYPTSY = 'https://www.cryptsy.com/markets/view/132',
URL_LINK_BTCTURK = 'https://www.btcturk.com/Exchange/FastSellBtc',
URL_JSON_BTCTURK = 'https://www.btcturk.com/api/ticker',
URL_JSON_CRYPTSY = 'https://www.cryptsy.com/orders/ajaxorderslist2/132',
URL_JSON_CURRENCY = 'http://api.piyasa.com/json/?kaynak=doviz_guncel_serb',
URL_JSON_PREEV = 'http://preev.com/pulse/units:xdg+eur/sources:bter+cryptsy+bitfinex+bitstamp+btce+bter+cryptsy+kraken+localbitcoins+btce+kraken';
var timer;
var ccb = {
calculate: function () {
const values = 'div.values .text-right h3';
var ciEuro = parseFloat($('input.dcAmountInEuro').val()),
ciDoge = parseFloat($('#dcAmountInDogecoin').text());
$(values).html(' <i class="fa fa-spinner fa-spin"></i>');
if (!ciDoge || isNaN(ciDoge)) {
$(values).html(' ');
}
else {
ciDoge = ciDoge.toFixed(4);
$.getJSON(URL_JSON_PREEV, function (data) {
var btcDogeRate = parseFloat(data.xdg.btc.bter.last);
var btceEuroRate = parseFloat(data.eur.btc.btce.last);
var krakenEuroRate = parseFloat(data.eur.btc.kraken.last);
var btcEuroRate = (btceEuroRate + krakenEuroRate) / 2;
var dogeEuroRate = btcDogeRate / btcEuroRate;
var marketDoge = (ciEuro / dogeEuroRate).toFixed(4);
var marketEuro = (ciDoge * dogeEuroRate).toFixed(4);
$.getJSON(URL_JSON_CRYPTSY, function (data) {
var cryptsyBtc = 0,
satoshi = data.buy[15][0];
cryptsyBtc = (ciDoge * satoshi).toFixed(8);
cryptsyBtc -= cryptsyBtc / 100 * .25;
cryptsyBtc = cryptsyBtc.toFixed(8);
$.getJSON(URL_JSON_BTCTURK, function (data) {
var bid = data.bid;
var btcTurkTry = ((cryptsyBtc - 0.001) * bid).toFixed(4);
$.getJSON(URL_JSON_CURRENCY, function (data) {
var currEuroRate = $.grep(data, function (e) {
return e.foex == 'EUR';
})[0].sell;
var btcTurkEuro = (btcTurkTry / currEuroRate).toFixed(4);
$('div.ci-doge-amount h3').text(ciDoge);
$('div.market-doge-amount h3').html('<a href="' + URL_LINK_PREEV + '" target="_blank">' + marketDoge + '</a>');
$('div.market-euro-price h3').html('<a href="' + URL_LINK_PREEV + '" target="_blank">€ ' + marketEuro + '</a>');
$('div.cryptsy-btc-amount h3').html('<a href="' + URL_LINK_CRYPTSY + '" target="_blank">฿ ' + cryptsyBtc + '</a>');
$('div.btcturk-tl-price h3').html('<a href="' + URL_LINK_BTCTURK + '" target="_blank">₺ ' + btcTurkTry + '</a>');
$('div.btcturk-euro-price h3').html('<a href="' + URL_LINK_BTCTURK + '" target="_blank">€ ' + btcTurkEuro + '</a>');
});
});
});
});
}
},
addBox: function () {
$('div.contentpanel div.row').append('' +
'<div class="col-md-12" style="max-width: 800px;">' +
' <div class="panel panel-default">' +
' <div class="panel-heading"><p>"Amount" alanına çevrilmesini istediğiniz tutarı giriniz</p></div>' +
' <div class="panel-body">' +
' <div class="row values">' +
' <div class="col-md-7">CoIntellect\'in verdiği Doge miktarı</div>' +
' <div class="col-md-5 text-right ci-doge-amount"><h3> </h3></div>' +
' <div class="col-md-7">Aynı ödemeyle piyasada alınabilecek Doge miktarı</div>' +
' <div class="col-md-5 text-right market-doge-amount"><h3> </h3></div>' +
' <div class="col-md-7">CoIntellect\'in verdiği Doge\'ların piyasa değeri (Euro)</div>' +
' <div class="col-md-5 text-right market-euro-price"><h3> </h3></div>' +
' <div class="col-md-7">CoIntellect\'in verdiği Doge\'ların Cryptsy değeri (BTC)</div>' +
' <div class="col-md-5 text-right cryptsy-btc-amount"><h3> </h3></div>' +
' <div class="col-md-7">CoIntellect\'in verdiği Doge\'ların BTCTurk değeri (TL)</div>' +
' <div class="col-md-5 text-right btcturk-tl-price"><h3> </h3></div>' +
' <div class="col-md-7">CoIntellect\'in verdiği Doge\'ların BTCTurk değeri (Euro)</div>' +
' <div class="col-md-5 text-right btcturk-euro-price"><h3> </h3></div>' +
' </div>' +
' </div>' +
' </div>' +
'</div>' +
'');
},
addAction: function () {
$('input.dcAmountInEuro').keyup(function () {
window.clearTimeout(timer);
timer = window.setTimeout(function () {
ccb.calculate();
}, DELAY);
});
$('div.datainfo:first h4 > a').click(function (event) {
event.preventDefault();
$('input.dcAmountInEuro').val($(this).text().match(/([0-9\.]+)/g)[0]).keyup();
});
},
init: function () {
this.addBox();
this.addAction();
}
};
ccb.init();