Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.12 KB | None | 0 0
  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. coindeal_FTOBTC_BID = response.data.bid
  144.  
  145. response = await sprawdz_cene(yobit_klucz_api, yobit_klucz_sekret, para_walutowa_BTC_USD);
  146. wyniki();
  147. }
  148.  
  149. applyRequests();
  150.  
  151. function wyniki() {
  152.  
  153. //TUTAJ BĘDĄ SIĘ WYKONYWAĆ OBLICZENIA
  154.  
  155. console.log(coindeal_balans_BTC);
  156. console.log(coindeal_balans_PLN);
  157. console.log(coindeal_balans_FTO);
  158.  
  159. console.log(coindeal_BTCPLN_BID[0]);
  160. console.log(coindeal_BTCPLN_ASK[0]);
  161. console.log(coindeal_FTOBTC_BID[0]);
  162.  
  163. console.log(Yobit_balans_BTC);
  164. console.log(Yobit_balans_FTO);
  165.  
  166. console.log(Yobit_FTOBTC_ASK[1]);
  167.  
  168.  
  169. }
  170.  
  171.  
  172.  
  173.  
  174. //setInterval(function () {
  175.  
  176. //dupa()
  177.  
  178. //sprawdz_cene (yobit_klucz_api, yobit_klucz_sekret, para_walutowa_BTC_USD);
  179.  
  180. //wyniki();
  181.  
  182.  
  183.  
  184. //}, 1200);
  185.  
  186.  
  187.  
  188.  
  189. /////////////////FUNKCJE//////////////////////////
  190.  
  191.  
  192. ////ZBIERANIE DANYCH////
  193.  
  194.  
  195.  
  196. async function sprawdz_cene(klucz_api, klucz_sekret, para_walutowa) {
  197. // let bitbay = new ccxt.bitbay ()
  198. //let bitbay = new ccxt.bitbay ({ verbose: true })
  199. //let bitbay = new ccxt.bitbay ()
  200. let yobit = new ccxt.yobit({
  201. apiKey: klucz_api,
  202. secret: klucz_sekret,
  203. })
  204.  
  205. const exchangeId = 'yobit'
  206. , exchangeClass = ccxt[exchangeId]
  207. , exchange = new exchangeClass({
  208. 'apiKey': klucz_api,
  209. 'secret': klucz_sekret,
  210. 'timeout': 30000,
  211. 'enableRateLimit': true,
  212. })
  213.  
  214.  
  215. /* console.log (bitbay.id, await bitbay.loadMarkets ())
  216. console.log (bitbay.id, await bitbay.loadMarkets ())
  217. console.log (bitbay.id, await bitbay.loadMarkets ())
  218. */
  219. // console.log (bitbay.id, await bitbay.fetchOrderBook (bitbay.symbols[0]))
  220. // console.log (bitbay.id, await bitbay.fetchTicker (para_walutowa))
  221. // console.log (bitbay.id, await bitbay.fetchTrades (para_walutowa))
  222.  
  223. // console.log (bitbay.id, await bitbay.fetchBalance ())
  224.  
  225.  
  226.  
  227.  
  228. balans = (yobit.id, await yobit.fetchBalance())
  229.  
  230. //console.log (balans.free.FTO);
  231.  
  232. Yobit_balans_BTC = balans.free.BTC
  233. Yobit_balans_FTO = balans.free.FTO
  234.  
  235.  
  236.  
  237. yobit_FTOBTC = (yobit.id, await yobit.fetchOrderBook('FTO/BTC'))
  238.  
  239. //console.log (dupa2.asks);
  240.  
  241. Yobit_FTOBTC_ASK = (yobit_FTOBTC.asks)
  242. //cena= (yobit.id, await yobit.fetchTicker (para_walutowa))
  243.  
  244. //console.log (cena)
  245.  
  246.  
  247. //console.log (Yobit_FTOBTC_ASK);
  248.  
  249.  
  250.  
  251.  
  252. // sell 1 BTC/USD for market price, sell a bitcoin for dollars immediately
  253. // console.log (bitbay.id, await bitbay.createMarketSellOrder (para_walutowa, 1))
  254.  
  255.  
  256. // buy 1 BTC/USD for $2500, you pay $2500 and receive ฿1 when the order is closed
  257. //TA FUNKCJA DZIALA NA BITBAYU, STANDARDOWA TRANSAKCJA
  258.  
  259. // console.log (bitbay.id, await bitbay.createLimitSellOrder (para_walutowa, amount, price))
  260. /*
  261.  
  262. // pass/redefine custom exchange-specific order params: type, amount, price or whatever
  263. // use a custom order type
  264. bitbay.createLimitSellOrder (para_walutowa, 1, 10, { 'type': 'trailing-stop' })*/
  265.  
  266.  
  267.  
  268.  
  269.  
  270. };
  271.  
  272.  
  273.  
  274. //////TRANSFER/////
  275.  
  276.  
  277.  
  278. async function transfer(klucz_api, klucz_sekret, amount, portfel_biorca) {
  279. // let bitbay = new ccxt.bitbay ()
  280. //let bitbay = new ccxt.bitbay ({ verbose: true })
  281. //let bitbay = new ccxt.bitbay ()
  282. let bitbay = new ccxt.bitbay({
  283. apiKey: klucz_api,
  284. secret: klucz_sekret,
  285. })
  286.  
  287. const exchangeId = 'bitbay'
  288. , exchangeClass = ccxt[exchangeId]
  289. , exchange = new exchangeClass({
  290. 'apiKey': klucz_api,
  291. 'secret': klucz_sekret,
  292. 'timeout': 30000,
  293. 'enableRateLimit': true,
  294. })
  295.  
  296.  
  297. exchange.withdraw(code, amount, portfel_biorca, tag = undefined, params = {})
  298.  
  299.  
  300.  
  301. };
  302.  
  303.  
  304. //////////HANDEL/////////
  305.  
  306.  
  307.  
  308. async function sell(klucz_api, klucz_sekret, para_walutowa, amount, price) {
  309. // let bitbay = new ccxt.bitbay ()
  310. //let bitbay = new ccxt.bitbay ({ verbose: true })
  311. //let bitbay = new ccxt.bitbay ()
  312. let bitbay = new ccxt.bitbay({
  313. apiKey: klucz_api,
  314. secret: klucz_sekret,
  315. })
  316.  
  317. const exchangeId = 'bitbay'
  318. , exchangeClass = ccxt[exchangeId]
  319. , exchange = new exchangeClass({
  320. 'apiKey': klucz_api,
  321. 'secret': klucz_sekret,
  322. 'timeout': 30000,
  323. 'enableRateLimit': true,
  324. })
  325.  
  326.  
  327. //STANDARDOWA TRANSAKCJA TA FUNKCJA DZIALA NP NA BITBAYU, MA BYĆ JAKO CONSOLE.LOG
  328.  
  329. console.log(bitbay.id, await bitbay.createLimitSellOrder(para_walutowa, amount, price))
  330.  
  331.  
  332. /*
  333.  
  334.  
  335. ////INNE SPECJALNE FUNKCJE DO SPRZEDAZY
  336.  
  337.  
  338. //use a custom order type
  339. bitbay.createLimitSellOrder (para_walutowa, 1, 10, { 'type': 'trailing-stop' })
  340.  
  341.  
  342.  
  343. //sell 1 BTC/USD for market price, sell a bitcoin for dollars immediately
  344. console.log (bitbay.id, await bitbay.createMarketSellOrder (para_walutowa, 1))
  345.  
  346.  
  347. */
  348.  
  349. };
  350.  
  351.  
  352.  
  353.  
  354. async function buy(klucz_api, klucz_sekret, para_walutowa, amount, price) {
  355. // let bitbay = new ccxt.bitbay ()
  356. //let bitbay = new ccxt.bitbay ({ verbose: true })
  357. //let bitbay = new ccxt.bitbay ()
  358. let bitbay = new ccxt.bitbay({
  359. apiKey: klucz_api,
  360. secret: klucz_sekret,
  361. })
  362.  
  363. const exchangeId = 'bitbay'
  364. , exchangeClass = ccxt[exchangeId]
  365. , exchange = new exchangeClass({
  366. 'apiKey': klucz_api,
  367. 'secret': klucz_sekret,
  368. 'timeout': 30000,
  369. 'enableRateLimit': true,
  370. })
  371.  
  372.  
  373. //STANDARDOWA TRANSAKCJA TA FUNKCJA DZIALA NP NA BITBAYU
  374.  
  375. console.log(bitbay.id, await bitbay.createLimitBuyOrder(para_walutowa, amount, price))
  376.  
  377.  
  378. /*
  379.  
  380.  
  381. ////INNE SPECJALNE FUNKCJE DO KUPOWANIA
  382.  
  383.  
  384. //use a custom order type
  385. bitbay.createLimitBuyOrder (para_walutowa, 1, 10, { 'type': 'trailing-stop' })
  386.  
  387.  
  388.  
  389. //sell 1 BTC/USD for market price, sell a bitcoin for dollars immediately
  390. console.log (bitbay.id, await bitbay.createMarketBuyOrder (para_walutowa, 1))
  391.  
  392.  
  393. */
  394.  
  395. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement