Browse Source

postgres changes

tags/v0.2.0
Jonathan Strong 4 years ago
parent
commit
4ba8cd7161
3 changed files with 81 additions and 59 deletions
  1. +1
    -1
      Cargo.toml
  2. +75
    -47
      postgres-creat-trades-table.sql
  3. +5
    -11
      src/munge.rs

+ 1
- 1
Cargo.toml View File

@@ -25,7 +25,7 @@ csv = "1.1"
structopt = "0.3" structopt = "0.3"
serde = { version = "1", features = ["derive"] } serde = { version = "1", features = ["derive"] }
serde_json = "1" serde_json = "1"
markets = { version = "0.2.1", registry = "jstrong-dev" }
markets = { version = "0.3.0", registry = "jstrong-dev" }
slog = "2" slog = "2"
slog-async = "2" slog-async = "2"
slog-term = "2" slog-term = "2"


+ 75
- 47
postgres-creat-trades-table.sql View File

@@ -1,51 +1,28 @@
CREATE SEQUENCE public.trades_id_seq
CREATE SEQUENCE trades_id_seq
INCREMENT 1 INCREMENT 1
MINVALUE 1 MINVALUE 1
MAXVALUE 9223372036854775807 MAXVALUE 9223372036854775807
START 1 START 1
CACHE 1; CACHE 1;
ALTER TABLE public.trades_id_seq
OWNER TO jstrong;




CREATE TABLE public.exchanges
CREATE TABLE exchanges
( (


id smallint NOT NULL, id smallint NOT NULL,
symbol character varying(4) NOT NULL, symbol character varying(4) NOT NULL,


CONSTRAINT exchanges_pkey PRIMARY KEY (id) CONSTRAINT exchanges_pkey PRIMARY KEY (id)
);


) WITH ( OIDS=FALSE );

CREATE TABLE public.currencies
CREATE TABLE currencies
( (
id smallint NOT NULL, id smallint NOT NULL,
symbol character varying(6) NOT NULL, symbol character varying(6) NOT NULL,


CONSTRAINT currencies_pkey PRIMARY KEY (id) 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), id integer NOT NULL DEFAULT nextval('trades_id_seq'::regclass),
"time" timestamp with time zone NOT NULL, "time" timestamp with time zone NOT NULL,
@@ -56,66 +33,96 @@ CREATE TABLE public.trades
price double precision NOT NULL, price double precision NOT NULL,
side smallint NULL, -- side has no fk ... bid=1, ask=2 side smallint NULL, -- side has no fk ... bid=1, ask=2
server_time timestamp with time zone NULL, server_time timestamp with time zone NULL,

CONSTRAINT trades_pkey PRIMARY KEY (id), CONSTRAINT trades_pkey PRIMARY KEY (id),


CONSTRAINT exch_fk FOREIGN KEY (exch) 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, ON UPDATE NO ACTION ON DELETE NO ACTION DEFERRABLE INITIALLY DEFERRED,


CONSTRAINT base_fk FOREIGN KEY (base) 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, ON UPDATE NO ACTION ON DELETE NO ACTION DEFERRABLE INITIALLY DEFERRED,


CONSTRAINT quote_fk FOREIGN KEY (quote) 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 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 CREATE INDEX trades_time_abcdefg
ON public.trades
ON trades
USING btree USING btree
("time"); ("time");


CREATE INDEX trades_base_f6b2eeda
ON public.trades
CREATE INDEX trades_base_quote_f6b2eeda
ON trades
USING btree USING btree
(base);

CREATE INDEX trades_quote_0d5895fc
ON public.trades
USING btree
(quote);
(base, quote);


CREATE INDEX trades_exchange_5d5c6971 CREATE INDEX trades_exchange_5d5c6971
ON public.trades
ON trades
USING btree USING btree
(exch); (exch);



-- fill in exchanges/currencies -- 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');

+ 5
- 11
src/munge.rs View File

@@ -14,7 +14,7 @@ use structopt::StructOpt;
use serde::{Serialize, Deserialize}; use serde::{Serialize, Deserialize};
use slog::Drain; use slog::Drain;
use chrono::{DateTime, Utc, NaiveDateTime}; 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)*) => {{ macro_rules! fatal { ($fmt:expr, $($args:tt)*) => {{
eprintln!($fmt, $($args)*); eprintln!($fmt, $($args)*);
@@ -203,19 +203,13 @@ fn run(start: Instant, logger: &slog::Logger) -> Result<usize, String> {
println!("side: {:?} {}", Side::Ask, u8::from(Side::Ask)); println!("side: {:?} {}", Side::Ask, u8::from(Side::Ask));
println!(); 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 } => { Opt::Range { trades_csv, output_path, start, end } => {


Loading…
Cancel
Save