def getlimitOrderOpen(userId): result = getSpecificData("crypto_user", "user_id", userId) get_trade_response = client.list_open_orders(userId, result[7]) if 'order' not in get_trade_response: return jsonify({'exception': get_trade_response["error"]}) for trade in get_trade_response: trade1 = trade["order"] trade1["amount"] = RealTimeCurrencyExchangeRate(float( trade1["amount"])) return jsonify({'orders': get_trade_response})
def getOpenTrade(userId): result = getSpecificData("crypto_user", "user_id", userId) get_trade_response = client.list_active_trades(userId, result[7]) if 'trade' not in get_trade_response: return jsonify({'exception': get_trade_response["error"]}) for trade in get_trade_response: trade1 = trade["trade"] trade1["amount"] = RealTimeCurrencyExchangeRate(float( trade1["amount"])) return jsonify({'trades': get_trade_response})
def getBalance(userId): result = getSpecificData("crypto_user", "user_id", userId) get_trade_response = client.get_balance(userId, result[7]) if 'balances' not in get_trade_response: return jsonify({'exception': get_trade_response["balances"]}) balances = get_trade_response["balances"] print(balances) if balances: balances["usdValue"] = RealTimeCurrencyExchangeRate( float(balances["usdValue"])) return get_trade_response
def getTrade(userId, tradeID): result = getSpecificData("crypto_user", "user_id", userId) get_trade_response = client.get_trade_status(userId, result[7], tradeID) if 'trade' not in get_trade_response: return jsonify({'exception': get_trade_response["error"]}) trade = get_trade_response["trade"] trade["amount"] = RealTimeCurrencyExchangeRate(float(trade["amount"])) if trade["fromSymbol"] == "INR": updateWalletusers(userId, "SELL", trade["amount"]) if trade["toSymbol"] == "INR": updateWalletusers(userId, "BUY", trade["amount"]) return get_trade_response["trade"]
def createTrade(userId): data = request.get_json() result = getSpecificData("crypto_user", "user_id", userId) data["amount"] = RealTimeCurrencyExchangeRate1(float(data["amount"])) print(round(data["amount"], 2)) create_trade_response = client.create_trade(userId, result[7], data["fromSymbol"], data["toSymbol"], round(data["amount"], 2)) print(create_trade_response) if 'id' not in create_trade_response: return jsonify({'exception': create_trade_response["error"]}) insertTrade(userId, create_trade_response["id"]) return jsonify({'id': create_trade_response["id"]})
def createlimitOrder(userId): data = request.get_json() result = getSpecificData("crypto_user", "user_id", userId) data["price"] = RealTimeCurrencyExchangeRate1(float(data["price"])) create_trade_response = client.place_limit_order(userId, result[7], data["baseSymbol"], data["quoteSymbol"], data["quantity"], round(data["price"], 2), data["side"], data["timeInForce"]) if 'id' not in create_trade_response: return jsonify({'exception': create_trade_response["error"]}) insertTrade(userId, create_trade_response["id"]) return jsonify({'id': create_trade_response["id"]})
def getUserProfile(userId): result = getSpecificData("crypto_user", "user_id", userId) user = User(result[0], result[1], result[2], result[3], result[4], result[5], result[6], result[7], result[8]) print(user) return jsonify({ 'userId': user.id, 'accountId': user.exchangeAccountId, "firstName": user.firstName, "lastNme": user.lastName, "email": user.email, "panNo": user.panNo, "dob": user.dob, "mobileNo": user.mobileNo, "status": user.status })
def updateWalletusers(userId, type, balance): currentTimeStamp = datetime.now(timezone.utc) print(currentTimeStamp) result = getSpecificData("crypto_wallet", "user_id", userId) if (type == 'ADD') or (type == 'SELL'): print(result[2]) new_balance = float(result[2]) + float(balance) print(new_balance) if (type == 'WITHDRAW') or (type == 'BUY'): new_balance = float(result[2]) - float(balance) print(new_balance) print(new_balance) updateWallet(result[0], userId, new_balance, currentTimeStamp) insertWalletHistory(result[0], userId, type, balance, currentTimeStamp, "ACTIVE") return jsonify({'status': 'ok'})
def getlimitOrderAll(userId): result = getSpecificData("crypto_user", "user_id", userId) trades = getSpecificDataList("crypto_trade", "user_id", userId) print(trades) thislist = [] for trade in trades: get_trade_response = client.get_limit_order_status( userId, result[7], trade[1]) if 'order' not in get_trade_response: return jsonify({'exception': get_trade_response["error"]}) print(get_trade_response) trade1 = get_trade_response["order"] trade1["amount"] = RealTimeCurrencyExchangeRate(float( trade1["amount"])) thislist.append(get_trade_response["order"]) print(thislist) return jsonify({'orders': thislist})
def login(emailID): result = getSpecificData("crypto_user", "email", emailID) return jsonify({'userId': result[0]})
def getWalletBalance(userId): result = getSpecificData("crypto_wallet", "user_id", userId) balance = float(result[2]) print("else case", balance) return jsonify({'userId': userId, 'balance': balance})
def getlimitOrderCancel(userId, tradeID): result = getSpecificData("crypto_user", "user_id", userId) get_trade_response = client.cancel_limit_order(userId, result[7], tradeID) return get_trade_response