예제 #1
0
파일: config.py 프로젝트: jackcasey/cexbot
def first_run():
	path_config = get_conf_path()
	path_db = get_db_path()
	if not os.path.isdir(ad.user_data_dir):
		os.mkdir(ad.user_data_dir)
	if not os.path.isfile(path_config):
		logging.debug("Writing config at %s" % path_config)
		write_blank(path_config)
	if not os.path.isfile(path_db):
		logging.debug("Writing empty db at: %s" % path_db)
		db = DbManager(path_db)
		db.init()
예제 #2
0
def main(argv=[]):
  args = get_parser()

  verbose = 1
  if args.verbose:
    verbose = 2
  if args.debug:
    verbose = 3

  if verbose>2:
    log_level=logging.DEBUG
  elif verbose==2:
    log_level=logging.INFO
  elif verbose==1:
    log_level=logging.WARNING
  elif verbose<1:
    log_level=logging.ERROR

  logging.basicConfig(level=log_level, format="%(asctime)s %(levelname)s: %(message)s")

  # make sure this is always above command parsing
  cexbot.config.first_run()

  if verbose == 3:
    print args

  if args.command == 'config':
    if args.list:
      return cexbot.config.list()
    elif args.edit:
      return cexbot.config.edit_config()
    elif args.testauth:
      return cexbot.config.test_auth()
    elif args.name and args.value:
      v = cexbot.config.set(args.name, args.value)
      return cexbot.config.cprint(args.name)
    elif args.name:
      return cexbot.config.cprint(args.name)
    logging.error('Invalid config option')
    return 1

  elif args.command == 'update':
    return check_update()

  if args.task == 'cleardata':
    return cexbot.config.clear_userdata()


  config = cexbot.config.get_config()
  ac = CexAPI(config.get('cex', 'username'), config.get('cex', 'apikey'), config.get('cex', 'secret'))
  dbi = DbManager()
  cx = CexMethods(ac, dbi)

  if args.task == 'getbalance':
    logging.info("Balance: %s" % ac.get_balance())
    return True

  if args.task == 'initdb':
    return dbi.initdb()

  if args.task == 'getmarket':
    return ac.get_market()

  if args.task == 'getprice':
    return ac.get_market_quote()

  if args.task == 'order':
    amount = args.amount
    price = args.price
    r = ac.place_order(amount, price)
    logging.info("Ordered: %s" % r)

  if args.task == 'updatequotes':
    logging.info('Running updatequotes')
    ticker_timer = ReqTimer(2, cx.update_ticker)
    ticker_timer.start()

  if args.task == 'buybalance':
    logging.info('Running buybalance')
    balance_timer = ReqTimer(5, ac.buy_balance)
    balance_timer.start()