Guest User

Untitled

a guest
Jun 20th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. def ticker(exchange, currency):
  2. try:
  3. ticker = exchange.fetch_ticker(currency)
  4.  
  5. closing = ticker['last']
  6. timestamp = ticker['timestamp']
  7. open = ticker['open']
  8. high = ticker['high']
  9. low = ticker['low']
  10. volume = ticker['baseVolume']
  11. bid = ticker['bid']
  12. ask = ticker['ask']
  13.  
  14. # Check if there is empty values. Sometimes, some apis doesnt have values
  15. # and this causes problems in database records.
  16.  
  17. if not open:
  18. open = 0
  19. if not high:
  20. high = 0
  21. if not low:
  22. low = 0
  23. if not volume:
  24. volume = 0
  25. if not bid:
  26. bid = 0
  27. if not ask:
  28. ask = 0
  29.  
  30. delta_value = delta(exchange, currency)
  31.  
  32. price_delta_1h = delta_value[0]
  33.  
  34. price_delta_24h = delta_value[1]
  35.  
  36. print(str(exchange.exchangeName) + " " + str(currency) + " Delta 1h: " + str(price_delta_1h))
  37. print(str(exchange.exchangeName) + " " + str(currency) + " Delta 24h: " + str(price_delta_24h))
  38.  
  39. trading_pairs = {
  40. "trading_pair_id": id_convert(exchange, currency),
  41. "trading_pair": currency,
  42. "price": float(closing),
  43. "price_delta_1h": price_delta_1h,
  44. "price_delta_24h": price_delta_24h,
  45. "price_updated_at": timestamp
  46. }
  47.  
  48. database_write(exchange, currency, timestamp, open, high, closing, low, volume, bid, ask)
  49.  
  50. sleep(exchange.rateLimit / 1000)
  51. except (ccxt.ExchangeError, ccxt.AuthenticationError, ccxt.ExchangeNotAvailable, ccxt.RequestTimeout) as error:
  52. print('Got an error', type(error).__name__, error.args, ', retrying in', hold, 'seconds...')
  53. sleep(exchange.rateLimit / 1000)
  54. return trading_pairs
Add Comment
Please, Sign In to add comment