Exemple #1
0
  def set_user(self, user):
    if user is None:
      self.user = None
      self.is_broker = False
      self.profile = None
      self.should_end = False
      self.email_lang = 'en'
      return

    if self.user:
      raise UserAlreadyLogged
    self.user = user
    self.email_lang = user.email_lang

    self.is_broker = self.user.is_broker

    from models import Broker
    if self.is_broker:
      self.profile = Broker.get_broker( TradeApplication.instance().db_session,user.id)
      self.user_accounts = json.loads(self.profile.accounts)
    else:
      self.profile = user

    if user.broker_id is not None:
      self.broker           = Broker.get_broker( TradeApplication.instance().db_session,user.broker.id)
      self.broker_accounts  = json.loads(self.broker.accounts)
Exemple #2
0
  def set_user(self, user, permission_list):
    if user is None:
      self.user = None
      self.is_broker = False
      self.profile = None
      self.should_end = False
      self.email_lang = TradeApplication.instance().options.global_email_language
      return

    if self.user:
      raise UserAlreadyLogged
    self.user = user
    self.email_lang = user.email_lang
    self.permission_list = permission_list
    self.is_broker = self.user.is_broker

    from models import Broker
    if self.is_broker:
      self.profile = Broker.get_broker( TradeApplication.instance().db_session,user.id)
      self.user_accounts = json.loads(self.profile.accounts)
    else:
      self.profile = user

    if user.broker_id is not None:
      self.broker           = Broker.get_broker( TradeApplication.instance().db_session,user.broker.id)
      self.broker_accounts  = json.loads(self.broker.accounts)
Exemple #3
0
    def log_start_data(self):
        self.log('PARAM', 'BEGIN')
        self.log('PARAM', 'trade_in', self.options.trade_in)
        self.log('PARAM', 'trade_pub', self.options.trade_pub)
        self.log('PARAM', 'trade_log', self.options.trade_log)
        self.log('PARAM', 'session_timeout_limit',
                 self.options.session_timeout_limit)
        self.log('PARAM', 'db_echo', self.options.db_echo)
        self.log('PARAM', 'sqlalchemy_engine', self.options.sqlalchemy_engine)
        self.log('PARAM', 'sqlalchemy_connection_string',
                 self.options.sqlalchemy_connection_string)
        self.log('PARAM', 'test_mode', self.options.test_mode)
        self.log('PARAM', 'dev_mode', self.options.dev_mode)
        self.log('PARAM', 'satoshi_mode', self.options.satoshi_mode)
        self.log('PARAM', 'order_matcher_disabled',
                 self.order_matcher_disabled)
        self.log('PARAM', 'global_email_language',
                 self.options.global_email_language)
        self.log('PARAM', 'END')

        from models import User, Deposit, DepositMethods, Order, Withdraw, Broker, Currency, Instrument, Ledger

        currencies = self.db_session.query(Currency)
        for currency in currencies:
            self.log('DB_ENTITY', 'CURRENCY', currency)

        instruments = self.db_session.query(Instrument)
        for instrument in instruments:
            self.log('DB_ENTITY', 'INSTRUMENT', instrument)

        users = self.db_session.query(User)
        for user in users:
            self.log('DB_ENTITY', 'USER', user)

        # log all users on the replay log
        brokers = self.db_session.query(Broker)
        for broker in brokers:
            Broker.cache_broker(broker.id, broker)
            self.log('DB_ENTITY', 'BROKER', broker)

        deposit_options = self.db_session.query(DepositMethods)
        for deposit_option in deposit_options:
            self.log('DB_ENTITY', 'DEPOSIT_OPTION', deposit_option)

        deposits = self.db_session.query(Deposit)
        for deposit in deposits:
            self.log('DB_ENTITY', 'DEPOSIT', repr(deposit))

        withdraws = self.db_session.query(Withdraw)
        for withdraw in withdraws:
            self.log('DB_ENTITY', 'WITHDRAW', withdraw)

        ledgers = self.db_session.query(Ledger)
        for ledger in ledgers:
            self.log('DB_ENTITY', 'LEDGER', ledger)

        orders = self.db_session.query(Order).filter(
            Order.status.in_(("0", "1"))).order_by(Order.created)
        for order in orders:
            self.log('DB_ENTITY', 'ORDER', order)
