|
@@ -5,8 +5,9 @@ from inspect import signature
|
|
|
import connection
|
|
|
from connection import client_request
|
|
|
from debug import debug
|
|
|
-from game import DEFAULT_ORDER_EXPIRY, CURRENCY_NAME
|
|
|
-from run_client import allowed_commands, fake_loading_bar
|
|
|
+from game import DEFAULT_ORDER_EXPIRY, CURRENCY_NAME, MIN_INTEREST_INTERVAL
|
|
|
+from routes import client_commands
|
|
|
+from run_client import fake_loading_bar
|
|
|
from util import my_tabulate, yn_dialog
|
|
|
|
|
|
exiting = False
|
|
@@ -128,7 +129,7 @@ def change_pw(password=None, retype_pw=None):
|
|
|
def help():
|
|
|
print('Allowed commands:')
|
|
|
command_table = []
|
|
|
- for cmd in allowed_commands:
|
|
|
+ for cmd in client_commands:
|
|
|
this_module = sys.modules[__name__]
|
|
|
method = getattr(this_module, cmd)
|
|
|
params = signature(method).parameters
|
|
@@ -159,7 +160,8 @@ def depot():
|
|
|
row.append(row[1] * row[2])
|
|
|
print(my_tabulate(data,
|
|
|
headers=['Object', 'Amount', 'Course', 'Bid', 'Ask', 'Est. Value'],
|
|
|
- tablefmt="pipe"))
|
|
|
+ tablefmt="pipe",
|
|
|
+ floatfmt='.2f'))
|
|
|
wealth = response['own_wealth']
|
|
|
print(f'This corresponds to a wealth of roughly {wealth}.')
|
|
|
if response['banking_license']:
|
|
@@ -296,10 +298,11 @@ def buy_banking_license():
|
|
|
fake_loading_bar('Filling the necessary forms', duration=14.4)
|
|
|
fake_loading_bar('Waiting for bank regulation\'s response', duration=26.8)
|
|
|
response = client_request('buy_banking_license', {"session_id": connection.session_id})
|
|
|
- success = 'data' in response
|
|
|
+ success = 'message' in response and 'error' not in response
|
|
|
if success:
|
|
|
print('Success. You are now a bank.')
|
|
|
- summarize_banking_rules()
|
|
|
+ print()
|
|
|
+ summarize_bank_rules()
|
|
|
|
|
|
else:
|
|
|
if 'error' in response:
|
|
@@ -308,15 +311,107 @@ def buy_banking_license():
|
|
|
print('Banking license application access failed.')
|
|
|
|
|
|
|
|
|
-def summarize_banking_rules():
|
|
|
+def summarize_bank_rules():
|
|
|
variables = _global_variables()
|
|
|
+ banking_license_price = variables['banking_license_price']
|
|
|
marginal_lending_facility = variables['marginal_lending_facility']
|
|
|
cash_reserve_free_amount = variables['cash_reserve_free_amount']
|
|
|
cash_reserve_ratio = variables['cash_reserve_ratio']
|
|
|
- print(f'AS a bank, you are now allowed to borrow money from the central bank at the marginal '
|
|
|
- f'lending facility (currently {marginal_lending_facility * 100}%).')
|
|
|
+ deposit_facility = variables['deposit_facility']
|
|
|
+ print(f'A bank is by definition anyone who has a banking license.')
|
|
|
+ print(f'A banking license can be for {banking_license_price} {CURRENCY_NAME}.')
|
|
|
+ print(f'This includes payment of lawyers and consultants to deal with the formal application.')
|
|
|
+ print()
|
|
|
+ print(f'Banks are allowed to borrow money from the central bank at the marginal '
|
|
|
+ f'lending facility (currently {marginal_lending_facility * 100}% p.a.).')
|
|
|
print(f'For every {CURRENCY_NAME} above {cash_reserve_free_amount} banks have to '
|
|
|
f'deposit a cash reserve of {cash_reserve_ratio * 100}% at the central bank.')
|
|
|
+ print(f'Banks receive a deposit facility of {deposit_facility * 100}% p.a. for cash reserves.')
|
|
|
+
|
|
|
+
|
|
|
+def summarize_loan_rules():
|
|
|
+ variables = _global_variables()
|
|
|
+ personal_loan_interest_rate = variables['personal_loan_interest_rate']
|
|
|
+ print(f'You can take personal loans at an interest rate of {personal_loan_interest_rate * 100}% p.a.')
|
|
|
+ print(f'You can repay personal loans at any time if you have the liquidity.')
|
|
|
+ print(f'Interest rates will be automatically be debited from your account.')
|
|
|
+ print(f'Note that this debit may be delayed by up to {MIN_INTEREST_INTERVAL} seconds.')
|
|
|
+ print(f'If you have no {CURRENCY_NAME} available (or negative account balance), you can still')
|
|
|
+ print(f' - pay any further interests (account will move further into the negative)')
|
|
|
+ print(f' - take a new loan (if we think that you will be able to repay it)')
|
|
|
+ print(f' - sell any securities you own')
|
|
|
+ print(f'However you can not')
|
|
|
+ print(f' - spend money to buy securities')
|
|
|
+ print(f' - spend money to buy a banking license')
|
|
|
+
|
|
|
+
|
|
|
+def take_out_personal_loan(amount=None):
|
|
|
+ if amount is None:
|
|
|
+ summarize_loan_rules()
|
|
|
+ print()
|
|
|
+ amount = input('Please enter your desired loan volume: ')
|
|
|
+ try:
|
|
|
+ amount = float(amount)
|
|
|
+ except ValueError:
|
|
|
+ print('Amount must be a number larger than 0.')
|
|
|
+ return
|
|
|
+ if amount <= 0:
|
|
|
+ print('Amount must be a number larger than 0.')
|
|
|
+ fake_loading_bar('Checking if you are trustworthy', duration=0.0)
|
|
|
+ fake_loading_bar('Checking if you are credit-worthy', duration=0.0)
|
|
|
+ fake_loading_bar('Transferring the money', duration=1.6)
|
|
|
+ response = client_request('take_out_personal_loan', {"session_id": connection.session_id, 'amount': amount})
|
|
|
+ success = 'message' in response and 'error' not in response
|
|
|
+ if success:
|
|
|
+ print(f'You took a personal loan of {amount} {CURRENCY_NAME}.')
|
|
|
+ else:
|
|
|
+ if 'error' in response:
|
|
|
+ print('Taking a personal loan failed with message:', response['error'])
|
|
|
+ else:
|
|
|
+ print('Taking a personal loan failed.')
|
|
|
+
|
|
|
+
|
|
|
+def loans():
|
|
|
+ fake_loading_bar('Loading Data', duration=0.9)
|
|
|
+ response = client_request('loans', {"session_id": connection.session_id})
|
|
|
+ success = 'data' in response
|
|
|
+ if success:
|
|
|
+ print(my_tabulate(response['data'],
|
|
|
+ headers=['Loan ID', 'Total amount', 'Remaining', 'Interest p.a.', ],
|
|
|
+ tablefmt="pipe"))
|
|
|
+ else:
|
|
|
+ if 'error' in response:
|
|
|
+ print('Order access failed with message:', response['error'])
|
|
|
+ else:
|
|
|
+ print('Order access failed.')
|
|
|
+
|
|
|
+
|
|
|
+def repay_loan(loan_id=None, amount=None):
|
|
|
+ if loan_id is None:
|
|
|
+ loans()
|
|
|
+ print('Which loan would you like to pay back?')
|
|
|
+ loan_id = input('Loan id:')
|
|
|
+ if amount is None:
|
|
|
+ print('How much would you like to pay back?')
|
|
|
+ amount = input('Amount (type `all` for the remaining loan):')
|
|
|
+ if amount != 'all':
|
|
|
+ try:
|
|
|
+ amount = float(amount)
|
|
|
+ if amount <= 0:
|
|
|
+ raise ValueError
|
|
|
+ except ValueError:
|
|
|
+ print('Amount must be a number larger than 0 or \'all\' (for paying back the remaining loan).')
|
|
|
+ return
|
|
|
+ fake_loading_bar('Transferring the money', duration=1.7)
|
|
|
+ response = client_request('repay_loan', {"session_id": connection.session_id, 'amount': amount, 'loan_id': loan_id})
|
|
|
+ success = 'message' in response and 'error' not in response
|
|
|
+ if success:
|
|
|
+ print(f'You repayed the specified amount of {CURRENCY_NAME}.')
|
|
|
+ else:
|
|
|
+ if 'error' in response:
|
|
|
+ print('Repaying the loan failed with message:', response['error'])
|
|
|
+ else:
|
|
|
+ print('Repaying the loan failed.')
|
|
|
|
|
|
|
|
|
def _global_variables():
|