Skip to content

Commit b589a57

Browse files
committed
Initial commit
0 parents  commit b589a57

File tree

6 files changed

+591
-0
lines changed

6 files changed

+591
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
.DS_Store

LICENSE

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2014 Premasagar Rose
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.

README.md

+282
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,282 @@
1+
# poloniex.js
2+
3+
An (unofficial) Node.js API client for the [Poloniex][poloniex] cryptocurrency exchange.
4+
5+
The client supports both public (unauthenticated) and private (authenticated) calls to the [Poloniex API][poloniex-api].
6+
7+
For private calls, the user secret is never exposed to other parts of the program or over the Web. The user key is sent as a header to the API, along with a signed request.
8+
9+
Repo home: [github.com/premasagar/poloniex][repo]
10+
11+
12+
## License
13+
14+
MIT, open source. See LICENSE file.
15+
16+
17+
## Setting up the client
18+
19+
Either install via NPM:
20+
21+
npm install poloniex
22+
23+
or clone the repo and install dependencies:
24+
25+
git clone https://github.com/premasagar/poloniex.git
26+
cd poloniex
27+
npm install
28+
29+
30+
In your script, require the module:
31+
32+
var Poloniex = require('poloniex');
33+
34+
Create a new instance of the client. If only public API calls are needed, then no API key or secret is required:
35+
36+
var poloniex = new Poloniex();
37+
38+
To use Poloniex's trading API, [your API key and secret][poloniex-keys] must be provided:
39+
40+
var poloniex = new Poloniex('API_KEY', 'API_SECRET');
41+
42+
43+
## Temporary certificate workaround
44+
45+
Currently, the API server's certficate is rejected. This is presumably a temporary issue and has been reported to Poloniex. The line below is a temporary workaround. First try using the client without this line.
46+
47+
Poloniex.STRICT_SSL = false;
48+
49+
50+
## Making API calls
51+
52+
All [Poloniex API][poloniex-api] methods are supported (with some name changes to avoid naming collisions). All methods require a callback function.
53+
54+
The callback is passed two arguments:
55+
56+
1. An error object, or `null` if the API request was successful
57+
2. A data object, the response from the API
58+
59+
For the most up-to-date API documentation, see [poloniex.com/api][poloniex-api].
60+
61+
62+
## Public API methods
63+
64+
These methods do not require a user key or secret.
65+
66+
67+
### getTicker(callback)
68+
69+
Returns the ticker for all markets.
70+
Calls API method `returnTicker`.
71+
72+
poloniex.getTicker(function(err, data){
73+
if (err){
74+
// handle error
75+
}
76+
77+
console.log(data);
78+
});
79+
80+
81+
Example response:
82+
83+
{"BTC_LTC":"0.026","BTC_NXT":"0.00007600", ... }
84+
85+
86+
### get24hVolume(callback)
87+
88+
Returns the 24-hour volume for all markets, plus totals for primary currencies.
89+
Calls API method `return24hVolume`.
90+
91+
poloniex.get24hVolume(function(err, data){
92+
if (err){
93+
// handle error
94+
}
95+
96+
console.log(data);
97+
});
98+
99+
100+
Example response:
101+
102+
{"BTC_LTC":{"BTC":"2.23248854","LTC":"87.10381314"},"BTC_NXT":{"BTC":"0.981616","NXT":"14145"}, ... "totalBTC":"81.89657704","totalLTC":"78.52083806"}
103+
104+
105+
### getOrderBook(currencyA, currencyB, callback)
106+
107+
Returns the order book for a given market.
108+
Calls API method `returnOrderBook`.
109+
110+
poloniex.getOrderBook('VTC', 'BTC', function(err, data){
111+
if (err){
112+
// handle error
113+
}
114+
115+
console.log(data);
116+
});
117+
118+
119+
Example response:
120+
121+
{"asks":[[0.00007600,1164],[0.00007620,1300], ... "bids":[[0.00006901,200],[0.00006900,408], ... }
122+
123+
124+
### getTradeHistory(currencyA, currencyB, callback)
125+
126+
Returns the past 200 trades for a given market.
127+
Calls API method `returnTradeHistory`.
128+
129+
poloniex.getTradeHistory('VTC', 'BTC', function(err, data){
130+
if (err){
131+
// handle error
132+
}
133+
134+
console.log(data);
135+
});
136+
137+
138+
Example response:
139+
140+
[{"date":"2014-02-10 04:23:23","type":"buy","rate":"0.00007600","amount":"140","total":"0.01064"},{"date":"2014-02-10 01:19:37","type":"buy","rate":"0.00007600","amount":"655","total":"0.04978"}, ... ]
141+
142+
143+
144+
## Private, trading API methods
145+
146+
These methods require the user key and secret.
147+
148+
149+
### myBalances(callback)
150+
151+
Returns all of your balances.
152+
Calls API method `returnBalances`.
153+
154+
poloniex.myBalances(function(err, data){
155+
if (err){
156+
// handle error
157+
}
158+
159+
console.log(data);
160+
});
161+
162+
163+
Example response:
164+
165+
{"BTC":"0.59098578","LTC":"3.31117268", ... }
166+
167+
168+
### myOpenOrders(currencyA, currencyB, callback)
169+
170+
Returns your open orders for a given market, specified by the currency pair.
171+
Calls API method `returnOpenOrders`.
172+
173+
poloniex.myOpenOrders('VTC', 'BTC', function(err, data){
174+
if (err){
175+
// handle error
176+
}
177+
178+
console.log(data);
179+
});
180+
181+
182+
Example response:
183+
184+
[{"orderNumber":"120466","type":"sell","rate":"0.025","amount":"100","total":"2.5"},{"orderNumber":"120467","type":"sell","rate":"0.04","amount":"100","total":"4"}, ... ]
185+
186+
187+
### myTradeHistory(currencyA, currencyB, callback)
188+
189+
Returns your trade history for a given market, specified by the currency pair.
190+
Calls API method `returnTradeHistory`.
191+
192+
poloniex.myTradeHistory('VTC', 'BTC', function(err, data){
193+
if (err){
194+
// handle error
195+
}
196+
197+
console.log(data);
198+
});
199+
200+
201+
Example response:
202+
203+
[{"date":"2014-02-19 03:44:59","rate":"0.0011","amount":"99.9070909","total":"0.10989779","type":"sell"},{"date":"2014-02-19 04:55:44","rate":"0.0015","amount":"100","total":"0.15","type":"sell"}, ... ]
204+
205+
206+
### buy(currencyA, currencyB, rate, amount, callback)
207+
208+
Places a buy order in a given market.
209+
210+
poloniex.buy('VTC', 'BTC', 0.1, 100, function(err, data){
211+
if (err){
212+
// handle error
213+
}
214+
215+
console.log(data);
216+
});
217+
218+
219+
Example response:
220+
221+
{"orderNumber":170675}
222+
223+
224+
### sell(currencyA, currencyB, rate, amount, callback)
225+
226+
Places a sell order in a given market.
227+
228+
poloniex.sell('VTC', 'BTC', 0.1, 100, function(err, data){
229+
if (err){
230+
// handle error
231+
}
232+
233+
console.log(data);
234+
});
235+
236+
237+
Example response:
238+
239+
{"orderNumber":170675}
240+
241+
242+
### cancelOrder(currencyA, currencyB, orderNumber, callback)
243+
244+
Cancels an order you have placed in a given market.
245+
246+
poloniex.cancelOrder('VTC', 'BTC', 170675, function(err, data){
247+
if (err){
248+
// handle error
249+
}
250+
251+
console.log(data);
252+
});
253+
254+
255+
Example response:
256+
257+
{"success":1}
258+
259+
260+
### withdraw(currency, amount, address, callback)
261+
262+
Returns your open orders for a given market, specified by the currency pair.
263+
264+
poloniex.myOpenOrders('BTC', 0.01, '17Hzfoobar', function(err, data){
265+
if (err){
266+
// handle error
267+
}
268+
269+
console.log(data);
270+
});
271+
272+
273+
Example response:
274+
275+
{"response":"Withdrew 2398 NXT."}
276+
277+
278+
279+
[repo]: https://github.com/premasagar/poloniex
280+
[poloniex]: https://poloniex.com
281+
[poloniex-api]: https://poloniex.com/api
282+
[poloniex-keys]: https://poloniex.com/apiKeys

example.js

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
var Poloniex = require('./lib/poloniex'),
2+
// When using as an NPM module, use `require('poloniex')`
3+
4+
// Create a new instance, with optional API key and secret
5+
poloniex = new Poloniex(
6+
// 'API_KEY',
7+
// 'API_SECRET'
8+
);
9+
10+
11+
// * IMPORTANT *
12+
// The line below is temporary, to avoid API server certficiate failure `Error: CERT_UNTRUSTED`
13+
// This is presumably a temporary issue and has been reported to Poloniex.
14+
// Do not include the line below once the issue is resolved.
15+
Poloniex.STRICT_SSL = false;
16+
17+
18+
// Public call
19+
poloniex.getTicker(function(err, data){
20+
if (err){
21+
console.log('ERROR', err);
22+
return;
23+
}
24+
25+
console.log(data);
26+
});
27+
28+
29+
// Private call - requires API key and secret
30+
/*
31+
poloniex.buy('VTC', 'BTC', 0.1, 100, function(err, data){
32+
if (err){
33+
console.log('ERROR', err);
34+
return;
35+
}
36+
37+
console.log(data);
38+
});
39+
*/

0 commit comments

Comments
 (0)