def buy(self, currency, amount, price): print('BUYING {}{} at ${}'.format(amount, currency, price)) Listing.create(currency=currency, amount=amount, price=price, type='buy', date=datetime.now())
def sell(self, date, currency, amount, price): balance = self.wallet.get(currency) if balance['amount'] != 0 and balance['amount'] >= amount: print('{} SELLING {}{} at ${}'.format(date, amount, currency, price)) Listing.create(currency=currency, amount=amount, price=price, type='sell', date=datetime.now())
def listing_create(): """ Create a new listing. Takes in { listing: { title, description, photo, price, longitude, latitude, beds, rooms, bathrooms, created_by, }} Returns => { listing: { id, title, description, photo, price, longitude, latitude, beds, rooms, bathrooms, created_by, rented_by, } } TODO: Auth required: admin or logged in user """ listing_data = request.json.get("listing") form = ListingCreateForm(data=listing_data) if form.validate(): listing = Listing.create(form) db.session.commit() # TODO: reevaluate error with a try and except later return (jsonify(listing=listing.serialize(isDetailed=True)), 201) else: errors = [] for field in form: for error in field.errors: errors.append(error) return (jsonify(errors=errors), 400)