Using Binance API Results - cryptocurrency

I've recently started making calls to Binance API, specifically this:
https://api.binance.com/api/v3/ticker/24hr?symbol=BTCBUSD
This call only seems to have 1 parameter (symbol). My question concerns the meaning of the returned fields, or how to interpret them.
Here is a sample of returned data from the above call.
{
"symbol": "BTCBUSD",
"priceChange": "1519.63000000",
"priceChangePercent": "3.308",
"weightedAvgPrice": "47059.10006256",
"prevClosePrice": "45935.14000000",
"lastPrice": "47454.77000000",
"lastQty": "0.08014400",
"bidPrice": "47454.76000000",
"bidQty": "0.00858100",
"askPrice": "47454.77000000",
"askQty": "0.22488900",
"openPrice": "45935.14000000",
"highPrice": "48444.00000000",
"lowPrice": "45044.05000000",
"volume": "18094.48897600",
"quoteVolume": "851510367.30253731",
"openTime": 1614347997320,
"closeTime": 1614434397320,
"firstId": 116330237,
"lastId": 117165845,
"count": 835609
}
What does openPrice and prevClosePrice actually mean? They change between each call.
How does priceChange and priceChangePercent work? What fields are these values calculated from? And why are they markedly different to what I see when viewing Binance site for BTC/BUSD 24 HR period at the same time as I make the call?
Can anyone shed some light on these figures? I've searched online but not been able to find anything descriptive.
When I calculate the price change percent based on the difference between lastPrice and openPrice I get the following result which does match the priceChangePercent value.
((47454.77 - 45935.14) / 45935.14) * 100 = 3.308

openPrice = last candle started at this price
prevClosePrice = last 2nd candle closed at this price (it must be same with next candles open price)
priceChange = difference between start of the day price and current price (start of the day 00.00 in UTC i guess)
priceChangePercent = same with priceChange but percentage (also you can see in binance symbol lists these things, just order by change)

Related

Use result previous row as start value for next line

I'm working on an MRP simulation in which I have to subtract demand or add supply qty to available stock and I hope you can be of support. Find below the result I want to achieve.
I have 1 value for stock = 22 and a lot of values for future demand/supply on specific dates.
Part
Stock
Demand/Supply qty
Demand/Supply Date
Result
1000680
22
-1
2023-01-01
21
1000680
21* what I want to achieve
-15
2023-01-02
6* expected outcome
1000680
6* what I want to achieve
+10
2023-01-03
16* expected outcome
I'm still on the SQL learning curve. I started to add rownumbers to the lines to make sure that the sequence is correct:
select
 part,
 rownum = ROW_NUMBER() OVER (ORDER BY part, mrp_due_date),
 current_stock_qty,
 demand_supply_qty,
 
 current_stock - qty as new_stock_qty, -- if demand
 current_stock + qty as new_stock_qty, -- if supply
 mrp_due_date
from #base
Then I tried the lag function to derive previous row 'new_stock_qty' at date but this only worked for the first line (see image:
)
So I probably need the loop function to first calculate stock-demand and use the result as new stock.
I have looked through similar questions asked on this site, but I find it difficult to define my solution based on that information.

Bittrex api market change calculation

Does anyone know how Bittrex calculates the market change (shown in the image) and which values i can use to replicate it
Using the "Last Price" from https://api.bittrex.com/api/v1.1/public/getmarketsummary?market=btc-fsn gives me a different value
It looks that "PrevDay" field in API response reflects the price exactly 24 hours ago. Same for some other exchanges and data providers.
Actually % change on website should be based on same, but this may depend on how often data is refreshed in browser.
This percentage sign shows how much % market has been chnaged in last 24 hours
Like prev btc price=8000 and new btc price =8500
so market change 8500-8000=(500/8000)*100=6.25%

SOLR and complex pricing

