Why when the market price is below a limit buy, why is it not fullfilled? - binance

I am writing a trading bot in C++. I am making limit orders that allow for 1% leniency. As you can see there is a market price of 2.2532, and I made a limit buy at 2.2757. Logically, if the limit buy should be activated once the market price is at or below the limit price. However, as you can see from the pictures below, this is not the case. I posted pictures of both the order book and the trade history. What I am wondering is why. Does this have something to do with the order book? I also noticed when placing market values generally there is a fairly large discrepancy between the price of the market and the average price it is filled at.
Since getting the market price on Binance does not seem to actually tell you if the market order will be full-filled at that price, or if the limit order can go through at a price around there. Is there a way to actually programmatically/mathematically find out if a limit order will go through. Or, find out what the actual average price of a market order will be if bought in that moment?
UPDATE
So when I go to place a market order, I get this message:
Your order price will be 8% higher than the latest market price. Please proceed cautiously. When I want to buy at the market price. Partially I want to know why. But also, is there a way to get the exact number in which this price will be? Also, Is there a way to get this on the API exactly what the next market buy/sell will be?

After some more research on the question. According to investopedia
A trade will only occur when someone is willing to sell the security at the bid price, or buy it at the ask price.
Meaning, the price at which the asset will be sold at has less to do with the current market price, and a lot more to do with the order book. Looking at the pictures above, at that time according to limit orders the lowest someone was willing to sell the asset was, was 2.500 and the highest someone was willing to buy the asset for was 2.499. These are the ask price and bid price respectively. Since no one was willing to buy at the ask price or sell at the bid price, the transaction did not go through. Notice that the quantities are also important for knowing how much of the order will be filled, for your future reference.
For those that might be a little confused, you need to buy at the lowest someone is willing to sell. You need to sell at the highest someone is willing to buy. These come from the limit orders.
Back to the original question, the update on the 8% difference makes sense, the ask price probably dropped a little. However, if you notice 2.2532 * 1.08 is 2.433456 which is much closer to the 2.5 price above than the limit buy created at 2.2757 meaning the 8% notification makes sense.
I will now explain how you would calculate this using mathematics and coding. You need to pull from the order book ticker. This api request is /api/v3/ticker/bookTicker
I am going to use the example of wanting a market buy for GRTUSD. The dictionary you get back from the link https://api.binance.us/api/v3/ticker/bookTicker?symbol=GRTUSD is {"symbol":"GRTUSD","bidPrice":"0.1391","bidQty":"3613.45000000","askPrice":"0.1393","askQty":"5183.18000000"}
Some quick math shows that 5183.18000000 of GRT is the equivalent of a little over 722 USD at the ask price. This means if I placed a market buy for GRTUSD. As long as the amount of USD I was investing at that moment was equivalent to or less than 722 USD it would get filled at the ask price of 0.1393

Related

How to calculate the effort a customer type most likely require of an FTE during a year

I know how many customers of each customer-size group each sales representative handles on an annual basis. Is it possible to calculate the likely time/effort required by each customer size based on this data set? Or said differently, I'm trying to find out if larger customers require more or less effort than smaller customers.
Is there a function or formula in Excel that will allow be to answer the above based on the data set below?
To add some context, in case it is helpful. There are 2080 work hours a year. I'm assuming they spend all their time with the customers under their responsibility. I also expect that the largest customers require more time than a small customers, but I dont know how much more. That is what I'm trying to figure out. Some employees do handle a lot more customers than others, so its probably best to look a the relative difference between the customer sizes for each employee...
Customer size is rated from 0 (very small) to 7 (the largest).
Below is a small data extract of a large Data table

Choosing the right Stripe subscription model if pricing depends on another numerical attribute

I have little experience with payment gateways, and am trying to figure out how to synthesize the type of subscription billing that I am looking for: the monthly price gets rebalanced once a year, based on another attribute (a number that can get as high as seven or eight digits).
So, for example, the monthly subscription price as of January 1st will be a % of a user's credit card debt balance as of Dec 15th in the prior year. But the debt balance can get very high / does not have a cap.
I looked at the Stripe documentation to figure out of there's a way to do this. The only thing I could come up with is to use unit_amount in metered pricing and tying this to the credit balance. In other words, I would grab the debt balance number and use it as the unit_amount, and then apply a %. But then I need to also forward bill, so I trick the logic into shifting by a month, which seem impractical.
Alternatively, I am not sure I could do this with per seat pricing (e.g. $1 in debt = 1 seat). But I assume there's a max to the number of seats (i.e. someone cannot have, say 1m seats). I just couldn't determine this from the documentation...
That's what I was thinking, anyway. Perhaps there's a better way?
You've got a couple different options here:
At the start of the year you update the Subscription to a new price based on the calculations of the customer's credit card debt balance by specifying items[0].price_data. Setting items[0].price_data (see the api ref) allows you to create an "in-line price" that as part of the updating the Subscription, so you don't have to create one separately through a separate API request. If you haven't seen Stripe's docs on how to update the price of a Subscription you can see an example here, and you'll likely want to read about proration_behavior as well.
You have a single Price where 1 seat = $1 in debt, and you control how much you want to charge by changing the number of seats for the Subscription. I don't think Stripe has a limitation to the number of seats (as long as it's a valid integer), but they do have a limitation on the maximum amount you can charge which you can read about here. For USD the maximum charge amount is $999,999.99, so the maximum quantity would be you could specify for a $1 price is 999,999.
You could look into using metered pricing, but given that you don't want to bill at the end of the billing cycle the other two options seem better.
I think the first option (updating the price year by year) is your best one, but definitely try all of them out in test mode and take a look at how the Invoices look to see which one you like best.

