Ultima attività 1729055573

CCXT-readme-15.js Raw
1// cjs example
2'use strict';
3const ccxt = require ('ccxt');
4
5(async function () {
6 let kraken = new ccxt.kraken ()
7 let bitfinex = new ccxt.bitfinex ({ verbose: true })
8 let huobipro = new ccxt.huobipro ()
9 let okcoinusd = new ccxt.okcoin ({
10 apiKey: 'YOUR_PUBLIC_API_KEY',
11 secret: 'YOUR_SECRET_PRIVATE_KEY',
12 })
13
14 const exchangeId = 'binance'
15 , exchangeClass = ccxt[exchangeId]
16 , exchange = new exchangeClass ({
17 'apiKey': 'YOUR_API_KEY',
18 'secret': 'YOUR_SECRET',
19 })
20
21 console.log (kraken.id, await kraken.loadMarkets ())
22 console.log (bitfinex.id, await bitfinex.loadMarkets ())
23 console.log (huobipro.id, await huobipro.loadMarkets ())
24
25 console.log (kraken.id, await kraken.fetchOrderBook (kraken.symbols[0]))
26 console.log (bitfinex.id, await bitfinex.fetchTicker ('BTC/USD'))
27 console.log (huobipro.id, await huobipro.fetchTrades ('ETH/USDT'))
28
29 console.log (okcoinusd.id, await okcoinusd.fetchBalance ())
30
31 // sell 1 BTC/USD for market price, sell a bitcoin for dollars immediately
32 console.log (okcoinusd.id, await okcoinusd.createMarketSellOrder ('BTC/USD', 1))
33
34 // buy 1 BTC/USD for $2500, you pay $2500 and receive ฿1 when the order is closed
35 console.log (okcoinusd.id, await okcoinusd.createLimitBuyOrder ('BTC/USD', 1, 2500.00))
36
37 // pass/redefine custom exchange-specific order params: type, amount, price or whatever
38 // use a custom order type
39 bitfinex.createLimitSellOrder ('BTC/USD', 1, 10, { 'type': 'trailing-stop' })
40
41}) ();