There will be lots of buying offers (with price and quantity) and a lot of selling offers (also with price and quantity)
I need to make a way to do comparisons (for the same product) between it’s Buy and Sell Prices and quantities (where only when Buy Price ≥ Sell Price and Buy Qtty ≤ Sell Qtty) to start a workflow.
Unfortunately, I can’t find out the correct operator to do it:
I don’t think you are doing the correct process here.
I also think you may not have your DB structured correctly.
Actually, it’s a little it hard to help you, but I guess you display the product on a specific page (of type product).
At this moment, you already have the information about this product. No need to search it again (and also, no need to use do every X sec… if data change, it will be updated in front end too)
What is the goal to compare the Buy price VS sell price? What is the idea behind this? Same for QTY.
I think that what you should search is more related to “offers” and probably “transactions” DB And theses item will be linked to product DB (that shouldn’t probably need your 4 fields… but it may also be a good idea to use them as aggretor and avoid searching offers and transactions DB each time (save WU))
Thanks, @Jici for the very quick answer!
The system that is most similar to my project is the stocks or crypto trading, where there are, for the same “product”, lots of buyers and sellers… buyers willing to pay X price against a seller willing to get Y price:
What is the best way to do such a buy/sell system?
Hi there, not sure if this helps specifically what you are trying to do. But the way I understand this is that you want to match buyers with appropriate sellers and vice versa. One way would be to create a data type called Buy Offers and another Called Sell Offers.
Once you have it laid out that way I think you’ll have an easier time sorting and filtering the way you’d like to. I put this together. When you select an offer on the left it filters the group to its right to show only offers that fit the criteria.
Don’t have two data types. Have one data type called Offer.
User (User) - the user who made the Offer
Type (Option set, Buy or Sell) - whether this is a buy or sell order
Product (Product) - the relevant product
pricePerItem (number) - the price per item
quantity (number) - the quantity of the offer
Status (option set, Open, Cancelled, Completed)
Generally speaking, if you have a DB structure like ‘Buy Offer’/‘Sell Offer’, the repetition of Offer tells you they’re exactly the same thing, just different variants (i.e one data type, with variations defined by an option set). The ‘buy’ or ‘sell’ is a property of the offer (and therefore a field on the offer).
Agreed! The separate types are redundant. But doing things this way first, figuring out the way the filters need to function has been a useful way for me to get unstuck in the past.
Thank you, @georgecollier for the guidance… I’m going to try this out as well as @dnogaki ’s
After solving the DB issue, I’m going to struggle with the workflow for the comparisons check (between orders fields values) making it run actions every X seconds or when order status changes.
As soon as I get some result, I’ll let you both know!