Skip to content

Commit

Permalink
added examples/py/async-gdax-fetch-order-book-continuously.py
Browse files Browse the repository at this point in the history
  • Loading branch information
kroitor committed Dec 12, 2017
1 parent c79a55c commit 3fe90de
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
31 changes: 31 additions & 0 deletions examples/py/async-gdax-fetch-order-book-continuously.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# -*- coding: utf-8 -*-

import asyncio
import os
import sys

root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
sys.path.append(root + '/python')

import ccxt.async as ccxt # noqa: E402


async def main(exchange, symbol):
while True:
print('--------------------------------------------------------------')
print(exchange.iso8601(exchange.milliseconds()), 'fetching', symbol, 'ticker from', exchange.name)
# this can be any call really
ticker = await exchange.fetch_order_book(symbol)
print(exchange.iso8601(exchange.milliseconds()), 'fetched', symbol, 'ticker from', exchange.name)
print(ticker)


# you can set enableRateLimit = True to enable the built-in rate limiter
# this way you request rate will never hit the limit of an exchange
# the library will throttle your requests to avoid that

exchange = ccxt.gdax({
'enableRateLimit': True, # this option enables the built-in rate limiter
})

asyncio.get_event_loop().run_until_complete(main(exchange, 'LTC/USD'))
2 changes: 1 addition & 1 deletion examples/py/async-gdax-fetch-ticker-continuously.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
async def main(exchange, symbol):
while True:
print('--------------------------------------------------------------')
print(exchange.iso8601(exchange.milliseconds()), 'fetchin', symbol, 'ticker from', exchange.name)
print(exchange.iso8601(exchange.milliseconds()), 'fetching', symbol, 'ticker from', exchange.name)
# this can be any call instead of fetch_ticker, really
ticker = await exchange.fetch_ticker(symbol)
print(exchange.iso8601(exchange.milliseconds()), 'fetched', symbol, 'ticker from', exchange.name)
Expand Down

0 comments on commit 3fe90de

Please sign in to comment.