/* same as testflow_3_1, but with an order BEST in the order book */ \set ECHO all set search_path to market; select count(*) from torder; count ------- 0 (1 row) /* order book empty */ /* one BEST and two LIMIT */ select * from fsubmitbarter(2,'a',NULL,'q1',10,'q2',10,'1 hour'::interval); id | diag ----+------ 21 | 0 (1 row) select * from fproducemvt(); ord | ordp | qtt_requ | qtt_prov | qtt | qtt_reci | qtt_give | err | json | own | type | stackid ----------------------------+------------+----------+----------+-----+----------+----------+-----+------+-----+------+--------- (2,21,1,21,10,q1,10,q2,10) | (,,,,,,,,) | 10 | 10 | 10 | 0 | 0 | 0 | | a | 2 | 21 (1 row) select * from fsubmitbarter(1,'b',NULL,'q1',10,'q2',20,'1 hour'::interval); id | diag ----+------ 22 | 0 (1 row) select * from fproducemvt(); ord | ordp | qtt_requ | qtt_prov | qtt | qtt_reci | qtt_give | err | json | own | type | stackid ----------------------------+------------+----------+----------+-----+----------+----------+-----+------+-----+------+--------- (1,22,2,22,10,q1,20,q2,20) | (,,,,,,,,) | 10 | 20 | 20 | 0 | 0 | 0 | | b | 1 | 22 (1 row) select * from fsubmitbarter(1,'c',NULL,'q1',10,'q2',30,'1 hour'::interval); id | diag ----+------ 23 | 0 (1 row) select * from fproducemvt(); ord | ordp | qtt_requ | qtt_prov | qtt | qtt_reci | qtt_give | err | json | own | type | stackid ----------------------------+------------+----------+----------+-----+----------+----------+-----+------+-----+------+--------- (1,23,3,23,10,q1,30,q2,30) | (,,,,,,,,) | 10 | 30 | 30 | 0 | 0 | 0 | | c | 1 | 23 (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 ----+------+-----+-----+----------+----------+----------+----------+----- 21 | 2 | a | 21 | 10 | q1 | 10 | q2 | 10 22 | 1 | b | 22 | 10 | q1 | 20 | q2 | 20 23 | 1 | c | 23 | 10 | q1 | 30 | q2 | 30 (3 rows) /* form 0 fsubmitprequote(_own,_qua_requ,_qua_prov)*/ select * from fsubmitprequote('d','q2','q1'); id | diag ----+------ 24 | 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":23, "oid":23, "own":3, "qtt_requ":10, "qtt_prov":30, "qtt":30, "flowr":30}, + {"type":78, "id":24, "oid":24, "own":4, "qtt_requ":30, "qtt_prov":10, "qtt":10, "flowr":10}],+ [{"type":1, "id":22, "oid":22, "own":2, "qtt_requ":10, "qtt_prov":20, "qtt":20, "flowr":20}, + {"type":78, "id":24, "oid":24, "own":4, "qtt_requ":20, "qtt_prov":10, "qtt":10, "flowr":10}],+ [{"type":2, "id":21, "oid":21, "own":1, "qtt_requ":10, "qtt_prov":10, "qtt":10, "flowr":10}, + {"type":78, "id":24, "oid":24, "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 ----+------ 25 | 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":23, "oid":23, "own":3, "qtt_requ":10, "qtt_prov":30, "qtt":30, "flowr":30}, + {"type":141, "id":25, "oid":25, "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 ----+------ 26 | 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":23, "oid":23, "own":3, "qtt_requ":10, "qtt_prov":30, "qtt":30, "flowr":30}, + {"type":133, "id":26, "oid":26, "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 ----+------ 27 | 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":23, "oid":23, "own":3, "qtt_requ":10, "qtt_prov":30, "qtt":30, "flowr":30}, + {"type":133, "id":27, "oid":27, "own":4, "qtt_requ":10, "qtt_prov":10, "qtt":17, "flowr":17}],+ [{"type":1, "id":22, "oid":22, "own":2, "qtt_requ":10, "qtt_prov":20, "qtt":20, "flowr":20}, + {"type":133, "id":27, "oid":27, "own":4, "qtt_requ":10, "qtt_prov":10, "qtt":14, "flowr":14}],+ [{"type":2, "id":21, "oid":21, "own":1, "qtt_requ":10, "qtt_prov":10, "qtt":10, "flowr":10}, + {"type":133, "id":27, "oid":27, "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 ----+------ 28 | 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":23, "oid":23, "own":3, "qtt_requ":10, "qtt_prov":30, "qtt":30, "flowr":30}, + {"type":133, "id":28, "oid":28, "own":4, "qtt_requ":5, "qtt_prov":10, "qtt":24, "flowr":24}],+ [{"type":1, "id":22, "oid":22, "own":2, "qtt_requ":10, "qtt_prov":20, "qtt":20, "flowr":20}, + {"type":133, "id":28, "oid":28, "own":4, "qtt_requ":5, "qtt_prov":10, "qtt":20, "flowr":20}],+ [{"type":2, "id":21, "oid":21, "own":1, "qtt_requ":10, "qtt_prov":10, "qtt":10, "flowr":10}, + {"type":133, "id":28, "oid":28, "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 ----+------ 29 | 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":23, "oid":23, "own":3, "qtt_requ":10, "qtt_prov":30, "qtt":30, "flowr":30}, + {"type":129, "id":29, "oid":29, "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 ----+------ 30 | 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":23, "oid":23, "own":3, "qtt_requ":10, "qtt_prov":30, "qtt":30, "flowr":15},+ {"type":129, "id":30, "oid":30, "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 ----+------ 31 | 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":23, "oid":23, "own":3, "qtt_requ":10, "qtt_prov":30, "qtt":30, "flowr":30}, + {"type":129, "id":31, "oid":31, "own":4, "qtt_requ":10, "qtt_prov":10, "qtt":100, "flowr":17}],+ [{"type":1, "id":22, "oid":22, "own":2, "qtt_requ":10, "qtt_prov":20, "qtt":20, "flowr":20}, + {"type":129, "id":31, "oid":31, "own":4, "qtt_requ":10, "qtt_prov":10, "qtt":83, "flowr":14}], + [{"type":2, "id":21, "oid":21, "own":1, "qtt_requ":10, "qtt_prov":10, "qtt":10, "flowr":10}, + {"type":129, "id":31, "oid":31, "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 ----+------ 32 | 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 ----+-----+-----+---------+---------+-----+----- 37 | 36 | 21 | a | d | 10 | q2 36 | 36 | 32 | d | a | 10 | q1 35 | 34 | 22 | b | d | 20 | q2 34 | 34 | 32 | d | b | 14 | q1 33 | 32 | 23 | c | d | 30 | q2 32 | 32 | 32 | d | c | 17 | q1 (6 rows) select id,qtt from vorder; /* qtt=100-41 */ id | qtt ----+----- 32 | 59 (1 row) select * from frmbarter('d',32); id | diag ----+------ 33 | 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 */