Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def ticker(exchange, currency):
- try:
- ticker = exchange.fetch_ticker(currency)
- closing = ticker['last']
- timestamp = ticker['timestamp']
- open = ticker['open']
- high = ticker['high']
- low = ticker['low']
- volume = ticker['baseVolume']
- bid = ticker['bid']
- ask = ticker['ask']
- # Check if there is empty values. Sometimes, some apis doesnt have values
- # and this causes problems in database records.
- if not open:
- open = 0
- if not high:
- high = 0
- if not low:
- low = 0
- if not volume:
- volume = 0
- if not bid:
- bid = 0
- if not ask:
- ask = 0
- delta_value = delta(exchange, currency)
- price_delta_1h = delta_value[0]
- price_delta_24h = delta_value[1]
- print(str(exchange.exchangeName) + " " + str(currency) + " Delta 1h: " + str(price_delta_1h))
- print(str(exchange.exchangeName) + " " + str(currency) + " Delta 24h: " + str(price_delta_24h))
- trading_pairs = {
- "trading_pair_id": id_convert(exchange, currency),
- "trading_pair": currency,
- "price": float(closing),
- "price_delta_1h": price_delta_1h,
- "price_delta_24h": price_delta_24h,
- "price_updated_at": timestamp
- }
- database_write(exchange, currency, timestamp, open, high, closing, low, volume, bid, ask)
- sleep(exchange.rateLimit / 1000)
- except (ccxt.ExchangeError, ccxt.AuthenticationError, ccxt.ExchangeNotAvailable, ccxt.RequestTimeout) as error:
- print('Got an error', type(error).__name__, error.args, ', retrying in', hold, 'seconds...')
- sleep(exchange.rateLimit / 1000)
- return trading_pairs
Add Comment
Please, Sign In to add comment