Advertisement
ipsbruno2016

Untitled

Jan 19th, 2017
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. var request = require('request');
  2.  
  3. var OKCoin = require('okcoin-china');
  4. var dateFormat = require('dateformat');
  5.  
  6. var fs = require('fs');
  7.  
  8. const SMA = require('technicalindicators').SMA;
  9.  
  10.  
  11. // Inicializar classes
  12. var publicClient = new OKCoin();
  13. var privateClient = new OKCoin(apiKey, apiSecret);
  14.  
  15.  
  16.  
  17. isBuyable();
  18.  
  19.  
  20. function isBuyable() {
  21.  
  22.  
  23. var cny = 10000;
  24. var btc = 0;
  25.  
  26. var toBuy = false;
  27.  
  28. publicClient.getKline(function(error, data) {
  29.  
  30. if (error)
  31. return false;
  32.  
  33. var lolinput = [];
  34. var cno = 0;
  35.  
  36. for (p = 3; p < 100; p++) {
  37. for (x = 3; x < 100; x++) {
  38.  
  39. cny = 10000;
  40. btc = 0;
  41.  
  42. toBuy = false;
  43.  
  44. var prices = [];
  45.  
  46. var ema = [];
  47. var ama = [];
  48.  
  49. data.forEach(function(val) {
  50. prices.push(val[1]);
  51. })
  52.  
  53.  
  54. var sma = new SMA({
  55. period: p,
  56. values: prices
  57. });
  58.  
  59. var sme = new SMA({
  60. period: x,
  61. values: prices
  62. });
  63.  
  64.  
  65. var i = 0;
  66.  
  67. var l = 0;
  68.  
  69. prices.forEach(function(val) {
  70.  
  71. var csma = sma.nextValue(val);
  72. var csme = sme.nextValue(val);
  73.  
  74. var date = dateFormat(data[i][0], "hh:MM:ss TT");
  75.  
  76. if (csme < csma && toBuy == false) {
  77.  
  78. //console.log(date + " | Compra: $"+ data[i][1]);
  79.  
  80. btc = cny / data[i][1];
  81.  
  82. lastprice = data[i][1];
  83. toBuy = true;
  84. }
  85.  
  86. if (toBuy == true && csme > csma) {
  87. toBuy = false;
  88.  
  89. cny = btc * data[i][1];
  90.  
  91. l += data[i][1] - lastprice;
  92.  
  93. lastprice = data[i][1];
  94.  
  95. //console.log(date + " | Venda: $"+ data[i][1]);
  96. }
  97.  
  98. i++;
  99.  
  100. })
  101.  
  102. if(cny > cno) {
  103. lolinput = [p, x];
  104. cno = cny;
  105. }
  106.  
  107. }
  108. }
  109. console.log("Ai maluco os periodo pra media movel com mais lucro é o Input = {" + lolinput[0] + "," + lolinput[1] + "} RESULT: " + cno);
  110. }, 'btc_cny', '3min', 2000); // 2 mil candles a 3 min
  111.  
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement