Esempio n. 1
0
def main():
  candidates = ['bootstrap.ini']
  if len(sys.argv) > 1:
    candidates.append(sys.argv[1])

  config = ConfigParser.SafeConfigParser()
  config.read( candidates )

  from trade.models import Base, Currency, Instrument, User, Broker, DepositMethods
  db_engine = config.get('database','sqlalchemy_engine') + ':///' + os.path.expanduser(config.get('database','sqlalchemy_connection_string'))
  engine = create_engine( db_engine, echo=True)

  Base.metadata.create_all(engine)


  session = scoped_session(sessionmaker(bind=engine))

  for section_name in config.sections():
    if section_name == 'currencies':
      for id, currency_json in config.items(section_name):
        c = json.loads(currency_json)

        if Currency.get_currency(session,c[0]) :
          continue
        e = Currency(code                 = c[0],
                     sign                 = c[1],
                     description          = c[2],
                     is_crypto            = c[3],
                     pip                  = c[4],
                     format_python        = c[5],
                     format_js            = c[6],
                     human_format_python  = c[7],
                     human_format_js      = c[8] )
        session.add(e)
        session.commit()


    if section_name == 'instruments':
      for id, instrument_json in config.items(section_name):
        currency_description = json.loads(instrument_json)

        if Instrument.get_instrument(session, currency_description[0]):
          continue

        e = Instrument(symbol=currency_description[0],
                       currency=currency_description[1],
                       description=currency_description[2])
        session.add(e)
        session.commit()

    if section_name[:4] == 'user':
      broker_id = None
      try:
        broker_id = config.getint(section_name, 'broker_id')
      except Exception,e:
        pass

      broker_username = None
      try:
        broker_username = config.get(section_name, 'broker_username')
      except Exception,e:
        pass


      if not User.get_user(session,broker_id, config.get(section_name, 'username')):
        password = base64.b32encode(os.urandom(10))
        try:
          password = config.get(section_name, 'password')
        except Exception,e:
          pass

        transaction_fee_buy = None
        try:
          transaction_fee_buy = config.getint(section_name, 'transaction_fee_buy')
        except Exception,e:
          pass
Esempio n. 2
0
def main():
    candidates = ['bootstrap.ini']
    if len(sys.argv) > 1:
        candidates.append(os.path.expanduser(sys.argv[1]))

    config = ConfigParser.SafeConfigParser()
    config.read(candidates)

    from trade.models import Base, Currency, Instrument, User, Broker, DepositMethods
    db_engine = config.get(
        'database', 'sqlalchemy_engine') + ':///' + os.path.expanduser(
            config.get('database', 'sqlalchemy_connection_string'))
    engine = create_engine(db_engine, echo=True)
    #engine.raw_connection().connection.text_factory = str

    Base.metadata.create_all(engine)

    session = scoped_session(sessionmaker(bind=engine))

    for section_name in config.sections():
        if section_name == 'currencies':
            for id, currency_json in config.items(section_name):
                c = json.loads(currency_json)

                if Currency.get_currency(session, c[0]):
                    continue
                e = Currency(code=c[0],
                             sign=c[1],
                             description=c[2],
                             is_crypto=c[3],
                             pip=c[4],
                             format_python=c[5],
                             format_js=c[6],
                             human_format_python=c[7],
                             human_format_js=c[8])
                session.add(e)
                session.commit()

        if section_name == 'instruments':
            for id, instrument_json in config.items(section_name):
                currency_description = json.loads(instrument_json)

                if Instrument.get_instrument(session, currency_description[0]):
                    continue

                e = Instrument(symbol=currency_description[0],
                               market=currency_description[1],
                               currency=currency_description[2],
                               description=currency_description[3])
                session.add(e)
                session.commit()

        if section_name[:4] == 'user':
            broker_id = None
            try:
                broker_id = config.getint(section_name, 'broker_id')
            except Exception, e:
                pass

            broker_username = None
            try:
                broker_username = config.get(section_name, 'broker_username')
            except Exception, e:
                pass

            if not User.get_user(session, broker_id,
                                 config.get(section_name, 'username')):
                password = base64.b32encode(os.urandom(10))
                try:
                    password = config.get(section_name, 'password')
                except Exception, e:
                    pass

                transaction_fee_buy = None
                try:
                    transaction_fee_buy = config.getint(
                        section_name, 'transaction_fee_buy')
                except Exception, e:
                    pass
