-
Notifications
You must be signed in to change notification settings - Fork 10
/
examples.js
83 lines (63 loc) · 2.66 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
72
73
74
75
76
77
78
79
80
81
82
83
var OKCoin = require('okcoin');
// Test public data APIs
var publicClient = new OKCoin();
// get BTCUSD ticker
//publicClient.getTicker(logResponse, 'btc_usd');
// get BTCUSD order book
//publicClient.getDepth(logResponse, 'btc_usd');
// get trades defaulting to BTCUSD
//publicClient.getTrades(logResponse);
// get LTCUSD trades
//publicClient.getTrades(logResponse, 'ltc_usd');
// get trades since trade id 2209328
//publicClient.getTrades(logResponse, 'btc_usd', 2219111);
// 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.
var key = process.argv[2] || 'your-api-key';
var secret = process.argv[3] || 'your-api-secret';
var privateClient = new OKCoin(key, secret);
// uncomment the API you want to test.
// Be sure to check the parameters so you don't do any unwanted live trades
//privateClient.getUserInfo(logResponse);
// limit orders
//privateClient.addTrade(logResponse, 'btc_usd', 'buy', '0.01', '100');
//privateClient.addTrade(logResponse, 'btc_usd', 'sell', '0.01', '900');
// market orders
// market buy of 25 USD
//privateClient.addTrade(logResponse, 'btc_usd', 'buy_market', null, '2.5');
// market sell of 0.01 BTC
//privateClient.addTrade(logResponse, 'btc_usd', 'sell_market', '0.01');
//privateClient.cancelOrder(logResponse, 'btc_usd', 1);
//privateClient.getOrderInfo(logResponse, 'btc_usd', '31947122');
// get all open orders
//privateClient.getOrderInfo(logResponse, 'btc_usd', '-1');
// get all open orders
//privateClient.getOrdersInfo(logResponse, 'btc_usd', 0, '31947122,31941934');
// get all filled orders
privateClient.getOrdersInfo(logResponse, 'btc_usd', 0, '31947122,31941934');
// get the first 20 unfilled orders
//privateClient.getOrderHistory(logResponse, 'btc_usd', 0, 1, 20);
// get the first 20 filled orders
//privateClient.getOrderHistory(logResponse, 'btc_usd', 1, 1, 20);
// get the third 20 filled orders
//privateClient.getOrderHistory(logResponse, 'btc_usd', 1, 3, 20);
// get the first 5 account deposits
//privateClient.getAccountRecords(logResponse, 'btc_usd', 0, 1, 5);
// get the second 5 account deposits
//privateClient.getAccountRecords(logResponse, 'btc_usd', 0, 2, 5);
// get the first 5 account withdrawals
//privateClient.getAccountRecords(logResponse, 'btc_usd', 1, 1, 5);
// get historical trades
//privateClient.getTradeHistory(logResponse, 'btc_usd', 1);
function logResponse(err, data)
{
if (err)
{
console.log('error name %s', err.name);
console.log('error message %s', err);
}
console.log('\ndata: %s', JSON.stringify(data));
}