/* cycle of BEST */ \set ECHO all set search_path to market; select count(*) from torder; count ------- 0 (1 row) /* order book empty */ /* one cycle with BEST orders, the cycle exists even if OMEGA < 1 */ select * from fsubmitbarter(2,'a',NULL,'q1',20,'q2',10,'1 hour'::interval); id | diag ----+------ 47 | 0 (1 row) select * from fproducemvt(); ord | ordp | qtt_requ | qtt_prov | qtt | qtt_reci | qtt_give | err | json | own | type | stackid ----------------------------+------------+----------+----------+-----+----------+----------+-----+------+-----+------+--------- (2,47,1,47,20,q1,10,q2,10) | (,,,,,,,,) | 20 | 10 | 10 | 0 | 0 | 0 | | a | 2 | 47 (1 row) /* form 0 fsubmitprequote(_own,_qua_requ,_qua_prov)*/ select * from fsubmitprequote('b','q2','q1'); id | diag ----+------ 48 | 0 (1 row) select json from fproducemvt(); json ---------------------------------------------------------------------------------------------- {"qtt_requ":0,"qtt_prov":0,"qtt":0,"qtt_reci":10,"qtt_give":20,"paths":[ + [{"type":2, "id":47, "oid":47, "own":1, "qtt_requ":20, "qtt_prov":10, "qtt":10, "flowr":10},+ {"type":78, "id":48, "oid":48, "own":2, "qtt_requ":10, "qtt_prov":20, "qtt":20, "flowr":20}]+ ]} (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 and qtto */ select * from fsubmitquote(2,'b','q2','q1'); id | diag ----+------ 49 | 0 (1 row) select json from fproducemvt(); json ----------------------------------------------------------------------------------------------- {"qtt_requ":10,"qtt_prov":20,"qtt":20,"qtt_reci":10,"qtt_give":20,"paths":[ + [{"type":2, "id":47, "oid":47, "own":1, "qtt_requ":20, "qtt_prov":10, "qtt":10, "flowr":10}, + {"type":142, "id":49, "oid":49, "own":2, "qtt_requ":10, "qtt_prov":20, "qtt":20, "flowr":20}]+ ]} (1 row) /* form 2 fsubmitquote(_type,_own,_qua_requ,_qtt_requ,_qua_prov,_qtt_prov) flow limited by ωu,ωo and qtto */ select * from fsubmitquote(2,'b','q2',20,'q1',10); id | diag ----+------ 50 | 0 (1 row) select json from fproducemvt(); json ----------------------------------------------------------------------------------------------- {"qtt_requ":20,"qtt_prov":10,"qtt":10,"qtt_reci":10,"qtt_give":10,"paths":[ + [{"type":2, "id":47, "oid":47, "own":1, "qtt_requ":20, "qtt_prov":10, "qtt":10, "flowr":10}, + {"type":134, "id":50, "oid":50, "own":2, "qtt_requ":20, "qtt_prov":10, "qtt":10, "flowr":10}]+ ]} (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(2,'d','q2',20,'q1',10,20); id | diag ----+------ 51 | 0 (1 row) select json from fproducemvt(); json ----------------------------------------------------------------------------------------------- {"qtt_requ":20,"qtt_prov":10,"qtt":20,"qtt_reci":10,"qtt_give":10,"paths":[ + [{"type":2, "id":47, "oid":47, "own":1, "qtt_requ":20, "qtt_prov":10, "qtt":10, "flowr":10}, + {"type":130, "id":51, "oid":51, "own":4, "qtt_requ":20, "qtt_prov":10, "qtt":20, "flowr":10}]+ ]} (1 row) /* barter */ select * from fsubmitbarter(2,'d',NULL,'q2',20,'q1',10,10,'1 hour'::interval); id | diag ----+------ 52 | 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 2; id | grp | xid | own_src | own_dst | qtt | nat ----+-----+-----+---------+---------+-----+----- 59 | 58 | 47 | a | d | 10 | q2 58 | 58 | 52 | d | a | 10 | q1 (2 rows) select count(*) from vorder; count ------- 0 (1 row) /* order book empty */