\set ECHO all -- repeate commands in results count ------- 0 (1 row) id | diag ----+------ 8 | 0 (1 row) ord | ordp | qtt_requ | qtt_prov | qtt | qtt_reci | qtt_give | err | json | own | type | stackid --------------------------+------------+----------+----------+-----+----------+----------+-----+------+-----+------+--------- (1,8,1,8,10,q1,10,q2,10) | (,,,,,,,,) | 10 | 10 | 10 | 0 | 0 | 0 | | a | 1 | 8 (1 row) id | diag ----+------ 9 | 0 (1 row) ord | ordp | qtt_requ | qtt_prov | qtt | qtt_reci | qtt_give | err | json | own | type | stackid --------------------------+------------+----------+----------+-----+----------+----------+-----+------+-----+------+--------- (1,9,2,9,10,q1,20,q2,20) | (,,,,,,,,) | 10 | 20 | 20 | 0 | 0 | 0 | | b | 1 | 9 (1 row) id | diag ----+------ 10 | 0 (1 row) ord | ordp | qtt_requ | qtt_prov | qtt | qtt_reci | qtt_give | err | json | own | type | stackid ----------------------------+------------+----------+----------+-----+----------+----------+-----+------+-----+------+--------- (1,10,3,10,10,q1,30,q2,30) | (,,,,,,,,) | 10 | 30 | 30 | 0 | 0 | 0 | | c | 1 | 10 (1 row) /* 3 competing orders */ select id,type,own,oid,qtt_requ,qua_requ,qtt_prov,qua_prov,qtt from vorder; id | type | own | oid | qtt_requ | qua_requ | qtt_prov | qua_prov | qtt ----+------+-----+-----+----------+----------+----------+----------+----- 8 | 1 | a | 8 | 10 | q1 | 10 | q2 | 10 9 | 1 | b | 9 | 10 | q1 | 20 | q2 | 20 10 | 1 | c | 10 | 10 | q1 | 30 | q2 | 30 (3 rows) /* form 0 fsubmitprequote(_own,_qua_requ,_qua_prov)*/ select * from fsubmitprequote('d','q2','q1'); id | diag ----+------ 11 | 0 (1 row) /* 3 potential cycles ordered by increasing prices 10/30, 10/20, 10/10*/ select json from fproducemvt(); json ----------------------------------------------------------------------------------------------- {"qtt_requ":0,"qtt_prov":0,"qtt":0,"qtt_reci":60,"qtt_give":30,"paths":[ + [{"type":1, "id":10, "oid":10, "own":3, "qtt_requ":10, "qtt_prov":30, "qtt":30, "flowr":30}, + {"type":78, "id":11, "oid":11, "own":4, "qtt_requ":30, "qtt_prov":10, "qtt":10, "flowr":10}],+ [{"type":1, "id":9, "oid":9, "own":2, "qtt_requ":10, "qtt_prov":20, "qtt":20, "flowr":20}, + {"type":78, "id":11, "oid":11, "own":4, "qtt_requ":20, "qtt_prov":10, "qtt":10, "flowr":10}],+ [{"type":1, "id":8, "oid":8, "own":1, "qtt_requ":10, "qtt_prov":10, "qtt":10, "flowr":10}, + {"type":78, "id":11, "oid":11, "own":4, "qtt_requ":10, "qtt_prov":10, "qtt":10, "flowr":10}] + ]} (1 row) /* ωu,qttu values defined by owner ωo,qtto defines by others */ /* form 1 fsubmitquote(_own,_qua_requ,_qua_prov) flow limited by best price 10/30 and qtto */ select * from fsubmitquote(1,'d','q2','q1'); id | diag ----+------ 12 | 0 (1 row) select json from fproducemvt(); json ----------------------------------------------------------------------------------------------- {"qtt_requ":30,"qtt_prov":10,"qtt":10,"qtt_reci":30,"qtt_give":10,"paths":[ + [{"type":1, "id":10, "oid":10, "own":3, "qtt_requ":10, "qtt_prov":30, "qtt":30, "flowr":30}, + {"type":141, "id":12, "oid":12, "own":4, "qtt_requ":30, "qtt_prov":10, "qtt":10, "flowr":10}]+ ]} (1 row) /* form 2 fsubmitquote(_type,_own,_qua_requ,_qtt_requ,_qua_prov,_qtt_prov) flow limited by ωu,ωo and qtto */ /* limited by ωu,ωo and qtto */ /* one cycle */ select * from fsubmitquote(1,'d','q2',30,'q1',10); id | diag ----+------ 13 | 0 (1 row) select json from fproducemvt(); json ----------------------------------------------------------------------------------------------- {"qtt_requ":30,"qtt_prov":10,"qtt":10,"qtt_reci":30,"qtt_give":10,"paths":[ + [{"type":1, "id":10, "oid":10, "own":3, "qtt_requ":10, "qtt_prov":30, "qtt":30, "flowr":30}, + {"type":133, "id":13, "oid":13, "own":4, "qtt_requ":30, "qtt_prov":10, "qtt":10, "flowr":10}]+ ]} (1 row) /* 3 cycles */ select * from fsubmitquote(1,'d','q2',10,'q1',10); id | diag ----+------ 14 | 0 (1 row) select json from fproducemvt(); json ------------------------------------------------------------------------------------------------ {"qtt_requ":10,"qtt_prov":10,"qtt":41,"qtt_reci":60,"qtt_give":41,"paths":[ + [{"type":1, "id":10, "oid":10, "own":3, "qtt_requ":10, "qtt_prov":30, "qtt":30, "flowr":30}, + {"type":133, "id":14, "oid":14, "own":4, "qtt_requ":10, "qtt_prov":10, "qtt":17, "flowr":17}],+ [{"type":1, "id":9, "oid":9, "own":2, "qtt_requ":10, "qtt_prov":20, "qtt":20, "flowr":20}, + {"type":133, "id":14, "oid":14, "own":4, "qtt_requ":10, "qtt_prov":10, "qtt":14, "flowr":14}],+ [{"type":1, "id":8, "oid":8, "own":1, "qtt_requ":10, "qtt_prov":10, "qtt":10, "flowr":10}, + {"type":133, "id":14, "oid":14, "own":4, "qtt_requ":10, "qtt_prov":10, "qtt":10, "flowr":10}] + ]} (1 row) /* only limited by ωo and qtto */ select * from fsubmitquote(1,'d','q2',5,'q1',10); id | diag ----+------ 15 | 0 (1 row) select json from fproducemvt(); json ----------------------------------------------------------------------------------------------- {"qtt_requ":5,"qtt_prov":10,"qtt":58,"qtt_reci":60,"qtt_give":58,"paths":[ + [{"type":1, "id":10, "oid":10, "own":3, "qtt_requ":10, "qtt_prov":30, "qtt":30, "flowr":30}, + {"type":133, "id":15, "oid":15, "own":4, "qtt_requ":5, "qtt_prov":10, "qtt":24, "flowr":24}],+ [{"type":1, "id":9, "oid":9, "own":2, "qtt_requ":10, "qtt_prov":20, "qtt":20, "flowr":20}, + {"type":133, "id":15, "oid":15, "own":4, "qtt_requ":5, "qtt_prov":10, "qtt":20, "flowr":20}],+ [{"type":1, "id":8, "oid":8, "own":1, "qtt_requ":10, "qtt_prov":10, "qtt":10, "flowr":10}, + {"type":133, "id":15, "oid":15, "own":4, "qtt_requ":5, "qtt_prov":10, "qtt":14, "flowr":14}] + ]} (1 row) /* form 3 fsubmitquote(_type,_own,_qua_requ,_qtt_requ,_qua_prov,_qtt_prov,qtt) flow limited by ωu,ωo and qttu,qtto */ select * from fsubmitquote(1,'d','q2',30,'q1',10,20); id | diag ----+------ 16 | 0 (1 row) select json from fproducemvt(); json ----------------------------------------------------------------------------------------------- {"qtt_requ":30,"qtt_prov":10,"qtt":20,"qtt_reci":30,"qtt_give":10,"paths":[ + [{"type":1, "id":10, "oid":10, "own":3, "qtt_requ":10, "qtt_prov":30, "qtt":30, "flowr":30}, + {"type":129, "id":16, "oid":16, "own":4, "qtt_requ":30, "qtt_prov":10, "qtt":20, "flowr":10}]+ ]} (1 row) /* limited by this ωu,qttu */ select * from fsubmitquote(1,'d','q2',30,'q1',10,5); id | diag ----+------ 17 | 0 (1 row) select json from fproducemvt(); json ---------------------------------------------------------------------------------------------- {"qtt_requ":30,"qtt_prov":10,"qtt":5,"qtt_reci":15,"qtt_give":5,"paths":[ + [{"type":1, "id":10, "oid":10, "own":3, "qtt_requ":10, "qtt_prov":30, "qtt":30, "flowr":15},+ {"type":129, "id":17, "oid":17, "own":4, "qtt_requ":30, "qtt_prov":10, "qtt":5, "flowr":5}] + ]} (1 row) /* limited by this ωo,qtto */ select * from fsubmitquote(1,'d','q2',10,'q1',10,100); id | diag ----+------ 18 | 0 (1 row) select json from fproducemvt(); json ------------------------------------------------------------------------------------------------- {"qtt_requ":10,"qtt_prov":10,"qtt":100,"qtt_reci":60,"qtt_give":41,"paths":[ + [{"type":1, "id":10, "oid":10, "own":3, "qtt_requ":10, "qtt_prov":30, "qtt":30, "flowr":30}, + {"type":129, "id":18, "oid":18, "own":4, "qtt_requ":10, "qtt_prov":10, "qtt":100, "flowr":17}],+ [{"type":1, "id":9, "oid":9, "own":2, "qtt_requ":10, "qtt_prov":20, "qtt":20, "flowr":20}, + {"type":129, "id":18, "oid":18, "own":4, "qtt_requ":10, "qtt_prov":10, "qtt":83, "flowr":14}], + [{"type":1, "id":8, "oid":8, "own":1, "qtt_requ":10, "qtt_prov":10, "qtt":10, "flowr":10}, + {"type":129, "id":18, "oid":18, "own":4, "qtt_requ":10, "qtt_prov":10, "qtt":69, "flowr":10}] + ]} (1 row) /* barter */ select * from fsubmitbarter(1,'d',NULL,'q2',10,'q1',10,100,'1 hour'::interval); id | diag ----+------ 19 | 0 (1 row) select json from fproducemvt(); json ------ (1 row) select id,grp,xid,own_src,own_dst,qtt,nat from tmvt order by id desc limit 6; id | grp | xid | own_src | own_dst | qtt | nat ----+-----+-----+---------+---------+-----+----- 22 | 21 | 8 | a | d | 10 | q2 21 | 21 | 19 | d | a | 10 | q1 20 | 19 | 9 | b | d | 20 | q2 19 | 19 | 19 | d | b | 14 | q1 18 | 17 | 10 | c | d | 30 | q2 17 | 17 | 19 | d | c | 17 | q1 (6 rows) select id,qtt from vorder; /* qtt=100-41 */ id | qtt ----+----- 19 | 59 (1 row) select * from frmbarter('d',19); id | diag ----+------ 20 | 0 (1 row) select json from fproducemvt(); json ------------------------------------------------------- {"info":"removeorder - the barter order is removed "} (1 row) select count(*) from vorder; count ------- 0 (1 row) /* order book empty */