Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2018
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. // I am using axios module in order to connect
  3.  
  4. var axios = require('axios');
  5.  
  6. var user = "5df3d044-7bd9-4d34-b6fc-841ae8bbae74";
  7. var password = "ca4af97f-2d15-4e10-a235-979c9d31bf09";
  8.  
  9. //line below encodes both keys to base64
  10. var token = Buffer.from(user + ':' + password).toString('base64')
  11.  
  12.  
  13. var coindeal_balans_BTC;
  14. var coindeal_balans_PLN;
  15. var coindeal_balans_FTO;
  16.  
  17. var coindeal_BTCPLN_BID;
  18. var coindeal_BTCPLN_ASK;
  19. var coindeal_FTOBTC_BID;
  20.  
  21. var Yobit_balans_BTC;
  22. var Yobit_balans_FTO;
  23. var Yobit_FTOBTC_ASK;
  24.  
  25.  
  26. ////////////////YOBIT/////////////
  27.  
  28.  
  29. //////KLUCZE API//////
  30.  
  31.  
  32.  
  33. yobit_klucz_api = 'CDAE42BEA94587D1122EDA09986051AF'
  34. yobit_klucz_sekret = 'ba4261d84cbd1ad782b861c0f3874793'
  35.  
  36.  
  37.  
  38. ////PARY WALUTOWE////
  39.  
  40.  
  41. para_walutowa_GAME_PLN = 'GAME/PLN'
  42. para_walutowa_BTC_PLN = 'BTC/PLN'
  43. para_walutowa_BTC_USD = 'BTC/USD'
  44.  
  45.  
  46. //itd...
  47.  
  48. ////POZOSTAŁE ZMIENNE///
  49.  
  50.  
  51.  
  52. var cena
  53. var balans_PLN
  54.  
  55.  
  56.  
  57. ///////REQUIRES///////to ma tutaj być dokładnie w tym miejscu nie ruszać tego bo się program zrypie
  58.  
  59. //const fs = require('fs');
  60.  
  61. 'use strict';
  62. const ccxt = require('ccxt');
  63.  
  64.  
  65. ///////////////////GLOWNY PROGRAM/////////////////////
  66.  
  67.  
  68. // FUNKCJE AXIOSA POBIERAJĄ DANE Z COINDEALA
  69. async function applyRequests() {
  70.     var response = await axios({
  71.         method: 'GET',
  72.         url: 'https://apigateway.coindeal.com/api/v1/trading/balance',
  73.         data: {
  74.  
  75.         },
  76.         headers: {
  77.             'Authorization': 'Basic ' + token,
  78.  
  79.         },
  80.     });
  81.  
  82.     coindeal_balans_PLN = (response.data[7].available);
  83.     coindeal_balans_BTC = (response.data[0].available);
  84.     coindeal_balans_FTO = (response.data[8].available);
  85.  
  86.     response = await axios({
  87.         method: 'GET',
  88.         url: 'https://apigateway.coindeal.com/api/v1/trading/balance',
  89.         data: {
  90.  
  91.         },
  92.         headers: {
  93.             'Authorization': 'Basic ' + token,
  94.  
  95.         },
  96.     })
  97.  
  98.     response = await axios({
  99.         method: 'GET',
  100.         url: 'https://apigateway.coindeal.com/api/v1/public/orderbook/BTCPLN?limit=10000',
  101.         data: {
  102.             symbol: "BTCPLN",
  103.             currencyPair: "0",
  104.             message: "string",
  105.             errors: {}
  106.         },
  107.         headers: {
  108.             'Authorization': 'Basic ' + token,
  109.  
  110.         },
  111.     });
  112.  
  113.     coindeal_BTCPLN_BID = response.data.bid
  114.     coindeal_BTCPLN_ASK = response.data.ask
  115.  
  116.     response = await axios({
  117.         method: 'GET',
  118.         url: 'https://apigateway.coindeal.com/api/v1/trading/balance',
  119.         data: {
  120.  
  121.         },
  122.         headers: {
  123.             'Authorization': 'Basic ' + token,
  124.  
  125.         },
  126.     })
  127.  
  128.     response = await axios({
  129.         method: 'GET',
  130.         url: 'https://apigateway.coindeal.com/api/v1/public/orderbook/FTOBTC?limit=10000',
  131.         data: {
  132.             symbol: "FTOBTC",
  133.             currencyPair: "0",
  134.             message: "string",
  135.             errors: {}
  136.         },
  137.         headers: {
  138.             'Authorization': 'Basic ' + token,
  139.  
  140.         },
  141.     })
  142.  
  143.     sprawdz_cene(yobit_klucz_api, yobit_klucz_sekret, para_walutowa_BTC_USD);
  144.     wyniki();
  145. }
  146.  
  147. applyRequests();
  148.  
  149. function wyniki() {
  150.  
  151.     //TUTAJ BĘDĄ SIĘ WYKONYWAĆ OBLICZENIA
  152.  
  153.     console.log(coindeal_balans_BTC);
  154.     console.log(coindeal_balans_PLN);
  155.     console.log(coindeal_balans_FTO);
  156.  
  157.     console.log(coindeal_BTCPLN_BID[0]);
  158.     console.log(coindeal_BTCPLN_ASK[0]);
  159.     console.log(coindeal_FTOBTC_BID[0]);
  160.  
  161.     console.log(Yobit_balans_BTC);
  162.     console.log(Yobit_balans_FTO);
  163.  
  164.     console.log(Yobit_FTOBTC_ASK[1]);
  165.  
  166.  
  167. }
  168.  
  169.  
  170.  
  171.  
  172. //setInterval(function () {
  173.  
  174. //dupa()
  175.  
  176. //sprawdz_cene (yobit_klucz_api, yobit_klucz_sekret, para_walutowa_BTC_USD);
  177.  
  178. //wyniki();
  179.  
  180.  
  181.  
  182. //}, 1200);
  183.  
  184.  
  185.  
  186.  
  187. /////////////////FUNKCJE//////////////////////////
  188.  
  189.  
  190. ////ZBIERANIE DANYCH////
  191.  
  192.  
  193.  
  194. async function sprawdz_cene(klucz_api, klucz_sekret, para_walutowa) {
  195.     //  let bitbay    = new ccxt.bitbay ()
  196.     //let bitbay  = new ccxt.bitbay ({ verbose: true })
  197.     //let bitbay     = new ccxt.bitbay ()
  198.     let yobit = new ccxt.yobit({
  199.         apiKey: klucz_api,
  200.         secret: klucz_sekret,
  201.     })
  202.  
  203.     const exchangeId = 'yobit'
  204.         , exchangeClass = ccxt[exchangeId]
  205.         , exchange = new exchangeClass({
  206.             'apiKey': klucz_api,
  207.             'secret': klucz_sekret,
  208.             'timeout': 30000,
  209.             'enableRateLimit': true,
  210.         })
  211.  
  212.  
  213.     /*   console.log (bitbay.id,    await bitbay.loadMarkets ())
  214. console.log (bitbay.id,  await bitbay.loadMarkets  ())
  215. console.log (bitbay.id,     await bitbay.loadMarkets ())
  216. */
  217.     // console.log (bitbay.id,    await bitbay.fetchOrderBook (bitbay.symbols[0]))
  218.     //  console.log (bitbay.id,  await bitbay.fetchTicker (para_walutowa))
  219.     //   console.log (bitbay.id,     await bitbay.fetchTrades (para_walutowa))
  220.  
  221.     // console.log (bitbay.id, await bitbay.fetchBalance ())
  222.  
  223.  
  224.  
  225.  
  226.     balans = (yobit.id, await yobit.fetchBalance())
  227.  
  228.     //console.log (balans.free.FTO);
  229.  
  230.     Yobit_balans_BTC = balans.free.BTC
  231.     Yobit_balans_FTO = balans.free.FTO
  232.  
  233.  
  234.  
  235.     yobit_FTOBTC = (yobit.id, await yobit.fetchOrderBook('FTO/BTC'))
  236.  
  237.     //console.log (dupa2.asks);
  238.  
  239.     Yobit_FTOBTC_ASK = (yobit_FTOBTC.asks)
  240.     //cena= (yobit.id,  await yobit.fetchTicker (para_walutowa))
  241.  
  242.     //console.log (cena)
  243.  
  244.  
  245.     //console.log (Yobit_FTOBTC_ASK);
  246.  
  247.  
  248.  
  249.  
  250.     // sell 1 BTC/USD for market price, sell a bitcoin for dollars immediately
  251.     // console.log (bitbay.id, await bitbay.createMarketSellOrder (para_walutowa, 1))
  252.  
  253.  
  254.     // buy 1 BTC/USD for $2500, you pay $2500 and receive ฿1 when the order is closed
  255.     //TA FUNKCJA DZIALA NA BITBAYU, STANDARDOWA TRANSAKCJA
  256.  
  257.     // console.log (bitbay.id, await bitbay.createLimitSellOrder (para_walutowa, amount, price))
  258.     /*
  259.    
  260.         // pass/redefine custom exchange-specific order params: type, amount, price or whatever
  261.         // use a custom order type
  262.         bitbay.createLimitSellOrder (para_walutowa, 1, 10, { 'type': 'trailing-stop' })*/
  263.  
  264.  
  265.  
  266.  
  267.  
  268. };
  269.  
  270.  
  271.  
  272. //////TRANSFER/////
  273.  
  274.  
  275.  
  276. async function transfer(klucz_api, klucz_sekret, amount, portfel_biorca) {
  277.     //  let bitbay    = new ccxt.bitbay ()
  278.     //let bitbay  = new ccxt.bitbay ({ verbose: true })
  279.     //let bitbay     = new ccxt.bitbay ()
  280.     let bitbay = new ccxt.bitbay({
  281.         apiKey: klucz_api,
  282.         secret: klucz_sekret,
  283.     })
  284.  
  285.     const exchangeId = 'bitbay'
  286.         , exchangeClass = ccxt[exchangeId]
  287.         , exchange = new exchangeClass({
  288.             'apiKey': klucz_api,
  289.             'secret': klucz_sekret,
  290.             'timeout': 30000,
  291.             'enableRateLimit': true,
  292.         })
  293.  
  294.  
  295.     exchange.withdraw(code, amount, portfel_biorca, tag = undefined, params = {})
  296.  
  297.  
  298.  
  299. };
  300.  
  301.  
  302. //////////HANDEL/////////
  303.  
  304.  
  305.  
  306. async function sell(klucz_api, klucz_sekret, para_walutowa, amount, price) {
  307.     //  let bitbay    = new ccxt.bitbay ()
  308.     //let bitbay  = new ccxt.bitbay ({ verbose: true })
  309.     //let bitbay     = new ccxt.bitbay ()
  310.     let bitbay = new ccxt.bitbay({
  311.         apiKey: klucz_api,
  312.         secret: klucz_sekret,
  313.     })
  314.  
  315.     const exchangeId = 'bitbay'
  316.         , exchangeClass = ccxt[exchangeId]
  317.         , exchange = new exchangeClass({
  318.             'apiKey': klucz_api,
  319.             'secret': klucz_sekret,
  320.             'timeout': 30000,
  321.             'enableRateLimit': true,
  322.         })
  323.  
  324.  
  325.     //STANDARDOWA TRANSAKCJA TA FUNKCJA DZIALA NP NA BITBAYU, MA BYĆ JAKO CONSOLE.LOG
  326.  
  327.     console.log(bitbay.id, await bitbay.createLimitSellOrder(para_walutowa, amount, price))
  328.  
  329.  
  330.     /*
  331.    
  332.    
  333.     ////INNE SPECJALNE FUNKCJE DO SPRZEDAZY
  334.    
  335.        
  336.         //use a custom order type
  337.         bitbay.createLimitSellOrder (para_walutowa, 1, 10, { 'type': 'trailing-stop' })
  338.        
  339.        
  340.        
  341.         //sell 1 BTC/USD for market price, sell a bitcoin for dollars immediately
  342.         console.log (bitbay.id, await bitbay.createMarketSellOrder (para_walutowa, 1))
  343.    
  344.        
  345.     */
  346.  
  347. };
  348.  
  349.  
  350.  
  351.  
  352. async function buy(klucz_api, klucz_sekret, para_walutowa, amount, price) {
  353.     //  let bitbay    = new ccxt.bitbay ()
  354.     //let bitbay  = new ccxt.bitbay ({ verbose: true })
  355.     //let bitbay     = new ccxt.bitbay ()
  356.     let bitbay = new ccxt.bitbay({
  357.         apiKey: klucz_api,
  358.         secret: klucz_sekret,
  359.     })
  360.  
  361.     const exchangeId = 'bitbay'
  362.         , exchangeClass = ccxt[exchangeId]
  363.         , exchange = new exchangeClass({
  364.             'apiKey': klucz_api,
  365.             'secret': klucz_sekret,
  366.             'timeout': 30000,
  367.             'enableRateLimit': true,
  368.         })
  369.  
  370.  
  371.     //STANDARDOWA TRANSAKCJA TA FUNKCJA DZIALA NP NA BITBAYU
  372.  
  373.     console.log(bitbay.id, await bitbay.createLimitBuyOrder(para_walutowa, amount, price))
  374.  
  375.  
  376.     /*
  377.    
  378.    
  379.     ////INNE SPECJALNE FUNKCJE DO KUPOWANIA
  380.    
  381.        
  382.         //use a custom order type
  383.         bitbay.createLimitBuyOrder (para_walutowa, 1, 10, { 'type': 'trailing-stop' })
  384.        
  385.        
  386.        
  387.         //sell 1 BTC/USD for market price, sell a bitcoin for dollars immediately
  388.         console.log (bitbay.id, await bitbay.createMarketBuyOrder (para_walutowa, 1))
  389.    
  390.        
  391.     */
  392.  
  393. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement