生成汇率K线的脚本 - Xiaotian0617/Center GitHub Wiki


CREATE CONTINUOUS QUERY calc_rate_1m ON PriceRate 
RESAMPLE EVERY 15s FOR 2m
BEGIN 
SELECT last("rate") as "rate",last("key") as "key"
INTO "PriceRate"."1d"."priceRate1m" 
FROM "TopCoinDB"."autogen"."price_rate" 
GROUP BY *,time(1m) 
END;

CREATE CONTINUOUS QUERY calc_rate_3m ON PriceRate 
RESAMPLE EVERY 15s FOR 6m
BEGIN 
SELECT last("rate") as "rate",last("key") as "key"
INTO "PriceRate"."3d"."priceRate3m" 
FROM "PriceRate"."1d"."priceRate1m" 
GROUP BY *,time(3m) 
END;

CREATE CONTINUOUS QUERY calc_rate_5m ON PriceRate 
RESAMPLE EVERY 15s FOR 10m
BEGIN 
SELECT last("rate") as "rate",last("key") as "key"
INTO "PriceRate"."5d"."priceRate5m" 
FROM "PriceRate"."1d"."priceRate1m" 
GROUP BY *,time(5m) 
END;

CREATE CONTINUOUS QUERY calc_rate_10m ON PriceRate 
RESAMPLE EVERY 15s FOR 20m
BEGIN 
SELECT last("rate") as "rate",last("key") as "key"
INTO "PriceRate"."10d"."priceRate10m" 
FROM "PriceRate"."5d"."priceRate5m" 
GROUP BY *,time(10m) 
END;

CREATE CONTINUOUS QUERY calc_rate_15m ON PriceRate 
RESAMPLE EVERY 15s FOR 30m
BEGIN 
SELECT last("rate") as "rate",last("key") as "key"
INTO "PriceRate"."15d"."priceRate15m" 
FROM "PriceRate"."5d"."priceRate5m" 
GROUP BY *,time(15m) 
END;

CREATE CONTINUOUS QUERY calc_rate_30m ON PriceRate 
RESAMPLE EVERY 15s FOR 1h
BEGIN 
SELECT last("rate") as "rate",last("key") as "key"
INTO "PriceRate"."30d"."priceRate30m" 
FROM "PriceRate"."15d"."priceRate15m" 
GROUP BY *,time(30m) 
END;

CREATE CONTINUOUS QUERY calc_rate_1h ON PriceRate 
RESAMPLE EVERY 15s FOR 2h
BEGIN 
SELECT last("rate") as "rate",last("key") as "key"
INTO "PriceRate"."60d"."priceRate1h" 
FROM "PriceRate"."30d"."priceRate30m" 
GROUP BY *,time(1h) 
END;

CREATE CONTINUOUS QUERY calc_rate_2h ON PriceRate 
RESAMPLE EVERY 15s FOR 4h
BEGIN 
SELECT last("rate") as "rate",last("key") as "key"
INTO "PriceRate"."120d"."priceRate2h" 
FROM "PriceRate"."60d"."priceRate1h" 
GROUP BY *,time(2h) 
END;

CREATE CONTINUOUS QUERY calc_rate_4h ON PriceRate 
RESAMPLE EVERY 15s FOR 8h
BEGIN 
SELECT last("rate") as "rate",last("key") as "key"
INTO "PriceRate"."240d"."priceRate4h" 
FROM "PriceRate"."120d"."priceRate2h" 
GROUP BY *,time(4h) 
END;

CREATE CONTINUOUS QUERY calc_rate_6h ON PriceRate 
RESAMPLE EVERY 15s FOR 12h
BEGIN 
SELECT last("rate") as "rate",last("key") as "key"
INTO "PriceRate"."360d"."priceRate6h" 
FROM "PriceRate"."120d"."priceRate2h" 
GROUP BY *,time(6h) 
END;

CREATE CONTINUOUS QUERY calc_rate_12h ON PriceRate 
RESAMPLE EVERY 15s FOR 1d
BEGIN 
SELECT last("rate") as "rate",last("key") as "key"
INTO "PriceRate"."720d"."priceRate12h" 
FROM "PriceRate"."360d"."priceRate6h" 
GROUP BY *,time(12h) 
END;

CREATE CONTINUOUS QUERY calc_rate_1d ON PriceRate 
RESAMPLE EVERY 15s FOR 2d
BEGIN 
SELECT last("rate") as "rate",last("key") as "key"
INTO "PriceRate"."1dINF"."priceRate1D" 
FROM "PriceRate"."720d"."priceRate12h" 
GROUP BY *,time(1d) 
END;

CREATE CONTINUOUS QUERY calc_rate_3d ON PriceRate 
RESAMPLE EVERY 15s FOR 6d
BEGIN 
SELECT last("rate") as "rate",last("key") as "key"
INTO "PriceRate"."3dINF"."priceRate3D" 
FROM "PriceRate"."1dINF"."priceRate1D" 
GROUP BY *,time(3d) 
END;

CREATE CONTINUOUS QUERY calc_rate_1w ON PriceRate 
RESAMPLE EVERY 15s FOR 2w
BEGIN 
SELECT last("rate") as "rate",last("key") as "key"
INTO "PriceRate"."1wINF"."priceRate1W" 
FROM "PriceRate"."1dINF"."priceRate1D" 
GROUP BY *,time(1w) 
END;