CCXT-readme-15.js
· 1.5 KiB · JavaScript
Eredeti
// cjs example
'use strict';
const ccxt = require ('ccxt');
(async function () {
let kraken = new ccxt.kraken ()
let bitfinex = new ccxt.bitfinex ({ verbose: true })
let huobipro = new ccxt.huobipro ()
let okcoinusd = new ccxt.okcoin ({
apiKey: 'YOUR_PUBLIC_API_KEY',
secret: 'YOUR_SECRET_PRIVATE_KEY',
})
const exchangeId = 'binance'
, exchangeClass = ccxt[exchangeId]
, exchange = new exchangeClass ({
'apiKey': 'YOUR_API_KEY',
'secret': 'YOUR_SECRET',
})
console.log (kraken.id, await kraken.loadMarkets ())
console.log (bitfinex.id, await bitfinex.loadMarkets ())
console.log (huobipro.id, await huobipro.loadMarkets ())
console.log (kraken.id, await kraken.fetchOrderBook (kraken.symbols[0]))
console.log (bitfinex.id, await bitfinex.fetchTicker ('BTC/USD'))
console.log (huobipro.id, await huobipro.fetchTrades ('ETH/USDT'))
console.log (okcoinusd.id, await okcoinusd.fetchBalance ())
// sell 1 BTC/USD for market price, sell a bitcoin for dollars immediately
console.log (okcoinusd.id, await okcoinusd.createMarketSellOrder ('BTC/USD', 1))
// buy 1 BTC/USD for $2500, you pay $2500 and receive ฿1 when the order is closed
console.log (okcoinusd.id, await okcoinusd.createLimitBuyOrder ('BTC/USD', 1, 2500.00))
// pass/redefine custom exchange-specific order params: type, amount, price or whatever
// use a custom order type
bitfinex.createLimitSellOrder ('BTC/USD', 1, 10, { 'type': 'trailing-stop' })
}) ();
1 | // cjs example |
2 | 'use strict'; |
3 | const 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 | }) (); |