How can I set up a weighted average of purchase price for something that I might sell part amounts of?

I have a weighted average set up like this:
=IFERROR(SUMPRODUCT(Purchases_XYZ[Cost Per Unit],Purchases_XYZ[Cost])/SUM(Purchases_XYZ[Cost]),"")
The full table includes:
Purchases_XYZ[Date], Purchases_XYZ[Cost], Purchases_XYZ[Units], Purchases_XYZ[Cost Per Unit], Purchases_XYZ[Extras], Purchases_XYZ[Location]
But what if I sell 30% of my units at Location "b"? Then I need to manually decrease the number of units I have left at Location "b".
What if I sell all the units at Location "d"? Then my weighted average can no longer be counted because there is no longer any of that unit left at that price.
I can do the manual stuff - that wouldn't be impossible. But I feel like I am making more work than it needs to be. If you have solutions to offer, I am keen to hear how it could be done.

Choose correct PRODUCT COST from ROW based on amount sold

I am making a sheet to CALCULATE REAL REVENUE from each sale I make on my online store.
The problem is that the COST of my products is not always constant. It varies depending on many factors so each time I make a purchase I add the NEW PRODUCTS COST (LATEST COST).
Each time I make a new purchase I will add the QUANTITY and the new COST. (PURCHASE 1, PURCHASE 2, PURCHASE 3,etc).
Screenshoot of my sheet with example on ROW 41
In Column B I want to know which is the CURRENT COST based on the amount of TOTAL SALES of each product.
For example:
If I have sold less than 100 ( Pruchase 1 QUANTITY) then I need the formula to choose value of E41 (PURCHASE 1 COST).
If I have sold MORE than 100 and LESS than 300 (which is the SUM of PURCHASE 1 & PURCHASE 2) I need the formula to choose value of G41 (PURCHASE 2 COST) AND SO ON...
The formula I have come up with so far is this:
=INDEX(41:41,,IF(C41<=D41,COLUMN(E41),IF(C41<=D41+F41,COLUMN(E41)+2,IF(C41<=D41+F41+H41,COLUMN(E41)+4,COLUMN(E41)+6))))
This formula WORKS but only for the first 3 PURCHASES.
I need a formula that has no limit but I don't know how to make a VARIABLE formula.
Please take my words literally when I say that I wouldn't waste one minute on trying to solve your problem with your current sheet design. You would need VBA, and then extract quantities and prices from each purchase without the ability to filter on columns. (Minute is up.)
What you need is a Purchase database: ItemID, Date, Quantity, Price, maybe Ref#. From that you can pull out the transactions for any item by filtering on the item and the cost by using functions like SUMIF. However, this just brings the real problem within reach without solving it.
The problem is that when you buy 100 pcs #42 your price is 42. Then you buy another 100 pieces #46 your average price is 44. But if you sold 50 pieces with a cost of 42 then the average cost of the remaining 150 is 45. Therefore you can't determine the average cost of any remainder without knowing the quantity sold and the average cost applied to that sale. To solve that problem you will still need VBA but the suggested db format of purchase record would at least support such a solution.
Not so long ago I programmed a solution where there were additional columns in the db and each sale was recorded in 3 columns (much like your present purchase record): date, Qty, Ref. In this way I could trace the sale of each individual purchase (this was for shares trading). The sale of the newer quantity wouldn't start until the earlier quantity was sold out.
Perhaps you don't need to trace where the purchased quantity went to and just need one column to count down the balance to zero. That would be much simpler but has the drawback that you can't roll back errors. In the end the rollback was the reason why I abandoned the design. The key to the ability to abandon it is a similar db for sales: date, qty, price, Ref#.
With such a setup you might design a system to either extract the average or FiFo price from the purchase side and associate it with a sale. If the condition is that it should be done with worksheet functions you could add a column for "current cost" in the purchase db, changing with each purchase, which you look up by date from the sales side using VLOOKUP or SUMPRODUCT, having set a cost price applicable from the day of purchase until the next. If that appeals to you, a method must be found to deal with days on which there are both purchases and sales.

MS Access 2003 - Calculating an average based on qty sold/per site with supply %

Here is another question I have about being able to calculate this scenario in Access, or even at all for that matter:
I have a query that find the TOP 5 items sold in a given timeframe, and it groups by site. I use this to create a comparative chart between the site for ppt presentations. I do a lot of these but I have a problem with the presentation that I foresee they will have a problem with and it makes for bad metrics:
Some stores are bigger than others, and get much more supply. So a straight aggregate total of just qty of toping selling items, and comparing the locations is stacking the deck a little.
So if Site A gets 80% of the supply, and sells 500, Site B gets 15% supply and sell 75, and site C get 5% supply and sells 50 items, then Site C actually has the best sales for their size. I have exactly what I need in terms in the first chart (from my queries and such) to show the aggregate total, but what do I need to represent the idea mentioned above.
The factors that I have that go into this are:
ItemID - group by
Item - group by
qty sold - sum/descending (which is the variable that determines the Top 5)
Store/Location - Group By
and then I run a seperate query to get the total deliveries (supply) to each site
I realize that this may just be a lack of mathmatical understanding on my part, but can anyone help with this?
thanks
The first issue that I see isn't about SQL savvy; it's how to serve your data customer. What does he or she want to see? Metrics is a term with a holy ring, and for good reason: it's supposed to be what is used for the big business decisions, and it's scary easy to measure the wrong thing.
So I'd make sure I know what my customer wants. If you can't model it on a spreadsheet, you won't be able to develop your reporting effectively.
Every deck of cards is loaded. You have to know how they want it loaded.

Resources