def read_transaction_by_id(transaction_id): session = get_session(current_app) txn = session.query(Transaction).filter( Transaction.id == transaction_id).first() if not txn: return error_out(MissingResourceError('Transaction')) return jsonify(txn.shallow_json), 200
def read_markets_for_product(product_id): session = get_session(current_app) markets = session.query(Market).filter( Market.product_id == product_id).all() if not markets: return error_out(MissingResourceError('Market')) return jsonify([market.shallow_json for market in markets]), 200
def read_hs_prices(product_id, exchange_id, source_id): end_date = date.today() if request.args.get('endDate'): end_date = datetime.strptime(request.args.get('startDate'), '%Y-%m-%d').date() start_date = end_date - relativedelta(days=365) if request.args.get('startDate'): start_date = datetime.strptime(request.args.get('startDate'), '%Y-%m-%d').date() session = get_session(current_app) dly_prices = session.query(DailyPrice) \ .filter(DailyPrice.product_id == product_id) \ .filter(DailyPrice.exchange_id == exchange_id) \ .filter(DailyPrice.source_id == source_id) \ .filter(DailyPrice.date >= start_date) \ .filter(DailyPrice.date <= end_date) \ .order_by(DailyPrice.date) \ .all() if not dly_prices: return error_out(MissingResourceError('DailyPrice')) return jsonify([px.highchart_json for px in dly_prices]), 200
def read_alert_type_by_id(alert_type_id): shallow = False if request.args.get('shallow') == 'false' else True session = get_session(current_app) alert_type = session.query(AlertType).filter(AlertType.id == alert_type_id).first() if not alert_type: return error_out(MissingResourceError('AlertType')) if shallow: return jsonify(alert_type.shallow_json), 200 return jsonify(alert_type.json), 200
def read_alert_by_id(alert_id): shallow = True if request.args.get('shallow') == 'true' else False session = get_session(current_app) alert = session.query(Alert).filter(Alert.id == alert_id).first() if not alert: return error_out(MissingResourceError('Alert')) if shallow: return jsonify(alert.shallow_json), 200 return jsonify(alert.json), 200
def read_currency_by_id(currency_id): shallow = False if request.args.get('shallow') == 'false' else True session = get_session(current_app) currency = session.query(Currency).filter( Currency.id == currency_id).first() if not currency: return error_out(MissingResourceError('Currency')) if shallow: return jsonify(currency.shallow_json), 200 return jsonify(currency.json), 200
def delete_cut(cut_id): """ DELETE request to /api/v1.0/cut/<cut_id> will delete the target Cut object from the database """ session = get_session(current_app) cut = session.query(Cut).filter(Cut.id == cut_id).first() if not cut: return error_out(MissingResourceError('Cut')) session.delete(cut) session.commit() return jsonify(200)
def delete_exchange(exchange_id): """ DELETE request to /api/v1.0/exchange/<exchange_id> will delete the target Exchange object from the database """ session = get_session(current_app) exchange = session.query(Exchange).filter(Exchange.id == exchange_id).first() if not exchange: return error_out(MissingResourceError('Exchange')) session.delete(exchange) session.commit() return jsonify(200)
def delete_alert(alert_id): """ DELETE request to /api/v1.0/alert/<alert_id> will delete the target Alert object from the database """ session = get_session(current_app) alert = session.query(Alert).filter(Alert.id == alert_id).first() if not alert: return error_out(MissingResourceError('Alert')) session.delete(alert) session.commit() return jsonify(200)
def delete_product(product_id): """ DELETE request to /api/v1.0/product/<product_id> will delete the target Product object from the database """ session = get_session(current_app) product = session.query(Product).filter(Product.id == product_id).first() if not product: return error_out(MissingResourceError('Product')) session.delete(product) session.commit() return jsonify(200)
def delete_market(market_id): """ DELETE request to /api/v1.0/market/<market_id> will delete the target Market object from the database """ session = get_session(current_app) market = session.query(Market).filter(Market.id == market_id).first() if not market: return error_out(MissingResourceError('Market')) session.delete(market) session.commit() return jsonify(200)
def delete_user(user_id): """ DELETE request to /api/v1.0/user/<user_id> will delete the target User object from the database """ session = get_session(current_app) user = session.query(User).filter(User.id == user_id).first() if not user: return error_out(MissingResourceError('User')) session.delete(user) session.commit() return jsonify(200)
def delete_holding(holding_id): """ DELETE request to /api/v1.0/holding/<holding_id> will delete the target Holding object from the database """ session = get_session(current_app) holding = session.query(Holding).filter(Holding.id == holding_id).first() if not holding: return error_out(MissingResourceError('Holding')) session.delete(holding) session.commit() return jsonify(200)
def delete_wallet_data(wallet_data_id): """ DELETE request to /api/v1.0/wallet/<wallet_id> will delete the target WalletData object from the database """ session = get_session(current_app) wd = session.query(WalletData).filter(WalletData.id == wallet_data_id).first() if not wd: return error_out(MissingResourceError('WalletData')) session.delete(wd) session.commit() return jsonify(200)
def delete_transaction(transaction_id): """ DELETE request to /api/v1.0/transaction/<transaction_id> will delete the target Transaction object from the database """ session = get_session(current_app) transaction = session.query(Transaction).filter( Transaction.id == transaction_id).first() if not transaction: return error_out(MissingResourceError('Transaction')) session.delete(transaction) session.commit() return jsonify(200)
def update_wallet_data(wallet_data_id): """ PUT request to /api/wallet/<wallet_id> will update WalletData object <id> with fields passed """ session = get_session(current_app) put_data = request.json if not put_data: return error_out(MissingJSONError()) wd = session.query(WalletData).filter(WalletData.id == wallet_data_id).first() if not wd: return error_out(MissingResourceError('WalletData')) for k, v in put_data.items(): setattr(wd, k, v) session.add(wd) session.commit() return jsonify(wd.shallow_json), 200
def update_user(user_id): """ PUT request to /api/user/<exchane_id> will update User object <id> with fields passed """ session = get_session(current_app) put_data = request.json if not put_data: return error_out(MissingJSONError()) user = session.query(User).filter(User.id == user_id).first() if not user: return error_out(MissingResourceError('User')) for k, v in put_data.items(): setattr(user, k, v) session.add(user) session.commit() return jsonify(user.shallow_json)
def update_product(product_id): """ PUT request to /api/product/<exchane_id> will update Product object <id> with fields passed """ session = get_session(current_app) put_data = request.json if not put_data: return error_out(MissingJSONError()) product = session.query(Product).filter(Product.id == product_id).first() if not product: return error_out(MissingResourceError('Product')) for k, v in put_data.items(): setattr(product, k, v) session.add(product) session.commit() return jsonify(product.shallow_json)
def update_alert(): """ PUT request to /api/alert/<alert_id> will update Alert object <id> with fields passed """ session = get_session(current_app) put_data = request.json if not put_data: return error_out(MissingJSONError()) alert = session.query(Alert).filter(Alert.id == put_data['id']).first() if not alert: return error_out(MissingResourceError('Alert')) for k, v in put_data.items(): setattr(alert, k, v) session.add(alert) session.commit() return jsonify(alert.shallow_json)
def update_market(market_id): """ PUT request to /api/market/<exchane_id> will update Market object <id> with fields passed """ session = get_session(current_app) put_data = request.json if not put_data: return error_out(MissingJSONError()) market = session.query(Market).filter(Market.id == market_id).first() if not market: return error_out(MissingResourceError('Market')) for k, v in put_data.items(): setattr(market, k, v) session.add(market) session.commit() return jsonify(market.shallow_json), 200
def update_exchange(exchange_id): """ PUT request to /api/exchange/<exchange_id> will update Exchange object <id> with fields passed """ session = get_session(current_app) put_data = request.json if not put_data: return error_out(MissingJSONError()) exchange = session.query(Exchange).filter(Exchange.id == exchange_id).first() if not exchange: return error_out(MissingResourceError('Exchange')) for k, v in put_data.items(): setattr(exchange, k, v) session.add(exchange) session.commit() return jsonify(exchange.shallow_json)
def update_holding(holding_id): """ PUT request to /api/holding/<holding_id> will update Holding object <id> with fields passed """ session = get_session(current_app) put_data = request.json if not put_data: return error_out(MissingJSONError()) holding = session.query(Holding).filter(Holding.id == holding_id).first() if not holding: return error_out(MissingResourceError('Holding')) for k, v in put_data.items(): setattr(holding, k, v) session.add(holding) session.commit() return jsonify(holding.shallow_json)
def update_currency(): """ PUT request to /api/currency/<currency_id> will update Currency object <id> with fields passed """ session = get_session(current_app) put_data = request.json if not put_data: return error_out(MissingJSONError()) currency = session.query(Currency).filter( Currency.id == put_data['id']).first() if not currency: return error_out(MissingResourceError('Currency')) for k, v in put_data.items(): setattr(currency, k, v) session.add(currency) session.commit() return jsonify(currency.shallow_json)
def update_transaction(transaction_id): """ PUT request to /api/transaction/<transaction_id> will update Transaction object <id> with fields passed """ session = get_session(current_app) put_data = request.json if not put_data: return error_out(MissingJSONError()) transaction = session.query(Transaction).filter( Transaction.id == transaction_id).first() if not transaction: return error_out(MissingResourceError('Transaction')) for k, v in put_data.items(): setattr(transaction, k, v) session.add(transaction) session.commit() return jsonify(transaction.shallow_json), 200
def delete_wallet(wallet_id): """ DELETE request to /api/v1.0/wallet/<wallet_id> will delete the target Wallet object from the database """ session = get_session(current_app) wallet = session.query(Wallet).filter(Wallet.id == wallet_id).first() qr_base = '/coinpl/coinpl/static/img/qrcodes/wallet_qr_{}.png' filename_qr = qr_base.format(wallet.id) if not wallet: return error_out(MissingResourceError('Wallet')) wallet.deactivated = True session.add(wallet) session.commit() if os.path.exists(filename_qr): os.remove(filename_qr) return jsonify(200)
def read_holdings(): session = get_session(current_app) holdings = session.query(Holding).all() if not holdings: return error_out(MissingResourceError('Holding')) return jsonify([holding.shallow_json for holding in holdings]), 200
def read_market_by_id(market_id): session = get_session(current_app) exch = session.query(Market).filter(Market.id == market_id).first() if not exch: return error_out(MissingResourceError('Market')) return jsonify(exch.shallow_json), 200
def read_currencies(): session = get_session(current_app) currencies = session.query(Currency).all() if not currencies: return error_out(MissingResourceError('Currency')) return jsonify([currency.shallow_json for currency in currencies]), 200
def read_holding_by_id(holding_id): session = get_session(current_app) holding = session.query(Holding).filter(Holding.id == holding_id).first() if not holding: return error_out(MissingResourceError('Holding')) return jsonify(holding.shallow_json), 200
def read_users(): session = get_session(current_app) users = session.query(User).all() if not users: return error_out(MissingResourceError('User')) return jsonify([user.shallow_json for user in users]), 200