You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
913B

  1. SELECT hr,
  2. bmex / gdax AS ratio
  3. FROM
  4. (SELECT hr,
  5. max(gdax) "gdax", -- max(..) necessary to grab the non-NULL row from two returned
  6. max(bmex) "bmex" -- rows for each hr
  7. FROM
  8. (SELECT hr,
  9. (CASE
  10. WHEN exch=3 THEN wt_avg
  11. END) "gdax",
  12. (CASE
  13. WHEN exch=6 THEN wt_avg
  14. END) "bmex"
  15. FROM
  16. (SELECT hr,
  17. exch,
  18. w_sum / sum_w AS wt_avg
  19. FROM
  20. (SELECT date_trunc('hour', "time") AS hr,
  21. exch,
  22. sum(price * amount) AS w_sum,
  23. sum(amount) AS sum_w
  24. FROM trades
  25. WHERE base=1 -- btc=1 usd=100
  26. AND quote=100
  27. AND (exch=3 OR exch=6) -- gdax=3, bmex=6
  28. GROUP BY 1, 2
  29. ORDER BY 1, 2) a) b) c
  30. GROUP BY hr) d;