Exemple #4
0
  def log_start_data(self):
    self.log('PARAM','BEGIN')
    self.log('PARAM','trade_in'                     ,self.options.trade_in)
    self.log('PARAM','trade_pub'                    ,self.options.trade_pub)
    self.log('PARAM','trade_log'                    ,self.options.trade_log)
    self.log('PARAM','session_timeout_limit'        ,self.options.session_timeout_limit)
    self.log('PARAM','db_echo'                      ,self.options.db_echo)
    self.log('PARAM','sqlalchemy_engine'            ,self.options.sqlalchemy_engine)
    self.log('PARAM','sqlalchemy_connection_string' ,self.options.sqlalchemy_connection_string)
    self.log('PARAM','test_mode'                    ,self.options.test_mode)
    self.log('PARAM','dev_mode'                     ,self.options.dev_mode)
    self.log('PARAM','satoshi_mode'                 ,self.options.satoshi_mode)
    self.log('PARAM','order_matcher_disabled'       ,self.order_matcher_disabled)
    self.log('PARAM','global_email_language'        ,self.options.global_email_language)
    self.log('PARAM','END')


    from models import User, Deposit, DepositMethods, Order, Withdraw, Broker, Currency, Instrument, Ledger


    currencies = self.db_session.query(Currency)
    for currency in currencies:
      self.log('DB_ENTITY', 'CURRENCY', currency)

    instruments = self.db_session.query(Instrument)
    for instrument in instruments:
      self.log('DB_ENTITY', 'INSTRUMENT', instrument)

    users = self.db_session.query(User)
    for user in users:
      self.log('DB_ENTITY', 'USER', user)

    # log all users on the replay log
    brokers = self.db_session.query(Broker)
    for broker in brokers:
      Broker.cache_broker(broker.id, broker)
      self.log('DB_ENTITY', 'BROKER', broker)

    deposit_options = self.db_session.query(DepositMethods)
    for deposit_option in deposit_options:
      self.log('DB_ENTITY', 'DEPOSIT_OPTION',  deposit_option)

    deposits = self.db_session.query(Deposit)
    for deposit in deposits:
      self.log('DB_ENTITY', 'DEPOSIT',  repr(deposit))

    withdraws = self.db_session.query(Withdraw)
    for withdraw in withdraws:
      self.log('DB_ENTITY', 'WITHDRAW', withdraw )

    ledgers = self.db_session.query(Ledger)
    for ledger in ledgers:
      self.log('DB_ENTITY', 'LEDGER', ledger )

    orders = self.db_session.query(Order).filter(Order.status.in_(("0", "1"))).order_by(Order.created)
    for order in orders:
      self.log('DB_ENTITY','ORDER',order)
Exemple #5
0
def new_task():

    task = TasksTable()
    task.save()
    broker = Broker().new_task(exchange='',
                               routing_key='tasks',
                               body=str(task.id))

    return f'New task number {task.id} created and added to the queue.'
Exemple #6
0
  def set_user(self, user):
    if user is None:
      self.user = None
      self.is_broker = False
      self.profile = None
      self.should_end = False
      return

    if self.user:
      raise UserAlreadyLogged
    self.user = user

    self.is_broker = self.user.is_broker

    from models import Broker
    if self.is_broker:
      self.profile = Broker.get_broker( application.db_session,user.id)
    else:
      self.profile = user

    if user.broker_id is not None:
      self.broker = Broker.get_broker( application.db_session,user.broker.id)
Exemple #7
0
    def set_user(self, user):
        if user is None:
            self.user = None
            self.is_broker = False
            self.profile = None
            self.should_end = False
            return

        if self.user:
            raise UserAlreadyLogged
        self.user = user

        self.is_broker = self.user.is_broker

        from models import Broker
        if self.is_broker:
            self.profile = Broker.get_broker(application.db_session, user.id)
        else:
            self.profile = user

        if user.broker_id is not None:
            self.broker = Broker.get_broker(application.db_session,
                                            user.broker.id)
