-
Notifications
You must be signed in to change notification settings - Fork 7
/
examples.js
71 lines (71 loc) · 4.37 KB
/
examples.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//const BTCMarkets = require('btc-markets').default; // if you are using JavaScript
// import BTCMarkets from 'btc-markets'; // if you are using TypeScript or Babel
const index_1 = require("./index"); // used for testing inside the BTC Markets library
// Either pass your API key and secret as the first and second parameters to examples.js. eg
// node examples.js your-api-key your-api-secret
//
// Or enter them below.
// WARNING never commit your API keys into a public repository.
const key = process.argv[2] || 'your-api-key';
const secret = process.argv[3] || 'your-api-secret';
const client = new index_1.default(key, secret);
async function tests() {
try {
// get latest prices
const tick = await client.getTick("BTC", "AUD");
console.log(`Tick: ${JSON.stringify(tick)}`);
// get order book
const orderBook = await client.getOrderBook("BTC", "AUD");
console.log('Order Book has ' + orderBook.asks.length + ' asks with best ask having price ' +
orderBook.asks[0][0] + ' and amount ' + orderBook.asks[0][1]);
console.log(`OrderBook: ${JSON.stringify(orderBook)}`);
// get market trades since 728992317
const trades = await client.getTrades("BTC", "AUD", 728992317);
console.log(`Trades: ${JSON.stringify(trades)}`);
// limit buy order for of 0.001 ETH at 50 AUD
const limitOrder = await client.createOrder("ETH", "AUD", 50 * index_1.default.numberConverter, 0.001 * index_1.default.numberConverter, 'Bid', 'Limit', "10001");
console.log(`Limit order: ${JSON.stringify(limitOrder)}`);
//market sell for 0.001 BTC
const marketOrder = await client.createOrder("BTC", "AUD", null, 0.001 * index_1.default.numberConverter, 'Ask', 'Market', null);
console.log(`Market order: ${JSON.stringify(marketOrder)}`);
// limit buy order for of 0.001 ETH at 50 AUD with 40 AUD stop loss
const stopLossOrder = await client.createOrder("ETH", "AUD", 50 * index_1.default.numberConverter, 0.001 * index_1.default.numberConverter, 'Bid', 'Stop Limit', "10002", 40 * index_1.default.numberConverter);
console.log(`Stop loss order: ${JSON.stringify(stopLossOrder)}`);
// cancel two limit orders with id's 1132477709 and 1133590603
const cancelledOrders = await client.cancelOrders([1132477709, 1133590603]);
console.log(`Cancelled order ${JSON.stringify(cancelledOrders)}`);
const accountBalances = await client.getAccountBalances();
console.log(`Account balances: ${JSON.stringify(accountBalances)}`);
// get trading fee for a trading pair
const tradingFee = await client.getTradingFee("BTC", "AUD");
console.log(`Trading fee: ${JSON.stringify(tradingFee)}`);
// get order details
const orderDetails = await client.getOrderDetail([206855175, 23988196]);
console.log(`Order details: ${JSON.stringify(orderDetails)}`);
// get all trades since the start of time
const tradeHistory = await client.getTradeHistory("BTC", "AUD", undefined, null);
console.log(`Trade history ${JSON.stringify(tradeHistory)}`);
// get 50 orders since the start of time
const orderHistory = await client.getOrderHistory("BTC", "AUD", 50, null);
console.log(`Order history: ${JSON.stringify(orderHistory)}`);
// get my open orders
const openOrders = await client.getOpenOrders('BTC', 'AUD', 10, null);
console.log(`Open orders: ${JSON.stringify(openOrders)}`);
// withdrawal 0.05 ETH
const cryptoWithdrawal = await client.withdrawCrypto(0.05 * index_1.default.numberConverter, "0x775053A6125cB51e618Eb132f00E93d6033934AD", "ETH");
console.log(`Crypto withdrawal: ${JSON.stringify(cryptoWithdrawal)}`);
// withdrawal history with default params
const defaultWithdrawHistory = await client.withdrawHistory(null, null, null);
console.log(`Withdrawal history: ${JSON.stringify(defaultWithdrawHistory)}`);
// withdrawal history with params
const withdrawHistory = await client.withdrawHistory(10, 0, true);
console.log(`Withdrawal history: ${JSON.stringify(withdrawHistory)}`);
}
catch (err) {
console.log(`Something when wrong in the examples. Error: ${err.message}`);
}
}
tests();
//# sourceMappingURL=examples.js.map