We have a property booking site (similar to Airbnb) with a LAMP setup and a relatively simple SOLR index. A user can search by:
Location
Guests
Date IN/OUT
They can also filter results for a specific price range, as well as sort by price.
The issue is that price per night is never fixed, and is depends on several things such as custom prices (for one day, or a range of days), price per guest, discounts (e.g. weekend discount) etc. One example could be that price_per_night might be 50$, however for the 10th and 11th of August the real price per night could be 110$ plus 20$ extra guest fee, minus a discount of 30$ for that particular weekend. On top of this, commissions are applied on the total amount so we'd like this to be as accurate as possible.
While we can calculate this on the server side, this of course affects the results returned for a price range as well as the sorting (highest price first vs. lowest).
Could anyone suggest any possible solution?
Below is an example of a select:
"docs": [
{
"id": 1,
"property_type": 1,
"room_type": 1,
"minimum_nights": 2,
"maximum_nights": 120,
"location": "41.3902359,2.1685901",
"price_per_night": 210,
........
"unavailable_days": [
"2016-09-15T00:00:00Z",
"2016-09-16T00:00:00Z",
......
]
}

Newrelic custom plugin metrics

I'm working directly with the HTTP API and trying to get some metrics from our storage.
The doc states "Tip: If you want the metric to appear as a percentage in the user interface, then you must define it as a percentage in the JSON."
However - I can't send metric values which are percentages; the POST response has status 400 with body
{"error":"Unable to parse request: null"}
My POST is
{"components": [
{"duration": 1,
"guid": "com.cumulus.Test5",
"name":"ServerX",
"metrics": {
"Component/Filesystem/root/Percentage Used": "62%"
}
}],
"agent": {"host": "vss-syd", "version": "1.0.0", "pid": 1080}
}
Also - I have a metric "Number of devices offline" (for a ZFS storage pool) which is discrete i.e. not continuous - so averages don't make sense, just absolute values.
For which I'd like to set an alert if it gets above 0.
I know the threshold is only 'greater than', so I can set thresholds # 0.1 Alert & 0.2 Critical no prob.
However - please can someone point me in the right direction as to how I should
Send such a metric (i.e. need to specify [units] and aggregates?)
Create the Summary Metric + Graphs in the frontend? (which 'Value' to select e.g. 'Calls per minute')
There are two issues that look like they could be the cause.
The first is that the duration should be 60, which represents the number of seconds for which the reported metrics correspond. NewRelic is optimized to work with this particular interval and while you can have larger values (300 seconds is the recommended maximum), the minimum required value is 60. Smaller values may be accepted by the API, but the results will be unpredictable.
The second is that the percentage used is a string value which should instead be reported as an integer value, such as 62, or a float value of 62.0 if you wish to preserve that level of precision.
Regarding the second portion of your question about reporting and displaying a metric related to "# of Failing Disks":
New Relic does not currently support reporting metrics that represent absolute values. All metric values are presented in aggregate over some particular time period. Summary Metrics are aggregated over the most recent ~4 minutes, while metrics on charts and tables are aggregated over the time period selected in the time picker.
That said, you could try something along the lines of "percentage of failing disks" where perhaps an average might still be useful in that any non-zero value indicates a failure.
This average would be of questionable value once the aggregation time period became larger than a few minutes. However, given that summary metrics are always aggregated over a fixed time period of ~4 minutes — and it is summary metrics that trigger alerts — this may still be useful to you.

How to keep track changing items in a stock portfolio?

I have a system where people can pick some stocks and it values their portfolios but I'm having trouble doing this in a efficient way on a daily basis because I'm creating entries for days that don't have any changes(think of it like I'm measuring the values and having version control so I can track changes to the way the portfolio is designed).
Here's a example(each day's portfolio with stock name and weight):
Day1:
ibm = 10%
microsoft = 50%
google = 40%
day5:
ibm = 20%
microsoft = 20%
google = 40%
cisco = 20%
I can measure the value of the portfolio on day1 and understand I need to measure it again on day5(when it changed) but how do I measure day2-4 without recreating day1's entry in the database?
My approach right now(which I don't like) is to create a temp entry in my database for when someone changes the portfolio and then at the end of the day when I calculate the values if there is a temp entry I use that otherwise I create a new entry(for day2-4) using the last days data. The issue is as data often doesn't change I'm creating entries that are basically duplicates. The catch is: my stock data is all daily. I also thought of taking the portfolio and if it hasn't been updated in 3 days to find the returns of the last 3 days for each stock but I wasn't sure if there was a better solution.
Any ideas? I think this is a straight forward problem but I just can't see a efficient way of doing it.
note: in finance terms, its called creating a NAV and most firms do it the inefficient way I'm doing it but its because the process was created like 50 years ago and hasn't changed. I think this problem is very similar to version control but I can't seem to make a solution.
In storage terms is makes most sense to just store:
UserId - StockId1 - 23% - 2012-06-25
UserId - StockId2 - 11% - 2012-06-26
UserId - StockId1 - 20% - 2012-06-30
So you see that stock 1 went down at 30th. Now if you want to know the StockId1 percentage at the 28th you just select:
SELECT *
FROM stocks
WHERE datecolumn<=DATE(2012-06-28)
ORDER BY datecolumn DESC LIMIT 0,1
If it gives nothing back you did not have it, otherwise you get the last position back.
BTW. if you need for example a graph of stock 1 you could left join against a table full of dates. Then you can fill in the gaps easily.
Found this post here for example:
UPDATE mytable
SET number = (#n := COALESCE(number, #n))
ORDER BY date;
SQL QUERY replace NULL value in a row with a value from the previous known value

Resources