Exemple #8
0
    def log_start_data(self):
        self.log("PARAM", "BEGIN")
        self.log("PARAM", "trade_in", self.options.trade_in)
        self.log("PARAM", "trade_pub", self.options.trade_pub)
        self.log("PARAM", "trade_log", self.options.trade_log)
        self.log("PARAM", "session_timeout_limit", self.options.session_timeout_limit)
        self.log("PARAM", "db_echo", self.options.db_echo)
        self.log("PARAM", "sqlalchemy_engine", self.options.sqlalchemy_engine)
        self.log("PARAM", "sqlalchemy_connection_string", self.options.sqlalchemy_connection_string)
        self.log("PARAM", "test_mode", self.options.test_mode)
        self.log("PARAM", "dev_mode", self.options.dev_mode)
        self.log("PARAM", "satoshi_mode", self.options.satoshi_mode)
        self.log("PARAM", "order_matcher_disabled", self.order_matcher_disabled)
        self.log("PARAM", "global_email_language", self.options.global_email_language)
        self.log("PARAM", "END")

        from models import (
            User,
            Deposit,
            DepositMethods,
            Order,
            Withdraw,
            Broker,
            Currency,
            Instrument,
            ApiAccess,
            Balance,
            Position,
            GreenAddresses,
        )

        green_address_list = self.db_session.query(GreenAddresses)
        for green_address_entity in green_address_list:
            self.log("DB_ENTITY", "GREEN_ADDRESS", green_address_entity)

        currencies = self.db_session.query(Currency)
        for currency in currencies:
            self.log("DB_ENTITY", "CURRENCY", currency)

        instruments = self.db_session.query(Instrument)
        for instrument in instruments:
            self.log("DB_ENTITY", "INSTRUMENT", instrument)

        users = self.db_session.query(User)
        for user in users:
            self.log("DB_ENTITY", "USER", user)

        api_access_list = self.db_session.query(ApiAccess)
        for api_access_entity in api_access_list:
            self.log("DB_ENTITY", "API_ACCESS", api_access_entity)

        # log all users on the replay log
        brokers = self.db_session.query(Broker)
        for broker in brokers:
            Broker.cache_broker(broker.id, broker)
            self.log("DB_ENTITY", "BROKER", broker)

        deposit_options = self.db_session.query(DepositMethods)
        for deposit_option in deposit_options:
            self.log("DB_ENTITY", "DEPOSIT_OPTION", deposit_option)

        deposits = self.db_session.query(Deposit)
        for deposit in deposits:
            self.log("DB_ENTITY", "DEPOSIT", repr(deposit))

        withdraws = self.db_session.query(Withdraw)
        for withdraw in withdraws:
            self.log("DB_ENTITY", "WITHDRAW", withdraw)

        balance_list = self.db_session.query(Balance)
        for balance_entity in balance_list:
            self.log("DB_ENTITY", "BALANCE", balance_entity)

        position_list = self.db_session.query(Position)
        for position_entity in position_list:
            self.log("DB_ENTITY", "POSITION", position_entity)

        orders = self.db_session.query(Order).filter(Order.status.in_(("0", "1"))).order_by(Order.created)
        for order in orders:
            self.log("DB_ENTITY", "ORDER", order)
