Bittrex api market change calculation - cryptocurrency

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%

Related

How to skip rows with the same values

I have the following problem: I have a dataset with over 1million entries (shown below), that includes the variables company (=Name of the company (string)) and reviews (=amount of reviews a company received) and company1 (assigns numeric to specific company name). Now I want to calculate the average amount of reviews a company in the dataset receives. But if I just do sum reviewsthen it will count the amount of reviews of company 3 two times, the amount of reviews of company five 23 times etc. (as often as they are listed in the data). How do I avoid this and only count them once?
Your image is not readable (by me on a laptop). The Stata tag wiki gives detailed advice on how to give data examples and the command dataex bundled with recent versions of Stata is easily used for SE.
The flavour of your request is easier to follow. Here is an analogue. With the Grunfeld data we can calculate a mean investment for each year.
webuse grunfeld, clear
egen mean = mean(invest), by(year)
Now we might want to know how many years had mean invest above 200 (in the units used)?
su mean if mean > 200
or
count if mean > 200
returns the number of observations (not years). If you try it, the result is 30. In the Grunfeld data, there are 10 companies each measured for each year, so dividing by 10 is an easy answer. For more complicated datasets, it would better to tag each year just once, and then look only at tagged observations:
egen tag = tag(year)
count if tag & mean > 200
It would be more common to tag panels, not years, but the principle is the same. See the help for egen.
collapse and contract offer other routes, with or without using frames.

Is it possible to get the price of bitcoin in USD from the coinbase API for a specific time in the past?

GET https://api.coinbase.com/v2/prices/:currency_pair/spot
This price seems to be the current price
This question already has answers. Copy and pasted from here: Coinbase API v2 Getting Historic Price for Multiple Days
Any reason you aren't using coinbase pro?
The new api is very easy to use. Simply add the get command you want followed by the parameters separated with a question mark. Here is the new historic rates api documentation: https://docs.pro.coinbase.com/#get-historic-rates
The get command with the new api most similar to prices is "candles". It requires three parameters to be identified, start and stop time in iso format and granularity which is in seconds. Here is an example:
https://api.pro.coinbase.com/products/BTC-USD/candles?start=2018-07-10T12:00:00&stop=2018-07-15T12:00:00&granularity=900
EDIT: also, note the time zone is not for your time zone, I believe its GMT.

Using Binance API Results

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)

Drupal commerce multicurrency

So I'm trying to change to currency on my local drupal site (with room module) from USD to INR. The unit price gets converted just fine but when is comes to the order total, it's just wrong. For instance:
I booked a single room that costs 1000 INR
I booked a double room that costs 1200 INR
But when it comes to the order total, it sums up to be something like 141200 INR instead of 2200 INR. I can't seem to solve this.
You have provided no information about how you are handling your converting but the problem is pretty clear.
You are converting the price twice, thats the issue. Somehow in the current situation the system thinks the 2200 total price is in USD, and calculates it to IND.

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