Guest User

Untitled

a guest
May 20th, 2018
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. import ccxt
  2. # import library with exchange classes
  3. import couchdb
  4. # import library for connecting to database
  5. import time
  6. # needed for limiting api call
  7.  
  8. # connect to couchdb server
  9. couch = couchdb.Server()
  10.  
  11. """
  12. # get trading pairs
  13. def get_trading_pairs( mode = 0 ):
  14. if( mode == 0 ):
  15. # read configuration file
  16. elif( mode == 1 ):
  17. # get 24h volume rankings by currency
  18. """
  19.  
  20. trading_pairs = ['BTC/USD', 'BTC/EUR', 'BTC/USDT', 'XRP/USD', 'XRP/USDT', 'LTC/USD', 'LTC/USDT']
  21. exchanges = [ ccxt.bitstamp(), ccxt.bitfinex(), ccxt.gdax(), ccxt.okex() ]
  22.  
  23. # checkIfDBExists checks if there is designated database for trading pairs and if not creates it
  24. def check_if_DB_exists( couchDBServer, trading_symbol = "BTC/USD" ):
  25. if( trading_symbol not in couchDBServer ):
  26. couchDBServer.create(trading_symbol)
  27.  
  28. # check_if_exch_has_market checks if trading pair exists on exchange
  29. # return true if it does, false if it doesn't
  30. def check_if_exch_has_market( exchange, trading_symbol = "BTC/USD" ):
  31. # get all markets from exchange
  32. available_markets = exchange.load_markets()
  33.  
  34. # check if trading pair exists on exchange
  35. if((trading_symbol in available_markets)):
  36. return True
  37. else:
  38. return False
  39.  
  40. # write_data_to_database
  41. def write_data_to_database( data, couchDBServer, trading_symbol = "BTC/USD" ):
  42. couchDBServer[trading_symbol].save(data)
  43. """
  44. for pair in trading_pairs:
  45. check_if_DB_exists(couch, pair)
  46. """
  47. exchange_pair_list = {}
  48. exchange_pairs
  49.  
  50. for exchange in exchanges:
  51. #print(exchange.name)
  52. exchange_pair_list.append( exchange.name )
  53.  
  54. for pair in trading_pairs:
  55. if( check_if_exch_has_market(exchange, pair) ):
  56. print("Found trading pair %s in exchange: %s" % (pair, exchange.name))
Add Comment
Please, Sign In to add comment