Esempio n. 3
0
def main():
    candidates = ['bootstrap.ini']
    if len(sys.argv) > 1:
        candidates.append(sys.argv[1])

    config = ConfigParser.SafeConfigParser()
    config.read(candidates)

    options.define('db_engine', config.get('database', 'db_engine'))
    options.define('db_echo', True)

    from trade.models import engine, Currency, Instrument, User, Broker, DepositMethods
    session = scoped_session(sessionmaker(bind=engine))

    for section_name in config.sections():
        if section_name == 'currencies':
            for id, currency_json in config.items(section_name):
                c = json.loads(currency_json)

                if Currency.get_currency(session, c[0]):
                    continue
                e = Currency(code=c[0],
                             sign=c[1],
                             description=c[2],
                             is_crypto=c[3],
                             pip=c[4],
                             format_python=c[5],
                             format_js=c[6],
                             human_format_python=c[7],
                             human_format_js=c[8])
                session.add(e)
                session.commit()

        if section_name == 'instruments':
            for id, instrument_json in config.items(section_name):
                currency_description = json.loads(instrument_json)

                if Instrument.get_instrument(session, currency_description[0]):
                    continue

                e = Instrument(symbol=currency_description[0],
                               currency=currency_description[1],
                               description=currency_description[2])
                session.add(e)
                session.commit()

        if section_name[:4] == 'user':
            if not User.get_user(session, config.get(section_name,
                                                     'username')):
                broker_id = None
                broker_username = None
                password = base64.b32encode(os.urandom(10))
                transaction_fee_buy = None
                transaction_fee_sell = None
                verified = 0
                is_system = False
                is_staff = False
                is_broker = False
                state = None

                try:
                    broker_id = config.getint(section_name, 'broker_id')
                except Exception, e:
                    pass

                try:
                    broker_username = config.get(section_name,
                                                 'broker_username')
                except Exception, e:
                    pass

                try:
                    password = config.get(section_name, 'password')
                except Exception, e:
                    pass

                try:
                    transaction_fee_buy = config.getint(
                        section_name, 'transaction_fee_buy')
                except Exception, e:
                    pass
Esempio n. 4
0
def main():
    candidates = ["bootstrap.ini"]
    if len(sys.argv) > 1:
        candidates.append(sys.argv[1])

    config = ConfigParser.SafeConfigParser()
    config.read(candidates)

    options.define("db_engine", config.get("database", "db_engine"))
    options.define("db_echo", True)

    from trade.models import engine, Currency, Instrument, User, Broker, DepositMethods

    session = scoped_session(sessionmaker(bind=engine))

    for section_name in config.sections():
        if section_name == "currencies":
            for id, currency_json in config.items(section_name):
                c = json.loads(currency_json)

                if Currency.get_currency(session, c[0]):
                    continue
                e = Currency(
                    code=c[0],
                    sign=c[1],
                    description=c[2],
                    is_crypto=c[3],
                    pip=c[4],
                    format_python=c[5],
                    format_js=c[6],
                    human_format_python=c[7],
                    human_format_js=c[8],
                )
                session.add(e)
                session.commit()

        if section_name == "instruments":
            for id, instrument_json in config.items(section_name):
                currency_description = json.loads(instrument_json)

                if Instrument.get_instrument(session, currency_description[0]):
                    continue

                e = Instrument(
                    symbol=currency_description[0],
                    currency=currency_description[1],
                    description=currency_description[2],
                )
                session.add(e)
                session.commit()

        if section_name[:4] == "user":
            if not User.get_user(session, config.get(section_name, "username")):
                broker_id = None
                broker_username = None
                password = base64.b32encode(os.urandom(10))
                transaction_fee_buy = None
                transaction_fee_sell = None
                verified = 0
                is_system = False
                is_staff = False
                is_broker = False
                state = None

                try:
                    broker_id = config.getint(section_name, "broker_id")
                except Exception, e:
                    pass

                try:
                    broker_username = config.get(section_name, "broker_username")
                except Exception, e:
                    pass

                try:
                    password = config.get(section_name, "password")
                except Exception, e:
                    pass

                try:
                    transaction_fee_buy = config.getint(section_name, "transaction_fee_buy")
                except Exception, e:
                    pass