Skip to content
Permalink
Browse files

rate limiting edits

  • Loading branch information
kroitor committed Feb 14, 2020
1 parent 9159045 commit 0583f322131089d022afd07d0b01f6e074fc57b9
Showing with 3 additions and 25 deletions.
  1. +0 −1 examples/js/live-ticker.js
  2. +3 −3 examples/py/async-basic.py
  3. +0 −1 js/base/Exchange.js
  4. +0 −20 python/ccxt/async_support/base/exchange.py
@@ -26,7 +26,6 @@ let printTicker = async (id, symbol, rateLimit = undefined) => {
let exchange = new ccxt[id] ({ enableRateLimit: true, })

exchange.rateLimit = rateLimit ? rateLimit : exchange.rateLimit
exchange.tokenBucket.refillRate = 1 / exchange.rateLimit

log.green ('Rate limit:', exchange.rateLimit.toString ().bright)

@@ -11,9 +11,9 @@


async def test_binance():
binance = ccxt.binance()
markets = await binance.load_markets()
await binance.close()
exchange = ccxt.binance({'enableRateLimit': True)
markets = await exchange.load_markets()
await exchange.close()
return markets

if __name__ == '__main__':
@@ -367,7 +367,6 @@ module.exports = class Exchange {
throw new Error (this.id + '.rateLimit property is not configured')

this.tokenBucket = this.extend ({
refillRate: 1 / this.rateLimit,
delay: 1,
capacity: 1,
defaultCost: 1,
@@ -87,26 +87,6 @@ def open(self):
await self.session.close()
self.session = None

async def wait_for_token(self):
while self.rateLimitTokens <= 1:
# if self.verbose:
# print('Waiting for tokens: Exchange: {0}'.format(self.id))
self.add_new_tokens()
seconds_delays = [0.001, 0.005, 0.022, 0.106, 0.5]
delay = random.choice(seconds_delays)
await asyncio.sleep(delay)
self.rateLimitTokens -= 1

def add_new_tokens(self):
# if self.verbose:
# print('Adding new tokens: Exchange: {0}'.format(self.id))
now = time.monotonic()
time_since_update = now - self.rateLimitUpdateTime
new_tokens = math.floor((0.8 * 1000.0 * time_since_update) / self.rateLimit)
if new_tokens > 1:
self.rateLimitTokens = min(self.rateLimitTokens + new_tokens, self.rateLimitMaxTokens)
self.rateLimitUpdateTime = now

async def fetch2(self, path, api='public', method='GET', params={}, headers=None, body=None):
"""A better wrapper over request for deferred signing"""
if self.enableRateLimit:

0 comments on commit 0583f32

Please sign in to comment.
You can’t perform that action at this time.