1124 | 1127 |
1129 | 1132 |
1134 | 1137 |
1139 | 1142 |
1156 | 1159 |
1161 | 1164 |
1166 | 1169 |
1171 | 1174 |
├── .gitignore ├── .gitmodules ├── .htaccess ├── LICENSE ├── README.md ├── ccc-streamer-utilities.js └── index.html /.gitignore: -------------------------------------------------------------------------------- 1 | coinhive* 2 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "cryptocoins"] 2 | path = cryptocoins 3 | url = https://github.com/allienworks/cryptocoins 4 | -------------------------------------------------------------------------------- /.htaccess: -------------------------------------------------------------------------------- 1 | # Force www: 2 | RewriteEngine on 3 | RewriteCond %{HTTP_HOST} ^10k.pizza [NC] 4 | RewriteRule ^(.*)$ http://www.10k.pizza/$1 [L,R=301,NC] -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Ben 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 10K Pizza Cryptofolio 2 | 3 | A single-page cryptocurrency portfolio with extra bells and whistles. 4 | 5 | ## 10K Pizza 6 | 7 | This code forms the basis for [10K Pizza](https://www.10k.pizza), which runs this code on production along with a backend to manage user logins and additional email alert functionality. 8 | 9 | ### Aside: Installing with the server code 10 | 11 | If you're interested in running the site without a backend, this repository is all you'll need. If you'd like to include the backend code (which features a database, registration and login), you can pull the server and front-end from https://github.com/Cybourgeoisie/10KPizza. 12 | 13 | ## Installation 14 | 15 | To download and install the 10K Pizza cryptofolio locally, you'll need to clone with the "recursive" flag since this repository includes the latest cryptocoins repo as well: 16 | 17 | ```git clone --recursive https://github.com/Cybourgeoisie/cryptofolio.git``` 18 | 19 | ## Reporting Requests, Bugs & Issues 20 | 21 | Feel free to add issues to the repository as necessary. If you want to get my attention quicker, you can ping me directly on Twitter: [@cybourgeoisie](https://twitter.com/cybourgeoisie) or [@10K_Pizza](https://twitter.com/10K_Pizza). 22 | 23 | ## Donations 24 | 25 | Any crypto donations are welcome and greatly appreciated: 26 | 27 | **Bitcoin:** 28 | ```1DvKL6bsvFbPLHzpfyi1gN14UTLeTMteP1``` 29 | 30 | **Bitcoin Cash:** 31 | ```1aXsChnzsjJZ5K5moNqeuxzniJ6p4atra``` 32 | 33 | **Ethereum:** 34 | ```0x0963f59FB09D899768Bcd2599529d2CAaC855d2c``` 35 | 36 | **Litecoin:** 37 | ```LTXtDghDffVX6jarwskRsgP63qYyuh8AC3``` 38 | 39 | **Monero:** 40 | ```41zJ821YXfp952H7XAFNpZimo1gsF8V8mhd8ioSYf6tvesq5Tjm2rW5F1qM4uCFFgATQztxXowd5Q9pR3hpQvgcz5Z4QMha``` 41 | 42 | **Decred:** 43 | ```DsiRCP7pvKF5RgEuUgT77cHVtBdwRwSWNxV``` 44 | -------------------------------------------------------------------------------- /ccc-streamer-utilities.js: -------------------------------------------------------------------------------- 1 | var CCC = CCC || {}; 2 | 3 | CCC.STATIC=CCC.STATIC || {}; 4 | 5 | CCC.STATIC.TYPE={ 6 | 'TRADE' : '0' 7 | , 'FEEDNEWS' : '1' 8 | , 'CURRENT' : '2' 9 | , 'LOADCOMPLATE' : '3' 10 | , 'COINPAIRS' : '4' 11 | , 'CURRENTAGG' : '5' 12 | , 'TOPLIST' : '6' 13 | , 'TOPLISTCHANGE' : '7' 14 | , 'ORDERBOOK' : '8' 15 | , 'FULLORDERBOOK' : '9' 16 | , 'ACTIVATION' : '10' 17 | 18 | , 'TRADECATCHUP' : '100' 19 | , 'NEWSCATCHUP' : '101' 20 | 21 | , 'TRADECATCHUPCOMPLETE' : '300' 22 | , 'NEWSCATCHUPCOMPLETE' : '301' 23 | 24 | }; 25 | 26 | CCC.STATIC.CURRENCY = CCC.STATIC.CURRENCY || {}; 27 | 28 | CCC.STATIC.CURRENCY.SYMBOL = { 29 | 'BTC' : 'Ƀ' 30 | , 'LTC' : 'Ł' 31 | , 'DAO' : 'Ð' 32 | , 'USD' : '$' 33 | , 'CNY' : '¥' 34 | , 'EUR' : '€' 35 | , 'GBP' : '£' 36 | , 'JPY' : '¥' 37 | , 'PLN' : 'zł' 38 | , 'RUB' : '₽' 39 | , 'ETH' : 'Ξ' 40 | , 'GOLD' : 'Gold g' 41 | , 'INR' : '₹' 42 | , 'BRL' : 'R$' 43 | }; 44 | 45 | CCC.STATIC.CURRENCY.getSymbol = function(symbol){ 46 | return CCC.STATIC.CURRENCY.SYMBOL[symbol] || symbol; 47 | }; 48 | 49 | CCC.STATIC.UTIL = { 50 | exchangeNameMapping : { 51 | 'CCCAGG':'CryptoCompare Index', 52 | 'BTCChina':'BTCC' 53 | }, 54 | isMobile: function(userAgent){ 55 | if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|ipad|iris|kindle|Android|Silk|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(userAgent) 56 | || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(userAgent.substr(0,4))) 57 | return true; 58 | return false; 59 | }, 60 | convertToMB : function(bytes){ 61 | return (parseInt(bytes,10)/1024/1024).toFixed(2)+' MB'; 62 | }, 63 | getNameForExchange : function(exchangeName){ 64 | if(this.exchangeNameMapping.hasOwnProperty(exchangeName)){ 65 | return this.exchangeNameMapping[exchangeName]; 66 | } 67 | return exchangeName; 68 | }, 69 | noExponents : function(value){ 70 | var data= String(value).split(/[eE]/); 71 | if(data.length== 1) return data[0]; 72 | 73 | var z= '', sign= value<0? '-':'', 74 | str= data[0].replace('.', ''), 75 | mag= Number(data[1])+ 1; 76 | 77 | if(mag<0){ 78 | z= sign + '0.'; 79 | while(mag++) z += '0'; 80 | return z + str.replace(/^\-/,''); 81 | } 82 | mag -= str.length; 83 | while(mag--) z += '0'; 84 | return str + z; 85 | }, 86 | reduceFloatVal : function(value){ 87 | value = parseFloat(value); 88 | if(value>1){ 89 | value = Math.round(value * 100) / 100; 90 | return value; 91 | } 92 | if(value>=0.00001000){ 93 | return parseFloat(value.toPrecision(4)); 94 | } 95 | if(value>=0.00000100){ 96 | return parseFloat(value.toPrecision(3)); 97 | } 98 | if(value>=0.00000010){ 99 | return parseFloat(value.toPrecision(2)); 100 | } 101 | return parseFloat(value.toPrecision(1)); 102 | }, 103 | reduceReal : function(value){ 104 | value = parseFloat(value); 105 | return parseFloat(value.toFixed(8)); 106 | }, 107 | convertCurrentKeyToAll : function(key){ 108 | var valuesArray = key.split("~"); 109 | valuesArray[0]=CCC.STATIC.TYPE.CURRENTAGG; 110 | valuesArray[1]='CCCAGG'; 111 | return valuesArray.join('~'); 112 | }, 113 | convertCurrentKeyToTrade : function(key){ 114 | var valuesArray = key.split("~"); 115 | valuesArray[0]=CCC.STATIC.TYPE.TRADE; 116 | return valuesArray.join('~'); 117 | }, 118 | convertValueToDisplay: function(symbol,value,filterNumberFunctionAngularJS,type,fullNumbers){ 119 | var prefix = ''; 120 | var valueSign=1; 121 | value = parseFloat(value); 122 | var valueAbs=Math.abs(value); 123 | var decimalsOnBigNumbers = 2; 124 | var decimalsOnNormalNumbers = 2; 125 | var decimalsOnSmallNumbers = 4; 126 | if(fullNumbers===true){ 127 | decimalsOnBigNumbers =2; 128 | decimalsOnNormalNumbers = 0; 129 | decimalsOnSmallNumbers= 4; 130 | } 131 | if(type=="8decimals"){ 132 | decimalsOnBigNumbers =4; 133 | decimalsOnNormalNumbers = 8; 134 | decimalsOnSmallNumbers= 8; 135 | if(value<0.0001 && value>=0.00001){decimalsOnSmallNumbers=4;} 136 | if(value<0.001 && value>=0.0001){decimalsOnSmallNumbers=5;} 137 | if(value<0.01 && value>=0.001){decimalsOnSmallNumbers=6;} 138 | if(value<0.1 && value>=0.01){decimalsOnSmallNumbers=7;} 139 | } 140 | if(symbol!=''){prefix = symbol+' ';} 141 | if(value<0){valueSign = -1;} 142 | if(value==0){return prefix+'0';} 143 | 144 | if(value<0.00001000 && value>=0.00000100 && decimalsOnSmallNumbers>3){ 145 | decimalsOnSmallNumbers=3; 146 | } 147 | if(value<0.00000100 && value>=0.00000010 && decimalsOnSmallNumbers>2){ 148 | decimalsOnSmallNumbers=2; 149 | } 150 | if(value<0.00000010 && decimalsOnSmallNumbers>1){ 151 | decimalsOnSmallNumbers=1; 152 | } 153 | 154 | if(type=="short"||type=="8decimals"){ 155 | if(valueAbs>10000000000){ 156 | valueAbs=valueAbs/1000000000; 157 | return prefix+filterNumberFunctionAngularJS(valueSign*valueAbs,decimalsOnBigNumbers)+' B'; 158 | } 159 | if(valueAbs>10000000){ 160 | valueAbs=valueAbs/1000000; 161 | return prefix+filterNumberFunctionAngularJS(valueSign*valueAbs,decimalsOnBigNumbers)+' M'; 162 | } 163 | if(valueAbs>10000){ 164 | valueAbs=valueAbs/1000; 165 | return prefix+filterNumberFunctionAngularJS(valueSign*valueAbs,decimalsOnBigNumbers)+' K'; 166 | } 167 | if(type=="8decimals" && valueAbs>=100){ 168 | return prefix+filterNumberFunctionAngularJS(valueSign*valueAbs,decimalsOnBigNumbers); 169 | } 170 | if(valueAbs>=1){ 171 | return prefix+filterNumberFunctionAngularJS(valueSign*valueAbs,decimalsOnNormalNumbers); 172 | } 173 | return prefix+(valueSign*valueAbs).toPrecision(decimalsOnSmallNumbers); 174 | }else{ 175 | if(valueAbs>=1){ 176 | return prefix+filterNumberFunctionAngularJS(valueSign*valueAbs,decimalsOnNormalNumbers); 177 | } 178 | 179 | return prefix+this.noExponents((valueSign*valueAbs).toPrecision(decimalsOnSmallNumbers)); 180 | } 181 | } 182 | }; 183 | 184 | 185 | CCC.TRADE=CCC.TRADE || {}; 186 | /* 187 | trade fields binary values always in the last ~ 188 | */ 189 | 190 | CCC.TRADE.FLAGS = { 191 | 'SELL' : 0x1 // hex for binary 1 192 | , 'BUY' : 0x2 // hex for binary 10 193 | , 'UNKNOWN' : 0x4 // hex for binary 100 194 | } 195 | 196 | CCC.TRADE.FIELDS = { 197 | 'T' : 0x0 // hex for binary 0, it is a special case of fields that are always there TYPE 198 | , 'M' : 0x0 // hex for binary 0, it is a special case of fields that are always there MARKET 199 | , 'FSYM' : 0x0 // hex for binary 0, it is a special case of fields that are always there FROM SYMBOL 200 | , 'TSYM' : 0x0 // hex for binary 0, it is a special case of fields that are always there TO SYMBOL 201 | , 'F' : 0x0 // hex for binary 0, it is a special case of fields that are always there FLAGS 202 | , 'ID' : 0x1 // hex for binary 1 ID 203 | , 'TS' : 0x2 // hex for binary 10 TIMESTAMP 204 | , 'Q' : 0x4 // hex for binary 100 QUANTITY 205 | , 'P' : 0x8 // hex for binary 1000 PRICE 206 | , 'TOTAL' : 0x10 // hex for binary 10000 TOTAL 207 | 208 | }; 209 | 210 | CCC.TRADE.DISPLAY = CCC.TRADE.DISPLAY||{}; 211 | CCC.TRADE.DISPLAY.FIELDS = { 212 | 'T' : {"Show":false} 213 | , 'M' : {"Show":true, 'Filter':'Market'} 214 | , 'FSYM' : {"Show":true, 'Filter':'CurrencySymbol'} 215 | , 'TSYM' : {"Show":true, 'Filter':'CurrencySymbol'} 216 | , 'F' : {"Show":true, 'Filter':'TradeFlag'} 217 | , 'ID' : {"Show":true, 'Filter':'Text'} 218 | , 'TS' : {'Show':true, 'Filter':'Date' , 'Format':'yyyy MMMM dd HH:mm:ss'} 219 | , 'Q' : {'Show':true, 'Filter':'Number', 'Symbol':'FSYM'} 220 | , 'P' : {'Show':true, 'Filter':'Number', 'Symbol':'TSYM'} 221 | , 'TOTAL' : {'Show':true, 'Filter':'Number', 'Symbol':'TSYM'} 222 | 223 | }; 224 | 225 | CCC.TRADE.pack = function(tradeObject){ 226 | var mask = 0; 227 | var packedTrade =''; 228 | for (var field in tradeObject) { 229 | packedTrade += '~'+tradeObject[field]; 230 | mask|=this.FIELDS[field]; 231 | } 232 | return packedTrade.substr(1)+'~'+mask.toString(16); 233 | }; 234 | 235 | CCC.TRADE.unpack = function(tradeString){ 236 | var valuesArray = tradeString.split("~"); 237 | var valuesArrayLenght = valuesArray.length; 238 | var mask = valuesArray[valuesArrayLenght-1]; 239 | var maskInt = parseInt(mask,16); 240 | var unpackedTrade = {}; 241 | var currentField = 0; 242 | for(var property in this.FIELDS){ 243 | if(this.FIELDS[property] === 0) 244 | { 245 | unpackedTrade[property] = valuesArray[currentField]; 246 | currentField++; 247 | } 248 | else if(maskInt&this.FIELDS[property]) 249 | { 250 | unpackedTrade[property] = valuesArray[currentField]; 251 | currentField++; 252 | } 253 | } 254 | 255 | return unpackedTrade; 256 | } 257 | 258 | CCC.TRADE.getKey = function(tradeObject){ 259 | return tradeObject['T']+'~'+tradeObject['M']+'~'+tradeObject['FSYM']+'~'+tradeObject['TSYM']; 260 | }; 261 | 262 | CCC.CURRENT=CCC.CURRENT || {}; 263 | /* 264 | current fields mask values always in the last ~ 265 | */ 266 | 267 | CCC.CURRENT.FLAGS = { 268 | 'PRICEUP' : 0x1 // hex for binary 1 269 | , 'PRICEDOWN' : 0x2 // hex for binary 10 270 | , 'PRICEUNCHANGED' : 0x4 // hex for binary 100 271 | , 'BIDUP' : 0x8 // hex for binary 1000 272 | , 'BIDDOWN' : 0x10 // hex for binary 10000 273 | , 'BIDUNCHANGED' : 0x20 // hex for binary 100000 274 | , 'OFFERUP' : 0x40 // hex for binary 1000000 275 | , 'OFFERDOWN' : 0x80 // hex for binary 10000000 276 | , 'OFFERUNCHANGED' : 0x100 // hex for binary 100000000 277 | , 'AVGUP' : 0x200 // hex for binary 1000000000 278 | , 'AVGDOWN' : 0x400 // hex for binary 10000000000 279 | , 'AVGUNCHANGED' : 0x800 // hex for binary 100000000000 280 | }; 281 | 282 | 283 | CCC.CURRENT.FIELDS={ 284 | 'TYPE' : 0x0 // hex for binary 0, it is a special case of fields that are always there 285 | , 'MARKET' : 0x0 // hex for binary 0, it is a special case of fields that are always there 286 | , 'FROMSYMBOL' : 0x0 // hex for binary 0, it is a special case of fields that are always there 287 | , 'TOSYMBOL' : 0x0 // hex for binary 0, it is a special case of fields that are always there 288 | , 'FLAGS' : 0x0 // hex for binary 0, it is a special case of fields that are always there 289 | , 'PRICE' : 0x1 // hex for binary 1 290 | , 'BID' : 0x2 // hex for binary 10 291 | , 'OFFER' : 0x4 // hex for binary 100 292 | , 'LASTUPDATE' : 0x8 // hex for binary 1000 293 | , 'AVG' : 0x10 // hex for binary 10000 294 | , 'LASTVOLUME' : 0x20 // hex for binary 100000 295 | , 'LASTVOLUMETO' : 0x40 // hex for binary 1000000 296 | , 'LASTTRADEID' : 0x80 // hex for binary 10000000 297 | , 'VOLUMEHOUR' : 0x100 // hex for binary 100000000 298 | , 'VOLUMEHOURTO' : 0x200 // hex for binary 1000000000 299 | , 'VOLUME24HOUR' : 0x400 // hex for binary 10000000000 300 | , 'VOLUME24HOURTO' : 0x800 // hex for binary 100000000000 301 | , 'OPENHOUR' : 0x1000 // hex for binary 1000000000000 302 | , 'HIGHHOUR' : 0x2000 // hex for binary 10000000000000 303 | , 'LOWHOUR' : 0x4000 // hex for binary 100000000000000 304 | , 'OPEN24HOUR' : 0x8000 // hex for binary 1000000000000000 305 | , 'HIGH24HOUR' : 0x10000 // hex for binary 10000000000000000 306 | , 'LOW24HOUR' : 0x20000 // hex for binary 100000000000000000 307 | , 'LASTMARKET' : 0x40000 // hex for binary 1000000000000000000, this is a special case and will only appear on CCCAGG messages 308 | }; 309 | 310 | CCC.CURRENT.DISPLAY = CCC.CURRENT.DISPLAY||{}; 311 | CCC.CURRENT.DISPLAY.FIELDS={ 312 | 'TYPE' : {'Show':false} 313 | , 'MARKET' : {'Show':true, 'Filter':'Market'} 314 | , 'FROMSYMBOL' : {'Show':false} 315 | , 'TOSYMBOL' : {'Show':false} 316 | , 'FLAGS' : {'Show':false} 317 | , 'PRICE' : {'Show':true, 'Filter':'Number', 'Symbol':'TOSYMBOL'} 318 | , 'BID' : {'Show':true, 'Filter':'Number', 'Symbol':'TOSYMBOL'} 319 | , 'OFFER' : {'Show':true, 'Filter':'Number', 'Symbol':'TOSYMBOL'} 320 | , 'LASTUPDATE' : {'Show':true, 'Filter':'Date' , 'Format':'yyyy MMMM dd HH:mm:ss'} 321 | , 'AVG' : {'Show':true,' Filter':'Number', 'Symbol':'TOSYMBOL'} 322 | , 'LASTVOLUME' : {'Show':true, 'Filter':'Number', 'Symbol':'FROMSYMBOL'} 323 | , 'LASTVOLUMETO' : {'Show':true, 'Filter':'Number', 'Symbol':'TOSYMBOL'} 324 | , 'LASTTRADEID' : {'Show':true, 'Filter':'String'} 325 | , 'VOLUMEHOUR' : {'Show':true, 'Filter':'Number', 'Symbol':'FROMSYMBOL'} 326 | , 'VOLUMEHOURTO' : {'Show':true, 'Filter':'Number', 'Symbol':'TOSYMBOL'} 327 | , 'VOLUME24HOUR' : {'Show':true, 'Filter':'Number', 'Symbol':'FROMSYMBOL'} 328 | , 'VOLUME24HOURTO' : {'Show':true, 'Filter':'Number', 'Symbol':'TOSYMBOL'} 329 | , 'OPENHOUR' : {'Show':true, 'Filter':'Number', 'Symbol':'TOSYMBOL'} 330 | , 'HIGHHOUR' : {'Show':true, 'Filter':'Number', 'Symbol':'TOSYMBOL'} 331 | , 'LOWHOUR' : {'Show':true, 'Filter':'Number', 'Symbol':'TOSYMBOL'} 332 | , 'OPEN24HOUR' : {'Show':true, 'Filter':'Number', 'Symbol':'TOSYMBOL'} 333 | , 'HIGH24HOUR' : {'Show':true, 'Filter':'Number', 'Symbol':'TOSYMBOL'} 334 | , 'LOW24HOUR' : {'Show':true, 'Filter':'Number', 'Symbol':'TOSYMBOL'} 335 | , 'LASTMARKET' : {'Show':true, 'Filter':'String'} 336 | }; 337 | 338 | CCC.CURRENT.pack = function(currentObject) 339 | { 340 | var mask = 0; 341 | var packedCurrent =''; 342 | for(var property in this.FIELDS) 343 | { 344 | if(currentObject.hasOwnProperty(property)){ 345 | packedCurrent += '~'+currentObject[property]; 346 | mask|=this.FIELDS[property]; 347 | } 348 | } 349 | //removing first character beacsue it is a ~ 350 | return packedCurrent.substr(1)+'~'+mask.toString(16); 351 | }; 352 | 353 | CCC.CURRENT.unpack = function(value) 354 | { 355 | var valuesArray = value.split("~"); 356 | var valuesArrayLenght = valuesArray.length; 357 | var mask = valuesArray[valuesArrayLenght-1]; 358 | var maskInt = parseInt(mask,16); 359 | var unpackedCurrent = {}; 360 | var currentField = 0; 361 | for(var property in this.FIELDS) 362 | { 363 | if(this.FIELDS[property] === 0) 364 | { 365 | unpackedCurrent[property] = valuesArray[currentField]; 366 | currentField++; 367 | } 368 | else if(maskInt&this.FIELDS[property]) 369 | { 370 | //i know this is a hack, for cccagg, future code please don't hate me:(, i did this to avoid 371 | //subscribing to trades as well in order to show the last market 372 | if(property === 'LASTMARKET'){ 373 | unpackedCurrent[property] = valuesArray[currentField]; 374 | }else{ 375 | unpackedCurrent[property] = parseFloat(valuesArray[currentField]); 376 | } 377 | currentField++; 378 | } 379 | } 380 | 381 | return unpackedCurrent; 382 | }; 383 | CCC.CURRENT.getKey = function(currentObject){ 384 | return currentObject['TYPE']+'~'+currentObject['MARKET']+'~'+currentObject['FROMSYMBOL']+'~'+currentObject['TOSYMBOL']; 385 | }; 386 | CCC.CURRENT.getKeyFromStreamerData = function(streamerData){ 387 | var valuesArray = streamerData.split("~"); 388 | return valuesArray[0]+'~'+valuesArray[1]+'~'+valuesArray[2]+'~'+valuesArray[3]; 389 | }; 390 | 391 | CCC.noExponents = function(value){ 392 | var data= String(value).split(/[eE]/); 393 | if(data.length== 1) return data[0]; 394 | 395 | var z= '', sign= value<0? '-':'', 396 | str= data[0].replace('.', ''), 397 | mag= Number(data[1])+ 1; 398 | 399 | if(mag<0){ 400 | z= sign + '0.'; 401 | while(mag++) z += '0'; 402 | return z + str.replace(/^\-/,''); 403 | } 404 | mag -= str.length; 405 | while(mag--) z += '0'; 406 | return str + z; 407 | }; 408 | 409 | CCC.filterNumberFunctionPolyfill = function(value,decimals){ 410 | var decimalsDenominator = Math.pow(10,decimals); 411 | var numberWithCorrectDecimals = Math.round(value*decimalsDenominator)/decimalsDenominator; 412 | var parts = numberWithCorrectDecimals.toString().split("."); 413 | parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ","); 414 | return parts.join("."); 415 | } 416 | 417 | CCC.convertValueToDisplay = function(symbol,value,type,fullNumbers){ 418 | var prefix = ''; 419 | var valueSign=1; 420 | value = parseFloat(value); 421 | var valueAbs=Math.abs(value); 422 | var decimalsOnBigNumbers = 2; 423 | var decimalsOnNormalNumbers = 2; 424 | var decimalsOnSmallNumbers = 4; 425 | if(fullNumbers===true){ 426 | decimalsOnBigNumbers =2; 427 | decimalsOnNormalNumbers = 0; 428 | decimalsOnSmallNumbers= 4; 429 | } 430 | if(symbol!=''){ 431 | prefix = symbol+' '; 432 | } 433 | if(value<0){ 434 | valueSign = -1; 435 | } 436 | 437 | if(value==0){ 438 | return prefix+'0'; 439 | } 440 | 441 | if(value<0.00001000 && value>=0.00000100 && decimalsOnSmallNumbers>3){ 442 | decimalsOnSmallNumbers=3; 443 | } 444 | if(value<0.00000100 && value>=0.00000010 && decimalsOnSmallNumbers>2){ 445 | decimalsOnSmallNumbers=2; 446 | } 447 | if(value<0.00000010 && value>=0.00000001 && decimalsOnSmallNumbers>1){ 448 | decimalsOnSmallNumbers=1; 449 | } 450 | 451 | if(type=="short"){ 452 | if(valueAbs>10000000000){ 453 | valueAbs=valueAbs/1000000000; 454 | return prefix+CCC.filterNumberFunctionPolyfill(valueSign*valueAbs,decimalsOnBigNumbers)+' B'; 455 | } 456 | if(valueAbs>10000000){ 457 | valueAbs=valueAbs/1000000; 458 | return prefix+CCC.filterNumberFunctionPolyfill(valueSign*valueAbs,decimalsOnBigNumbers)+' M'; 459 | } 460 | if(valueAbs>10000){ 461 | valueAbs=valueAbs/1000; 462 | return prefix+CCC.filterNumberFunctionPolyfill(valueSign*valueAbs,decimalsOnBigNumbers)+' K'; 463 | } 464 | if(valueAbs>=1){ 465 | return prefix+CCC.filterNumberFunctionPolyfill(valueSign*valueAbs,decimalsOnNormalNumbers); 466 | } 467 | return prefix+(valueSign*valueAbs).toPrecision(decimalsOnSmallNumbers); 468 | }else{ 469 | if(valueAbs>=1){ 470 | return prefix+CCC.filterNumberFunctionPolyfill(valueSign*valueAbs,decimalsOnNormalNumbers); 471 | } 472 | 473 | return prefix+CCC.noExponents((valueSign*valueAbs).toPrecision(decimalsOnSmallNumbers)); 474 | } 475 | }; -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | 5 | 6 |