Exemple #9
0
    def log_start_data(self):
        self.log('PARAM', 'BEGIN')
        self.log('PARAM', 'trade_in', self.options.trade_in)
        self.log('PARAM', 'trade_pub', self.options.trade_pub)
        self.log('PARAM', 'trade_log', self.options.trade_log)
        self.log('PARAM', 'session_timeout_limit',
                 self.options.session_timeout_limit)
        self.log('PARAM', 'db_echo', self.options.db_echo)
        self.log('PARAM', 'sqlalchemy_engine', self.options.sqlalchemy_engine)
        self.log('PARAM', 'sqlalchemy_connection_string',
                 self.options.sqlalchemy_connection_string)
        self.log('PARAM', 'test_mode', self.options.test_mode)
        self.log('PARAM', 'dev_mode', self.options.dev_mode)
        self.log('PARAM', 'satoshi_mode', self.options.satoshi_mode)
        self.log('PARAM', 'order_matcher_disabled',
                 self.order_matcher_disabled)
        self.log('PARAM', 'global_email_language',
                 self.options.global_email_language)
        self.log('PARAM', 'END')


        from models import User, Deposit, DepositMethods, Order, Withdraw, Broker, \
          Currency, Instrument, ApiAccess, Balance, Position, GreenAddresses

        green_address_list = self.db_session.query(GreenAddresses)
        for green_address_entity in green_address_list:
            self.log('DB_ENTITY', 'GREEN_ADDRESS', green_address_entity)

        currencies = self.db_session.query(Currency)
        for currency in currencies:
            self.log('DB_ENTITY', 'CURRENCY', currency)

        instruments = self.db_session.query(Instrument)
        for instrument in instruments:
            self.log('DB_ENTITY', 'INSTRUMENT', instrument)

        users = self.db_session.query(User)
        for user in users:
            self.log('DB_ENTITY', 'USER', user)

        api_access_list = self.db_session.query(ApiAccess)
        for api_access_entity in api_access_list:
            self.log('DB_ENTITY', 'API_ACCESS', api_access_entity)

        # log all users on the replay log
        brokers = self.db_session.query(Broker)
        for broker in brokers:
            Broker.cache_broker(broker.id, broker)
            self.log('DB_ENTITY', 'BROKER', broker)

        deposit_options = self.db_session.query(DepositMethods)
        for deposit_option in deposit_options:
            self.log('DB_ENTITY', 'DEPOSIT_OPTION', deposit_option)

        deposits = self.db_session.query(Deposit)
        for deposit in deposits:
            self.log('DB_ENTITY', 'DEPOSIT', repr(deposit))

        withdraws = self.db_session.query(Withdraw)
        for withdraw in withdraws:
            self.log('DB_ENTITY', 'WITHDRAW', withdraw)

        balance_list = self.db_session.query(Balance)
        for balance_entity in balance_list:
            self.log('DB_ENTITY', 'BALANCE', balance_entity)

        position_list = self.db_session.query(Position)
        for position_entity in position_list:
            self.log('DB_ENTITY', 'POSITION', position_entity)

        orders = self.db_session.query(Order).filter(
            Order.status.in_(("0", "1"))).order_by(Order.created)
        for order in orders:
            self.log('DB_ENTITY', 'ORDER', order)
import socket
import datetime
from time import sleep
from random import randint

from models import TasksTable, Broker


def on_receive(ch, method, properties, body):
    duration = randint(5, 30)
    print(f'Received task number "{body}". Should be done in {duration} s')

    tasks = TasksTable().filter(id=body).get()
    tasks.status = 'in progress'
    tasks.worker = socket.gethostname()
    tasks.save()

    # simulate work
    sleep(duration)

    tasks.finished = datetime.datetime.now()
    tasks.status = 'finished'
    tasks.duration = duration
    tasks.save()

    ch.basic_ack(delivery_tag=method.delivery_tag)


