Viktor/sqlfunctions

This is a massive rewrite of a lot of stuff, but it will let us lock down the database a lot better.

I've tested everything affected afaik, but I could have missed something. We need to write real integration tests.
I think we need to return the bids and asks in a single `select` query or the order books could appear inconsistent. For example, if we retrieve the bids first and then a sell order for less than the highest bid is committed before we query the asks, we could see an ask lower than the highest bid as well as bids that were already matched by this ask. This does not affect our database but it would look wrong to users and possibly affect automated trading bots. I suggest we use a function like this to get the order books atomically:
```
CREATE AGGREGATE array_agg_mult (anyarray) (
    SFUNC     = array_cat
   ,STYPE     = anyarray
   ,INITCOND  = '{}'
);

create function 
  orders_depth(
    a_base varchar(4),
    a_counter varchar(4),
    out asks numeric(23,8)[],
    out bids numeric(23,8)[])
  as $$
    select (
      select array_agg_mult(array[array[price, amount]]) from open_asks(a_base, a_counter)
    ), (
      select array_agg_mult(array[array[price, amount]]) from open_bids(a_base, a_counter)
    );
$$ language sql stable cost 100;
```