def createTrade(): # Get request data data = request.get_json() # Instantiate market objects bs = BlocServer() bc = BlocClient() # Retrieve keys from session and assign in client bc.signingKey = data['signingKey'] bc.verifyKey = data['verifyKey'] tradeRow = pd.DataFrame( data, index=[0])[['marketId', 'price', 'quantity', 'traderId']] # Call createMarket_client try: checks, allChecks = bc.createTrade_client(tradeRow=tradeRow, blocServer=bs) except Exception as err: checks = traceback.format_exc() allChecks = {'Boned': True} bs.conn.close() if np.isnan(allChecks['tradeId']): allChecks['tradeId'] = 0 return jsonify({ 'checks': str(checks), 'tradeId': int(allChecks['tradeId']), 'marketId': data['marketId'], 'price': data['price'], 'quantity': data['quantity'], 'traderId': data['traderId'], 'allChecks': str(allChecks) })
def createMarket(): # Get request data data = request.get_json() # Instantiate market objects bs = BlocServer() bc = BlocClient() # Retrieve keys from session and assign in client bc.signingKey = data['signingKey'] bc.verifyKey = data['verifyKey'] marketRow = pd.DataFrame(data, index=[0])[['marketRootId', 'marketBranchId', 'marketMin', 'marketMax', 'traderId']] # Call createMarket_client try: checks, allChecks = bc.createMarket_client(marketRow=marketRow, blocServer=bs) except: checks = traceback.format_exc() allChecks = {'Boned': True, 'marketId': 0} bs.conn.close() return jsonify({'checks': str(checks), 'marketId': int(allChecks['marketId']), 'marketRootId': data['marketRootId'], 'marketBranchId': data['marketBranchId'], 'marketMin': data['marketMin'], 'marketMax': data['marketMax'], 'traderId': data['traderId'], 'allChecks': str(allChecks)})
def createUser(): bs = BlocServer() bc = BlocClient() bc.generateSignatureKeys() newUsr = bc.createUser_client(blocServer=bs) bs.conn.close() return jsonify({'traderId': str(newUsr['traderId']), 'verifyKey': newUsr['verifyKey'], 'signingKey': bc.signingKey})
def setUpClass(cls): # Setup market server and two clients cls.bc1 = BlocClient() cls.bc2 = BlocClient() cls.bs = BlocServer() cls.bs.purgeTables() # Ovewrite with collateral = 2 cls.bs.COLLATERAL_LIMIT = 2000 # Pull user table to ensure is empty tmpUserTable = pd.read_sql_table('userTable', cls.bs.conn) # Generate signature keys for two traders cls.bc1.generateSignatureKeys() cls.bc2.generateSignatureKeys() # Register keys with market server cls.bs.createUser(cls.bc1.verifyKey) usr = cls.bs.createUser(cls.bc2.verifyKey) tmp = pd.read_sql_query( 'SELECT DISTINCT "traderId" from "userTable" ORDER BY "traderId"', cls.bs.conn) cls.trader0 = tmp.traderId[0] cls.trader1 = tmp.traderId[1] print(usr)