Broker.start_consuming(on_receive)
Exemple #11
0
    def setUp(self):
        from models import Base, db_bootstrap

        self.engine = create_engine('sqlite://', echo=False)
        Base.metadata.create_all(self.engine)

        self.db_session = scoped_session(sessionmaker(bind=self.engine))
        TradeApplication.instance().db_session = self.db_session

        db_bootstrap(self.db_session)

        currencies = [[
            "BTC", u"฿", "Bitcoin", True, 10000, "{:,.8f}",
            u"฿ #,##0.00000000;(฿ #,##0.00000000)", "{:,.8f}",
            u"฿ #,##0.00000000;(฿ #,##0.0000000)"
        ],
                      [
                          "USD", u"$", "Dollar", False, 100, "{:,.2f}",
                          u"¤ #,##0.00;(¤ #,##0.00)", "{:,.2f}",
                          u"¤ #,##0.00;(¤ #,##0.00)"
                      ]]

        for c in currencies:
            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])
            self.db_session.add(e)
            self.db_session.commit()

        instruments = [["BTCUSD", "USD", "BTC / USD"]]
        for currency_description in instruments:
            e = Instrument(symbol=currency_description[0],
                           currency=currency_description[1],
                           description=currency_description[2])
            self.db_session.add(e)
            self.db_session.commit()

        # user root
        e = User(id=-1,
                 username='******',
                 email='*****@*****.**',
                 password='******',
                 country_code='US',
                 state='NY',
                 transaction_fee_buy=0,
                 transaction_fee_sell=0,
                 verified=3,
                 is_staff=True,
                 is_system=True,
                 is_broker=True,
                 email_lang='en')
        self.db_session.add(e)

        # user blinktrade
        e = User(id=8999999,
                 username='******',
                 email='*****@*****.**',
                 password='******',
                 country_code='US',
                 state='NY',
                 transaction_fee_buy=0,
                 transaction_fee_sell=0,
                 verified=3,
                 is_staff=True,
                 is_broker=True,
                 email_lang='en')
        self.db_session.add(e)

        # user exchange
        e = User(id=5,
                 username='******',
                 email='*****@*****.**',
                 broker_id=8999999,
                 broker_username='******',
                 password='******',
                 country_code='US',
                 state='NY',
                 transaction_fee_buy=0,
                 transaction_fee_sell=0,
                 verified=5,
                 is_broker=True,
                 email_lang='en')
        self.db_session.add(e)
        self.db_session.commit()

        # user exchange bonus
        e = User(id=90000000,
                 username='******',
                 email='*****@*****.**',
                 broker_id=5,
                 broker_username='******',
                 password='******',
                 country_code='US',
                 state='NY',
                 transaction_fee_buy=0,
                 transaction_fee_sell=0,
                 verified=5,
                 is_broker=True,
                 email_lang='en')
        self.db_session.add(e)
        self.db_session.commit()
        self.user_exchange_bonus = e

        # user exchange fees
        e = User(id=90000001,
                 username='******',
                 email='*****@*****.**',
                 broker_id=5,
                 broker_username='******',
                 password='******',
                 country_code='US',
                 state='NY',
                 transaction_fee_buy=0,
                 transaction_fee_sell=0,
                 verified=5,
                 is_broker=True,
                 email_lang='en')
        self.db_session.add(e)
        self.db_session.commit()
        self.user_exchange_fees = e

        # broker exchange
        e = Broker(
            id=5,
            short_name='exchange',
            business_name='BlinkTrade Demo Exchange',
            address='21 Bitcoin Ave',
            signup_label='BlinkTrade Demo Exchange',
            city='New York',
            state='NY',
            zip_code='10000',
            country_code='US',
            lang='en',
            country='United States',
            mandrill_api_key=None,
            mailer_from_name='BlinkTrade',
            mailer_from_email='*****@*****.**',
            mailer_signature='BlinkTrade Demo Exchange',
            mailchimp_list_id='5c7b7818d8',
            phone_number_1=None,
            phone_number_2=None,
            skype='blinktrade',
            email='*****@*****.**',
            verification_jotform=
            'https://secure.jotform.co/form/42336230941852?user_id={{UserID}}&username={{Username}}&broker_id={{BrokerID}}&broker_username={{BrokerUsername}}&email={{Email}}&phoneNumber[country]=1&address[state]={{State}}&address[country]=United+States',
            upload_jotform=
            'https://secure.jotform.co/form/42344880060854?user_id={{UserID}}&username={{Username}}&broker_id={{BrokerID}}&broker_username={{BrokerUsername}}&deposit_method={{DepositMethod}}&control_number={{ControlNumber}}&deposit_id={{DepositID}}',
            currencies='USD',
            withdraw_structure=json.dumps({
                "BTC": [{
                    "method":
                    "bitcoin",
                    "description":
                    "Bitcoin withdrawal",
                    "disclaimer":
                    "",
                    "percent_fee":
                    0,
                    "fixed_fee":
                    0,
                    "limits": {
                        "0": {
                            "enabled": True,
                            "min": 500000,
                            "max": 100000000
                        },
                        "1": {
                            "enabled": True,
                            "min": 500000,
                            "max": 100000000
                        },
                        "2": {
                            "enabled": True,
                            "min": 500000,
                            "max": 100000000
                        },
                        "3": {
                            "enabled": True,
                            "min": 500000
                        },
                        "4": {
                            "enabled": True,
                            "min": 500000
                        },
                        "5": {
                            "enabled": True,
                            "min": 500000
                        }
                    },
                    "fields": [{
                        "side": "client",
                        "name": "Wallet",
                        "validator": "validateAddress",
                        "type": "text",
                        "value": "",
                        "label": "Wallet",
                        "placeholder": ""
                    }, {
                        "side": "broker",
                        "name": "TransactionID",
                        "validator": "validateAlphaNum",
                        "type": "text",
                        "value": "",
                        "label": "TransactionID",
                        "placeholder": ""
                    }]
                }],
                "USD": [{
                    "method":
                    "swift",
                    "description":
                    "Swift International Transfer",
                    "disclaimer":
                    "84 hours, 1%  fee + $25",
                    "percent_fee":
                    1,
                    "fixed_fee":
                    2500000000,
                    "limits": {
                        "0": {
                            "enabled": False
                        },
                        "1": {
                            "enabled": False
                        },
                        "2": {
                            "enabled": False
                        },
                        "3": {
                            "enabled": True,
                            "min": 3500000000,
                            "max": 280000000000
                        },
                        "4": {
                            "enabled": True,
                            "min": 3500000000,
                            "max": 5000000000000
                        },
                        "5": {
                            "enabled": True,
                            "min": 3500000000
                        }
                    },
                    "fields": [{
                        "side": "client",
                        "name": "BankName",
                        "validator": "validateAlphaNum",
                        "type": "text",
                        "value": "",
                        "label": "Banco name",
                        "placeholder": "ex. JPMORGAN CHASE BANK, N.A"
                    }, {
                        "side": "client",
                        "name": "BankSwift",
                        "validator": "validateAlphaNum",
                        "type": "text",
                        "value": "",
                        "label": "Swift code",
                        "placeholder": "ex. CHASUS33"
                    }, {
                        "side": "client",
                        "name": "RoutingNumber",
                        "validator": "validateAlphaNum",
                        "type": "text",
                        "value": "",
                        "label": "Routing Number",
                        "placeholder": "ex. 021000021"
                    }, {
                        "side": "client",
                        "name": "AccountNumber",
                        "validator": "validateAlphaNum",
                        "type": "text",
                        "value": "",
                        "label": "Account Number",
                        "placeholder": "ex. 88888-8"
                    }, {
                        "side": "broker",
                        "name": "TransactionID",
                        "validator": "validateAlphaNum",
                        "type": "text",
                        "value": "",
                        "label": "TransactionID",
                        "placeholder": ""
                    }]
                }]
            }).decode('utf-8'),
            crypto_currencies=json.dumps([{
                "Wallets": [{
                    "managed_by": "BlinkTrade, Exchange Operator, Mediator ",
                    "signatures": [],
                    "type": "cold",
                    "multisig": False,
                    "address": "n3yyGwzyfTxbKB8hkkv2AsQ9nBQgEozsV4"
                }, {
                    "managed_by": "Exchange Operator ",
                    "signatures": [],
                    "type": "hot",
                    "multisig": False,
                    "address": "msQRdMPcwLr3rWsLzG56ABhHtfavHH2yVW"
                }],
                "CurrencyCode":
                "BTC",
                "Confirmations": [[0, 200000000, 1],
                                  [200000000, 20000000000, 3],
                                  [20000000000, 2100000000000000, 6]],
                "CurrencyDescription":
                "Bitcoin"
            }]).decode('utf-8'),
            accept_customers_from=json.dumps(
                [["*"], ["CU", "SO", "SD", "NG", "IR", "KP"]]).decode('utf-8'),
            is_broker_hub=False,
            support_url='mailto:[email protected]',
            tos_url=
            'https://docs.google.com/a/blinktrade.com/document/d/1HyFRs_2Seh4LGZYjPk8bmbxueUjF7RMz-koAM3rG2Pc/pub?embedded=true',
            fee_structure=json.dumps([{
                "Operation":
                "Wire transfer",
                "Fee":
                "1%",
                "Terms":
                "Exchange operator decides its fees"
            }]).decode('utf-8'),
            transaction_fee_buy=60,
            transaction_fee_sell=60,
            accounts=json.dumps({
                "bonus": [90000000, "exchange_bonus", ["USD", 100000000]],
                "fees": [90000001, "exchange_fees"]
            }).decode('utf-8'),
            status='1',
            ranking=5)
        self.db_session.add(e)
        self.db_session.commit()

        e = DepositMethods(id=501,
                           broker_id=5,
                           name='usps',
                           description='USPS Money order',
                           disclaimer='1 business day',
                           type='DTP',
                           percent_fee=0,
                           fixed_fee=500000000,
                           broker_deposit_ctrl_num=501000001,
                           currency='USD',
                           deposit_limits=json.dumps({
                               "0": {
                                   "enabled": False
                               },
                               "1": {
                                   "enabled": False
                               },
                               "2": {
                                   "enabled": False
                               },
                               "3": {
                                   "enabled": True,
                                   "min": 1000000000,
                                   "max": 280000000000
                               },
                               "4": {
                                   "enabled": True,
                                   "min": 1000000000,
                                   "max": 5000000000000
                               },
                               "5": {
                                   "enabled": True,
                                   "min": 1000000000
                               }
                           }).decode('utf-8'),
                           html_template="""
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <link href="//maxcdn.bootstrapcdn.com/bootstrap/2.3.0/css/bootstrap.min.css" rel="stylesheet">
  </head>
  <body style="background-color: #ffffff">
    <div class="container">
      <div class="content-fluid">
        <table class="table table-condensed">
          <tr>
            <td>Order ID:</td>
            <td>*|control_number|*</td>
          </tr>
          <tr>
            <td>Created:</td>
            <td>*|created|*</td>
          </tr>
          <tr>
            <td>Deposit Method:</td>
            <td>Money Order</td>
          </tr>
          <tr>
            <td>Instructions:</td>
            <td>
              1. Head to your local United States Postal Service and purchase a money order slip for the correct amount. Learn more about USPS money orders <a href="https://www.usps.com/shop/money-orders.htm">here</a><br/>
              2. Fill out the money order form. <b>Important: Make sure to write your confirmation code directly on it!</b><br/>
              3. Take a picture of the filled out money order<br/>
              4. Upload the photo of the money order in the system<br/>
              5. Send the money order to :
              <strong>Satoshi Nakamoto<strong><br/>
              <strong>21 Bitcoin Street<strong><br/>
              <strong>New York - NY - 10001<strong><br/>
            </td>
          </tr>
          <tr>
            <td>Total Deposit:</td>
            <td>$ *|value|*</td>
          </tr>
          <tr>
            <td>Notes:</td>
            <td> <small>
              Please complete your deposit according to your preferred method. Be sure to send a copy of the Order ID with the receipt of completed payment to us.
            </small> </td>
          </tr>
        </table>
      </div>
    </div>
  </body>
</html>
                        """,
                           parameters='{}')
        self.db_session.add(e)
        self.db_session.commit()
        self.deposit_method_501 = e

        self.deposit_method_501.generate_deposit(self.db_session,
                                                 self.user_exchange_bonus,
                                                 100000000000, None)
def _create_broker(broker_data, agency):
	sender_broker = Broker()
	sender_broker.agency = agency.key
	sender_broker.build(broker_data)
	return sender_broker.find_or_create()