Skip to content

Commit 70d74da

Browse files
committed
okx fetchMyTrades() ratelimit
1 parent 490e835 commit 70d74da

File tree

4 files changed

+102
-53
lines changed

4 files changed

+102
-53
lines changed

examples/js/okx-poll-rate-limit.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import ccxt from '../../js/ccxt.js'
2+
3+
console.log ('CCXT Version:', ccxt.version)
4+
5+
async function main () {
6+
7+
const exchange = new ccxt.okx ({
8+
9+
// edit for your credentials
10+
'apiKey': 'YOUR_API_KEY',
11+
'secret': 'YOUR_API_SECRET',
12+
'password': 'YOUR_API_PASSWORD',
13+
14+
'api': {
15+
'private': {
16+
'get': {
17+
'trade/fills-history': 2.1,
18+
},
19+
},
20+
},
21+
22+
})
23+
24+
await exchange.loadMarkets ()
25+
26+
// if this script fails with a rate limiter error
27+
// uncomment the following line for debugging purposes
28+
29+
// exchange.verbose = true
30+
31+
const promises=[];
32+
for(let i=0;i<100;i++){
33+
promises.push(exchange.fetchMyTrades());
34+
}
35+
36+
const allResponses = await Promise.allSettled(promises);
37+
allResponses.forEach((result, i) => {
38+
39+
if(result.status == "fulfilled"){
40+
console.log (new Date(), i + 6, 'fetched', result.value.length, 'trades')
41+
} else {
42+
console.log ("Rejected:", i + 6, result.reason);
43+
}
44+
});
45+
46+
}
47+
48+
main ()

package-lock.json

Lines changed: 24 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

postinstall.js

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,28 @@ for (let color of Object.keys (colors)) {
2020
}
2121

2222
let ascii = [
23-
' ',
24-
' ',
25-
' ████████████████████████████████████ ',
26-
' ████████████████████████████████████ ',
27-
' ████ ████ ████ ',
28-
' ████ ████ ████ ',
29-
' ████ ████████████ ████████████ ',
30-
' ████ ████████████ ████████████ ',
31-
' ████ ████ ████ ',
32-
' ████ ████ ████ ',
33-
' ████████████████████████████████████ ',
34-
' ████████████████████████████████████ ',
35-
' ████ ████ ████ ████ ',
36-
' ████ ████ ████ ████ ',
37-
' ████████ ████████████ ████████ ',
38-
' ████████ ████████████ ████████ ',
39-
' ████ ████ ████████ ████████ ',
40-
' ████ ████ ████████ ████████ ',
41-
' ████████████████████████████████████ ',
42-
' ████████████████████████████████████ ',
43-
' ',
44-
' ',
23+
' ',
24+
' ',
25+
' ████████████████████████████████████ ',
26+
' ████████████████████████████████████ ',
27+
' ████ ████ ████ ',
28+
' ████ ████ ████ ',
29+
' ████ ████████████ ████████████ ',
30+
' ████ ████████████ ████████████ ',
31+
' ████ ████ ████ ',
32+
' ████ ████ ████ ',
33+
' ████████████████████████████████████ ',
34+
' ████████████████████████████████████ ',
35+
' ████ ████ ████ ████ ',
36+
' ████ ████ ████ ████ ',
37+
' ████████ ████████████ ████████ ',
38+
' ████████ ████████████ ████████ ',
39+
' ████ ████ ████████ ████████ ',
40+
' ████ ████ ████████ ████████ ',
41+
' ████████████████████████████████████ ',
42+
' ████████████████████████████████████ ',
43+
' ',
44+
' ',
4545
]
4646

4747
async function getData () {

wiki/Manual.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ Most exchanges allow **up to 1 or 2 requests per second**. Exchanges may tempora
522522
523523
The CCXT library has a built-in experimental rate-limiter that will do the necessary throttling in background transparently to the user. **WARNING: users are responsible for at least some type of rate-limiting: either by implementing a custom algorithm or by doing it with the built-in rate-limiter.**.
524524
525-
Turn on/off the built-in rate-limiter with `.enableRateLimit` property, like so:
525+
You can turn on/off the built-in rate-limiter with `.enableRateLimit` property, like so:
526526
527527
```javascript
528528
// JavaScript
@@ -573,15 +573,16 @@ In case your calls hit a rate limit or get nonce errors, the ccxt library will t
573573
A later retry is usually enough to handle that.
574574
575575
### Notes On Rate Limiter
576+
#### One Rate Limiter Per Each Exchange Instance
576577
577578
The rate limiter is a property of the exchange instance, in other words, each exchange instance has its own rate limiter that is not aware of the other instances. In many cases the user should reuse the same exchange instance throughout the program. Do not use multiple instances of the same exchange with the same API keypair from the same IP address.
578579
579580
```javascript
580581
// DO NOT DO THIS!
581582
582-
const binance1 = new ccxt.binance ({ enableRateLimit: true })
583-
const binance2 = new ccxt.binance ({ enableRateLimit: true })
584-
const binance3 = new ccxt.binance ({ enableRateLimit: true })
583+
const binance1 = new ccxt.binance ()
584+
const binance2 = new ccxt.binance ()
585+
const binance3 = new ccxt.binance ()
585586
586587
while (true) {
587588
const result = await Promise.all ([
@@ -598,7 +599,7 @@ Reuse the exchange instance as much as possible as shown below:
598599
```javascript
599600
// DO THIS INSTEAD:
600601
601-
const binance = new ccxt.binance ({ enableRateLimit: true })
602+
const binance = new ccxt.binance ()
602603
603604
while (true) {
604605
const result = await Promise.all ([
@@ -616,7 +617,7 @@ Since the rate limiter belongs to the exchange instance, destroying the exchange
616617
// DO NOT DO THIS!
617618
618619
async function tick () {
619-
const exchange = new ccxt.binance ({ enableRateLimit: true })
620+
const exchange = new ccxt.binance ()
620621
const response = await exchange.fetchOrderBook ('BTC/USDT')
621622
// ... some processing here ...
622623
return response
@@ -639,7 +640,7 @@ async function tick (exchange) {
639640
return response
640641
}
641642
642-
const exchange = new ccxt.binance ({ enableRateLimit: true })
643+
const exchange = new ccxt.binance ()
643644
while (true) {
644645
const result = await tick (exchange)
645646
console.log (result)

0 commit comments

Comments
 (0)