示例#1
0
 def test_post_internal_transfer(self, session, kind_from, kind_to):
     from_account = get_accounts(session, kind=kind_from)[0]
     to_account = list(
         set(get_accounts(session, kind=kind_to)).symmetric_difference(
             [from_account]))[0]
     data = {
         "id": str(time.time_ns()),
         "fromAccount": int(from_account),
         "toAccount": int(to_account),
         "amount": "0.00010000",
         "currency": "BTC"
     }
     response = requests.get(
         f'{trading_url}/api/account/{get_accounts(session)[0]}/internal-transfer',
         headers={'X-Auth-Nonce': session['nonce']},
         cookies=session['cookies'])
     logging.info(response.headers)
     logging.info(response.text)
     assert response.status_code == 200
示例#2
0
def generate2fa(request):
    # Login
    account = request.param
    response = requests.post(url=cfg.trading_url + '/api/auth/login', json=account['login_data'])
    jresp = json.loads(response.text)
    session = {"login_data": account['login_data'], "nonce": jresp['nonce'],
               "cookies": response.cookies, "accounts": jresp['accounts']}

    # Generate secret
    rsp = requests.post(cfg.trading_url + '/api/auth/account/' + str(get_accounts(session)[0]) + '/2fa/generate',
                        headers={'X-Auth-Nonce': session['nonce']},
                        cookies=session['cookies'])
    otp_secret = ast.literal_eval(rsp.text)['key']
    logging.info('Get key' + str(otp_secret))

    yield session, otp_secret
    time.sleep(30)
    # Re-login (required if auth2fa set)
    logging.info('Re-login')
    totp = pyotp.TOTP(otp_secret)
    logging.info(totp.now())
    response = requests.post(url=cfg.trading_url + '/api/auth/login', json={"email": account['login_data']['email'],
                                                                        "password": account['login_data']['password'],
                                                                        "passcode": totp.now()})
    jresp = json.loads(response.text)
    session = {"login_data": account['login_data'], "nonce": jresp['nonce'],
               "cookies": response.cookies, "accounts": jresp['accounts']}
    # Disable 2fa
    logging.info('Disable 2fa')
    time.sleep(30)
    logging.info(totp.now())
    data = {
        "password": session['login_data']['password'],
        "passcode": totp.now(),
        "authEnabled": False,
        "enabled": False
    }
    rsp = requests.post(cfg.trading_url + '/api/auth/account/' + str(get_accounts(session)[0]) + '/2fa/set',
                        headers={'X-Auth-Nonce': session['nonce']}, json=data,
                        cookies=session['cookies'])
    logging.info('2fa disabled ' + str(rsp.text) + "_" + str(rsp.status_code))
示例#3
0
def _load():
    try:
        with open(RENREN_FILE, 'r') as f:
            return pickle.load(f)
    except IOError:
        from utils import get_accounts
        r = RenRenRelationShip(*get_accounts())

        print 'collect friends'
        data = r.collect_friends(level=2)
        _dump(data)
        return data
示例#4
0
def _load():
    try:
        with open(RENREN_FILE, 'r') as f:
            return pickle.load(f)
    except IOError:
        from utils import get_accounts
        r = RenRenRelationShip(*get_accounts())
        
        print 'collect friends'
        data = r.collect_friends(level=2)
        _dump(data)
        return data
示例#5
0
def apikey(request):
    session = request.param
    response = requests.post(f'{cfg.trading_url}/api/auth/apikeys/new',
                             headers={'X-Auth-Nonce': session['nonce']},
                             cookies=session['cookies'],
                             json={"scopes": ["trading", "transfers"], "accounts": get_accounts(session)})
    apikey = ast.literal_eval(response.text)

    yield apikey

    response = requests.get(f'{cfg.trading_url}/api/auth/apikeys', headers={'X-Auth-Nonce': session['nonce']},
                            cookies=session['cookies'])
    if response.text.find(apikey['apiKey']) != -1:
        requests.delete(f'{cfg.trading_url}/api/auth/apikeys',
                        headers={'X-Auth-Nonce': session['nonce']},
                        cookies=session['cookies'], json={"apiKey": apikey['apiKey']})
 def test_post_create_payment(self, session, payment_ratio, base_amount,
                              cancel_payment):
     data = {
         "quoteAmount":
         str(round(float(base_amount) * float(payment_ratio), 2)),
         "quoteCurrency": "EUR",
         "baseAmount": base_amount,
         "baseCurrency": "BTC",
         "language": "ru",
         "ratio": payment_ratio,
         "account": get_accounts(session, kind='Spot')
     }
     response = requests.post(f'{trading_url}/api/payment/create',
                              headers={'X-Auth-Nonce': session['nonce']},
                              json=data,
                              cookies=session['cookies'])
     logging.info(response.headers)
     logging.info(response.text)
     assert response.status_code == 200
示例#7
0
def payment(request, payment_ratio):
    session = request.param
    data = {"quoteAmount": str(round(0.00400000 * float(payment_ratio), 2)),
            "quoteCurrency": "EUR",
            "baseAmount": "0.00400000",
            "baseCurrency": "BTC",
            "language": "ru",
            "ratio": payment_ratio,
            "account": get_accounts(session, kind='Spot')}
    requests.post(f'{cfg.trading_url}/api/payment/create', headers={'X-Auth-Nonce': session['nonce']},
                             json=data, cookies=session['cookies'])

    yield "id of payment"

    response = requests.get(f'{cfg.trading_url}/api/payment/active-payments', headers={'X-Auth-Nonce': session['nonce']},
                            cookies=session['cookies'])

    if response.text != "[]":
        requests.post(f'{cfg.trading_url}/api/payment/cancel/0',
                                 headers={'X-Auth-Nonce': session['nonce']},
                                 cookies=session['cookies'])
示例#8
0
def index():
    root = g.session.book.get_root_account()
    accounts = []
    for ac in get_accounts(root):
        accounts.append((ac.name, get_account_label(ac)))
    return render_template('index.html', accounts=accounts)