From 4ba8cd7161cbdeaf8178c21b073dc40187ba3bb6 Mon Sep 17 00:00:00 2001 From: Jonathan Strong Date: Fri, 3 Apr 2020 14:32:54 -0400 Subject: [PATCH] postgres changes --- Cargo.toml | 2 +- postgres-creat-trades-table.sql | 143 +++++++++++++++++--------------- src/munge.rs | 16 ++-- 3 files changed, 81 insertions(+), 80 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e079f48..133a7d2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,7 @@ csv = "1.1" structopt = "0.3" serde = { version = "1", features = ["derive"] } serde_json = "1" -markets = { version = "0.2.1", registry = "jstrong-dev" } +markets = { version = "0.3.0", registry = "jstrong-dev" } slog = "2" slog-async = "2" slog-term = "2" diff --git a/postgres-creat-trades-table.sql b/postgres-creat-trades-table.sql index 284e66d..5a17922 100644 --- a/postgres-creat-trades-table.sql +++ b/postgres-creat-trades-table.sql @@ -1,51 +1,28 @@ -CREATE SEQUENCE public.trades_id_seq +CREATE SEQUENCE trades_id_seq INCREMENT 1 MINVALUE 1 MAXVALUE 9223372036854775807 START 1 CACHE 1; -ALTER TABLE public.trades_id_seq - OWNER TO jstrong; --- CREATE SEQUENCE public.exchangess_id_seq --- INCREMENT 1 --- MINVALUE 1 --- MAXVALUE 255 --- START 1 --- CACHE 1; --- ALTER TABLE public.exchangess_id_seq --- OWNER TO jstrong; --- --- CREATE SEQUENCE public.currencies_id_seq --- INCREMENT 1 --- MINVALUE 1 --- MAXVALUE 255 --- START 1 --- CACHE 1; --- ALTER TABLE public.currencies_id_seq --- OWNER TO jstrong; - - -CREATE TABLE public.exchanges +CREATE TABLE exchanges ( id smallint NOT NULL, symbol character varying(4) NOT NULL, CONSTRAINT exchanges_pkey PRIMARY KEY (id) +); -) WITH ( OIDS=FALSE ); - -CREATE TABLE public.currencies +CREATE TABLE currencies ( id smallint NOT NULL, symbol character varying(6) NOT NULL, CONSTRAINT currencies_pkey PRIMARY KEY (id) +); -) WITH ( OIDS=FALSE ); - -CREATE TABLE public.trades +CREATE TABLE trades ( id integer NOT NULL DEFAULT nextval('trades_id_seq'::regclass), "time" timestamp with time zone NOT NULL, @@ -56,66 +33,96 @@ CREATE TABLE public.trades price double precision NOT NULL, side smallint NULL, -- side has no fk ... bid=1, ask=2 server_time timestamp with time zone NULL, + CONSTRAINT trades_pkey PRIMARY KEY (id), CONSTRAINT exch_fk FOREIGN KEY (exch) - REFERENCES public.exchanges (id) MATCH SIMPLE + REFERENCES exchanges (id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION DEFERRABLE INITIALLY DEFERRED, CONSTRAINT base_fk FOREIGN KEY (base) - REFERENCES public.currencies (id) MATCH SIMPLE + REFERENCES currencies (id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION DEFERRABLE INITIALLY DEFERRED, CONSTRAINT quote_fk FOREIGN KEY (quote) - REFERENCES public.currencies (id) MATCH SIMPLE + REFERENCES currencies (id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION DEFERRABLE INITIALLY DEFERRED -) -WITH ( - OIDS=FALSE ); -ALTER TABLE public.trades - OWNER TO jstrong; - CREATE INDEX trades_time_abcdefg - ON public.trades + ON trades USING btree ("time"); -CREATE INDEX trades_base_f6b2eeda - ON public.trades +CREATE INDEX trades_base_quote_f6b2eeda + ON trades USING btree - (base); - -CREATE INDEX trades_quote_0d5895fc - ON public.trades - USING btree - (quote); + (base, quote); CREATE INDEX trades_exchange_5d5c6971 - ON public.trades + ON trades USING btree (exch); --- CREATE INDEX trades_side_23985593 --- ON public.trades --- USING btree --- (side); - -- fill in exchanges/currencies -insert into public.exchanges (id, symbol) values(1, 'plnx'); -insert into public.exchanges (id, symbol) values(2, 'krkn'); -insert into public.exchanges (id, symbol) values(3, 'gdax'); -insert into public.exchanges (id, symbol) values(5, 'bits'); -insert into public.exchanges (id, symbol) values(6, 'bmex'); -insert into public.exchanges (id, symbol) values(7, 'btfx'); -insert into public.exchanges (id, symbol) values(8, 'bnce'); -insert into public.exchanges (id, symbol) values(9, 'okex'); -insert into public.currencies (id, symbol) values(1, 'btc'); -insert into public.currencies (id, symbol) values(2, 'eth'); -insert into public.currencies (id, symbol) values(3, 'xmr'); -insert into public.currencies (id, symbol) values(5, 'ltc'); -insert into public.currencies (id, symbol) values(15, 'etc'); -insert into public.currencies (id, symbol) values(4, 'usdt'); -insert into public.currencies (id, symbol) values(100, 'usd'); +INSERT INTO exchanges (id, symbol) VALUES (1, 'plnx'); +INSERT INTO exchanges (id, symbol) VALUES (2, 'krkn'); +INSERT INTO exchanges (id, symbol) VALUES (3, 'gdax'); +INSERT INTO exchanges (id, symbol) VALUES (4, 'exmo'); +INSERT INTO exchanges (id, symbol) VALUES (5, 'bits'); +INSERT INTO exchanges (id, symbol) VALUES (6, 'bmex'); +INSERT INTO exchanges (id, symbol) VALUES (7, 'btfx'); +INSERT INTO exchanges (id, symbol) VALUES (8, 'bnce'); +INSERT INTO exchanges (id, symbol) VALUES (9, 'okex'); +INSERT INTO exchanges (id, symbol) VALUES (10, 'drbt'); +INSERT INTO currencies (id, symbol) VALUES (1, 'btc'); +INSERT INTO currencies (id, symbol) VALUES (2, 'eth'); +INSERT INTO currencies (id, symbol) VALUES (3, 'xmr'); +INSERT INTO currencies (id, symbol) VALUES (4, 'usdt'); +INSERT INTO currencies (id, symbol) VALUES (5, 'ltc'); +INSERT INTO currencies (id, symbol) VALUES (6, 'dash'); +INSERT INTO currencies (id, symbol) VALUES (7, 'nvc'); +INSERT INTO currencies (id, symbol) VALUES (8, 'ppc'); +INSERT INTO currencies (id, symbol) VALUES (9, 'zec'); +INSERT INTO currencies (id, symbol) VALUES (10, 'xrp'); +INSERT INTO currencies (id, symbol) VALUES (11, 'gnt'); +INSERT INTO currencies (id, symbol) VALUES (12, 'steem'); +INSERT INTO currencies (id, symbol) VALUES (13, 'rep'); +INSERT INTO currencies (id, symbol) VALUES (14, 'gno'); +INSERT INTO currencies (id, symbol) VALUES (15, 'etc'); +INSERT INTO currencies (id, symbol) VALUES (16, 'icn'); +INSERT INTO currencies (id, symbol) VALUES (17, 'xlm'); +INSERT INTO currencies (id, symbol) VALUES (18, 'mln'); +INSERT INTO currencies (id, symbol) VALUES (19, 'bcn'); +INSERT INTO currencies (id, symbol) VALUES (20, 'bch'); +INSERT INTO currencies (id, symbol) VALUES (21, 'doge'); +INSERT INTO currencies (id, symbol) VALUES (22, 'eos'); +INSERT INTO currencies (id, symbol) VALUES (23, 'nxt'); +INSERT INTO currencies (id, symbol) VALUES (24, 'sc'); +INSERT INTO currencies (id, symbol) VALUES (25, 'zrx'); +INSERT INTO currencies (id, symbol) VALUES (26, 'bat'); +INSERT INTO currencies (id, symbol) VALUES (27, 'ada'); +INSERT INTO currencies (id, symbol) VALUES (28, 'usdc'); +INSERT INTO currencies (id, symbol) VALUES (29, 'dai'); +INSERT INTO currencies (id, symbol) VALUES (30, 'mkr'); +INSERT INTO currencies (id, symbol) VALUES (31, 'loom'); +INSERT INTO currencies (id, symbol) VALUES (32, 'cvc'); +INSERT INTO currencies (id, symbol) VALUES (33, 'mana'); +INSERT INTO currencies (id, symbol) VALUES (34, 'dnt'); +INSERT INTO currencies (id, symbol) VALUES (35, 'zil'); +INSERT INTO currencies (id, symbol) VALUES (36, 'link'); +INSERT INTO currencies (id, symbol) VALUES (37, 'algo'); +INSERT INTO currencies (id, symbol) VALUES (38, 'xtz'); +INSERT INTO currencies (id, symbol) VALUES (39, 'oxt'); +INSERT INTO currencies (id, symbol) VALUES (40, 'atom'); +INSERT INTO currencies (id, symbol) VALUES (100, 'usd'); +INSERT INTO currencies (id, symbol) VALUES (101, 'eur'); +INSERT INTO currencies (id, symbol) VALUES (102, 'rur'); +INSERT INTO currencies (id, symbol) VALUES (103, 'jpy'); +INSERT INTO currencies (id, symbol) VALUES (104, 'gbp'); +INSERT INTO currencies (id, symbol) VALUES (105, 'chf'); +INSERT INTO currencies (id, symbol) VALUES (106, 'cad'); +INSERT INTO currencies (id, symbol) VALUES (107, 'aud'); +INSERT INTO currencies (id, symbol) VALUES (108, 'zar'); +INSERT INTO currencies (id, symbol) VALUES (109, 'mxn'); diff --git a/src/munge.rs b/src/munge.rs index 3f3c34f..63c9e95 100644 --- a/src/munge.rs +++ b/src/munge.rs @@ -14,7 +14,7 @@ use structopt::StructOpt; use serde::{Serialize, Deserialize}; use slog::Drain; use chrono::{DateTime, Utc, NaiveDateTime}; -use markets::crypto::{Exchange, Ticker, Side}; +use markets::crypto::{Exchange, Ticker, Side, Currency}; macro_rules! fatal { ($fmt:expr, $($args:tt)*) => {{ eprintln!($fmt, $($args)*); @@ -203,19 +203,13 @@ fn run(start: Instant, logger: &slog::Logger) -> Result { println!("side: {:?} {}", Side::Ask, u8::from(Side::Ask)); println!(); - for exch in - &[e!(plnx), e!(krkn), e!(gdax), e!(bits), - e!(bmex), e!(btfx), e!(bnce), e!(okex), ] - { - println!("insert into exchanges (id, symbol) values({}, \"{}\");", u8::from(*exch), exch.as_str()); + for exch in Exchange::all() { + println!("INSERT INTO exchanges (id, symbol) VALUES ({}, '{}');", u8::from(exch), exch.as_str()); } - for currency in - &[c!(btc), c!(eth), c!(xmr), c!(ltc), c!(etc), c!(usdt), c!(usd)] - { - println!("insert into currencies (id, symbol) values({}, \"{}\");", u8::from(*currency), currency.as_str()); + for currency in Currency::all() { + println!("INSERT INTO currencies (id, symbol) VALUES ({}, '{}');", u8::from(currency), currency.as_str()); } - } Opt::Range { trades_csv, output_path, start, end } => {