From 418aaf42026f20624b114b0e73948465a97c901f Mon Sep 17 00:00:00 2001 From: marcus Date: Sat, 16 Dec 2023 14:45:36 -0800 Subject: [PATCH] new sqlx? --- ...f3b00e2261f74a42c0ef9c2bd845e9fefc15f.json | 16 + ...82df9287f4a7f05da6edf7b63600a38a3ddb0.json | 46 + ...4253a04434425554a7e08252b48ba9f1054a9.json | 16 + ...116a855c2e8090aeef40ed17af107950adf40.json | 15 + ...64845b355dce81d1c6837d77c44f7fa1bbb81.json | 34 + ...16227481753d71d934fe35d26f65d73493015.json | 16 + ...5d029957c852e65a31c7ed23067f143e0085d.json | 15 + ...813f1b7d34f99985b3937e4077060e3c82e41.json | 28 + ...66734f596e747341513c090252fecc21ef27d.json | 18 + ...50fa2e582869bcfafb72285b0ff427ce9dd34.json | 15 + ...580e2184c19ed177c3d5f2e9c30baa3f222d4.json | 40 + ...f028ac3ca594ad1ff8f99b1801144aae86417.json | 40 + ...508b513e0ac300dd7b6457d2f111c59a35b64.json | 16 + ...24a1af01b7d6d991cacd0d46adf8ee0ba6845.json | 46 + ...6dd6edaa4aac1c46b5c9b2b64800a49895480.json | 28 + ...901da8bf354a7547b715eed0d4941e1a21874.json | 16 + ...a9fbb14c646f71408d7cd95b3822daa0a8ac3.json | 23 + ...2fe8c0bf3e5339b12420dbfac087b9a166a76.json | 23 + ...d218a1f81ea9aef7568b4eb2b14d857e667c7.json | 16 + ...50d87f33af14ae49a474047e20aa66550b626.json | 23 + ...3780addfba267652475017084b1a283e58576.json | 29 + ...5a9ba055aa8caff90cff417a2ec7bbce01a22.json | 15 + ...0f8591c319bcbb7131975b0d21940e8c8d32f.json | 17 + ...b115a3d851abfa4b18e1d6b2ebf5a828d34b0.json | 34 + ...723b86a904386d45381a167f73b17980ba19c.json | 15 + ...6b7060adcf8d5c94a4883fd6cecca33809ca1.json | 22 + ...83882068b2f15066bd4397524c25629186b1e.json | 29 + ...f69845519228e9a0e54efbde7d3383411ba25.json | 22 + ...866804ab99775b4424fd70dc61d26db2d7f9c.json | 40 + ...27285ce50359b79029b6e9cf2d54492efd05a.json | 44 + ...8bed9b5ba64d692e3d82764a4075140b54fed.json | 22 + ...a5e1e693845675253d88acf750247aad17dd4.json | 40 + ...4291b42d5e24224792000635bc05aca0d4994.json | 16 + ...d65d8031562d74b6639b23b56927b2a3365b2.json | 16 + ...1d7ad937eed0e95511035ca2e4adeaea80a8a.json | 16 + ...6311cb880ca17d1de59046bbda34b1e7873ba.json | 17 + lean/sqlx-data.json | 815 ------------------ lean/src/buy/cancel_buy.rs | 5 +- lean/src/buy/commit_buy.rs | 10 +- lean/src/buy/init_buy.rs | 14 +- lean/src/log.rs | 2 +- lean/src/main.rs | 19 +- lean/src/sell/cancel_sell.rs | 9 +- lean/src/sell/commit_sell.rs | 7 +- lean/src/sell/init_sell.rs | 14 +- lean/src/trigger/buy/cancel_set_buy.rs | 5 +- lean/src/trigger/buy/set_buy_amount.rs | 6 +- lean/src/trigger/sell/set_sell_amount.rs | 6 +- quote-server-adaptor/src/main.rs | 22 +- 49 files changed, 954 insertions(+), 864 deletions(-) create mode 100644 lean/.sqlx/query-0b5d046f13b15fb90bcdcf53ef2f3b00e2261f74a42c0ef9c2bd845e9fefc15f.json create mode 100644 lean/.sqlx/query-18f12ed04bbb17c9111c1dbe3a282df9287f4a7f05da6edf7b63600a38a3ddb0.json create mode 100644 lean/.sqlx/query-1f441590542da84b8d7f0936f0a4253a04434425554a7e08252b48ba9f1054a9.json create mode 100644 lean/.sqlx/query-3eb5f90d0397982e5bb58b7bb53116a855c2e8090aeef40ed17af107950adf40.json create mode 100644 lean/.sqlx/query-474ee94334afdb02642decd9e8964845b355dce81d1c6837d77c44f7fa1bbb81.json create mode 100644 lean/.sqlx/query-478d505a821d9719f2b06e7a17e16227481753d71d934fe35d26f65d73493015.json create mode 100644 lean/.sqlx/query-4e55ae2d91f13f6e2c10f36cd455d029957c852e65a31c7ed23067f143e0085d.json create mode 100644 lean/.sqlx/query-4f05eb8d55adc5ffb6f2c3bd698813f1b7d34f99985b3937e4077060e3c82e41.json create mode 100644 lean/.sqlx/query-592b2cf584e4e3433508fc4375666734f596e747341513c090252fecc21ef27d.json create mode 100644 lean/.sqlx/query-614119b1e86a7ed3a6eb4befbd250fa2e582869bcfafb72285b0ff427ce9dd34.json create mode 100644 lean/.sqlx/query-61773af25838b0d523415f08caf580e2184c19ed177c3d5f2e9c30baa3f222d4.json create mode 100644 lean/.sqlx/query-667ed4c9ceccf223358b6665d30f028ac3ca594ad1ff8f99b1801144aae86417.json create mode 100644 lean/.sqlx/query-67fad622f62c146d64639531cae508b513e0ac300dd7b6457d2f111c59a35b64.json create mode 100644 lean/.sqlx/query-6b623b19a091fefa1f5224e98d924a1af01b7d6d991cacd0d46adf8ee0ba6845.json create mode 100644 lean/.sqlx/query-708bc80d9b3ee8d7e660954e7cd6dd6edaa4aac1c46b5c9b2b64800a49895480.json create mode 100644 lean/.sqlx/query-70bc7b299211efca9ed60559752901da8bf354a7547b715eed0d4941e1a21874.json create mode 100644 lean/.sqlx/query-71c63ae06c7e2ac29c5fb821279a9fbb14c646f71408d7cd95b3822daa0a8ac3.json create mode 100644 lean/.sqlx/query-745eb81b99a74f49dcc4b587bd42fe8c0bf3e5339b12420dbfac087b9a166a76.json create mode 100644 lean/.sqlx/query-75266347bd72da8e5e44147bdd8d218a1f81ea9aef7568b4eb2b14d857e667c7.json create mode 100644 lean/.sqlx/query-798f395f93b28ee53bd4c42f6a050d87f33af14ae49a474047e20aa66550b626.json create mode 100644 lean/.sqlx/query-85021a9a4c3c6353de87fee695a3780addfba267652475017084b1a283e58576.json create mode 100644 lean/.sqlx/query-89a57d157606bce9674a48092115a9ba055aa8caff90cff417a2ec7bbce01a22.json create mode 100644 lean/.sqlx/query-9842e265cf3f4009847049f64e60f8591c319bcbb7131975b0d21940e8c8d32f.json create mode 100644 lean/.sqlx/query-99bd329ede7aa25bfae7b91c620b115a3d851abfa4b18e1d6b2ebf5a828d34b0.json create mode 100644 lean/.sqlx/query-a03d253639396d19444c53793cc723b86a904386d45381a167f73b17980ba19c.json create mode 100644 lean/.sqlx/query-b01118474a60d5212c0986dc18b6b7060adcf8d5c94a4883fd6cecca33809ca1.json create mode 100644 lean/.sqlx/query-b95f5efd8e3c302373ee2e1c63e83882068b2f15066bd4397524c25629186b1e.json create mode 100644 lean/.sqlx/query-c733e387ec2e631933472a750a1f69845519228e9a0e54efbde7d3383411ba25.json create mode 100644 lean/.sqlx/query-cb96b90995ac76ea0a68ff99c71866804ab99775b4424fd70dc61d26db2d7f9c.json create mode 100644 lean/.sqlx/query-cc09091adee059150ddc5dacc2727285ce50359b79029b6e9cf2d54492efd05a.json create mode 100644 lean/.sqlx/query-d04627255755f5151a83750b65c8bed9b5ba64d692e3d82764a4075140b54fed.json create mode 100644 lean/.sqlx/query-e01e7b653209f8b4c361c63105aa5e1e693845675253d88acf750247aad17dd4.json create mode 100644 lean/.sqlx/query-e060004a9682688fd2c9c362e7d4291b42d5e24224792000635bc05aca0d4994.json create mode 100644 lean/.sqlx/query-e442247ab078298dbf3843d6be2d65d8031562d74b6639b23b56927b2a3365b2.json create mode 100644 lean/.sqlx/query-edb02b47e2d4d4a7b5767900edb1d7ad937eed0e95511035ca2e4adeaea80a8a.json create mode 100644 lean/.sqlx/query-f45afc55b6686ff912cda716d606311cb880ca17d1de59046bbda34b1e7873ba.json delete mode 100644 lean/sqlx-data.json diff --git a/lean/.sqlx/query-0b5d046f13b15fb90bcdcf53ef2f3b00e2261f74a42c0ef9c2bd845e9fefc15f.json b/lean/.sqlx/query-0b5d046f13b15fb90bcdcf53ef2f3b00e2261f74a42c0ef9c2bd845e9fefc15f.json new file mode 100644 index 0000000..50d3cfc --- /dev/null +++ b/lean/.sqlx/query-0b5d046f13b15fb90bcdcf53ef2f3b00e2261f74a42c0ef9c2bd845e9fefc15f.json @@ -0,0 +1,16 @@ +{ + "db_name": "PostgreSQL", + "query": "\n UPDATE stock SET amount = amount - $1\n WHERE \n owner_id = $2 AND\n stock_symbol = $3 AND\n amount >= $1\n ", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Float8", + "Text", + "Text" + ] + }, + "nullable": [] + }, + "hash": "0b5d046f13b15fb90bcdcf53ef2f3b00e2261f74a42c0ef9c2bd845e9fefc15f" +} diff --git a/lean/.sqlx/query-18f12ed04bbb17c9111c1dbe3a282df9287f4a7f05da6edf7b63600a38a3ddb0.json b/lean/.sqlx/query-18f12ed04bbb17c9111c1dbe3a282df9287f4a7f05da6edf7b63600a38a3ddb0.json new file mode 100644 index 0000000..d904aa3 --- /dev/null +++ b/lean/.sqlx/query-18f12ed04bbb17c9111c1dbe3a282df9287f4a7f05da6edf7b63600a38a3ddb0.json @@ -0,0 +1,46 @@ +{ + "db_name": "PostgreSQL", + "query": "SELECT * FROM log_entry WHERE username = $1", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "timestamp", + "type_info": "Timestamp" + }, + { + "ordinal": 1, + "name": "server", + "type_info": "Text" + }, + { + "ordinal": 2, + "name": "transaction_num", + "type_info": "Int4" + }, + { + "ordinal": 3, + "name": "username", + "type_info": "Text" + }, + { + "ordinal": 4, + "name": "log", + "type_info": "Jsonb" + } + ], + "parameters": { + "Left": [ + "Text" + ] + }, + "nullable": [ + false, + false, + false, + false, + false + ] + }, + "hash": "18f12ed04bbb17c9111c1dbe3a282df9287f4a7f05da6edf7b63600a38a3ddb0" +} diff --git a/lean/.sqlx/query-1f441590542da84b8d7f0936f0a4253a04434425554a7e08252b48ba9f1054a9.json b/lean/.sqlx/query-1f441590542da84b8d7f0936f0a4253a04434425554a7e08252b48ba9f1054a9.json new file mode 100644 index 0000000..3e98310 --- /dev/null +++ b/lean/.sqlx/query-1f441590542da84b8d7f0936f0a4253a04434425554a7e08252b48ba9f1054a9.json @@ -0,0 +1,16 @@ +{ + "db_name": "PostgreSQL", + "query": "UPDATE stock SET amount = amount - $1 WHERE owner_id = $2 AND stock_symbol = $3 AND amount >= $1", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Float8", + "Text", + "Text" + ] + }, + "nullable": [] + }, + "hash": "1f441590542da84b8d7f0936f0a4253a04434425554a7e08252b48ba9f1054a9" +} diff --git a/lean/.sqlx/query-3eb5f90d0397982e5bb58b7bb53116a855c2e8090aeef40ed17af107950adf40.json b/lean/.sqlx/query-3eb5f90d0397982e5bb58b7bb53116a855c2e8090aeef40ed17af107950adf40.json new file mode 100644 index 0000000..cd50f70 --- /dev/null +++ b/lean/.sqlx/query-3eb5f90d0397982e5bb58b7bb53116a855c2e8090aeef40ed17af107950adf40.json @@ -0,0 +1,15 @@ +{ + "db_name": "PostgreSQL", + "query": "UPDATE trader SET balance = balance + $2 WHERE user_id = $1", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Text", + "Float8" + ] + }, + "nullable": [] + }, + "hash": "3eb5f90d0397982e5bb58b7bb53116a855c2e8090aeef40ed17af107950adf40" +} diff --git a/lean/.sqlx/query-474ee94334afdb02642decd9e8964845b355dce81d1c6837d77c44f7fa1bbb81.json b/lean/.sqlx/query-474ee94334afdb02642decd9e8964845b355dce81d1c6837d77c44f7fa1bbb81.json new file mode 100644 index 0000000..dd5ff84 --- /dev/null +++ b/lean/.sqlx/query-474ee94334afdb02642decd9e8964845b355dce81d1c6837d77c44f7fa1bbb81.json @@ -0,0 +1,34 @@ +{ + "db_name": "PostgreSQL", + "query": "DELETE FROM queued_sell WHERE user_id = $1 RETURNING amount_dollars, stock_symbol, quoted_price", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "amount_dollars", + "type_info": "Float8" + }, + { + "ordinal": 1, + "name": "stock_symbol", + "type_info": "Text" + }, + { + "ordinal": 2, + "name": "quoted_price", + "type_info": "Float8" + } + ], + "parameters": { + "Left": [ + "Text" + ] + }, + "nullable": [ + false, + false, + false + ] + }, + "hash": "474ee94334afdb02642decd9e8964845b355dce81d1c6837d77c44f7fa1bbb81" +} diff --git a/lean/.sqlx/query-478d505a821d9719f2b06e7a17e16227481753d71d934fe35d26f65d73493015.json b/lean/.sqlx/query-478d505a821d9719f2b06e7a17e16227481753d71d934fe35d26f65d73493015.json new file mode 100644 index 0000000..c1f3b1d --- /dev/null +++ b/lean/.sqlx/query-478d505a821d9719f2b06e7a17e16227481753d71d934fe35d26f65d73493015.json @@ -0,0 +1,16 @@ +{ + "db_name": "PostgreSQL", + "query": "\n INSERT INTO stock (owner_id, stock_symbol, amount)\n VALUES ($1, $2, $3)\n ON CONFLICT (owner_id, stock_symbol)\n DO UPDATE SET\n amount = stock.amount + $3\n ", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Text", + "Text", + "Float8" + ] + }, + "nullable": [] + }, + "hash": "478d505a821d9719f2b06e7a17e16227481753d71d934fe35d26f65d73493015" +} diff --git a/lean/.sqlx/query-4e55ae2d91f13f6e2c10f36cd455d029957c852e65a31c7ed23067f143e0085d.json b/lean/.sqlx/query-4e55ae2d91f13f6e2c10f36cd455d029957c852e65a31c7ed23067f143e0085d.json new file mode 100644 index 0000000..4b2328a --- /dev/null +++ b/lean/.sqlx/query-4e55ae2d91f13f6e2c10f36cd455d029957c852e65a31c7ed23067f143e0085d.json @@ -0,0 +1,15 @@ +{ + "db_name": "PostgreSQL", + "query": "UPDATE trader SET balance = balance - $1 WHERE user_id = $2 AND balance >= $1", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Float8", + "Text" + ] + }, + "nullable": [] + }, + "hash": "4e55ae2d91f13f6e2c10f36cd455d029957c852e65a31c7ed23067f143e0085d" +} diff --git a/lean/.sqlx/query-4f05eb8d55adc5ffb6f2c3bd698813f1b7d34f99985b3937e4077060e3c82e41.json b/lean/.sqlx/query-4f05eb8d55adc5ffb6f2c3bd698813f1b7d34f99985b3937e4077060e3c82e41.json new file mode 100644 index 0000000..6be1741 --- /dev/null +++ b/lean/.sqlx/query-4f05eb8d55adc5ffb6f2c3bd698813f1b7d34f99985b3937e4077060e3c82e41.json @@ -0,0 +1,28 @@ +{ + "db_name": "PostgreSQL", + "query": "SELECT stock_symbol as name, amount as price FROM stock WHERE owner_id = $1", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "name", + "type_info": "Text" + }, + { + "ordinal": 1, + "name": "price", + "type_info": "Float8" + } + ], + "parameters": { + "Left": [ + "Text" + ] + }, + "nullable": [ + false, + false + ] + }, + "hash": "4f05eb8d55adc5ffb6f2c3bd698813f1b7d34f99985b3937e4077060e3c82e41" +} diff --git a/lean/.sqlx/query-592b2cf584e4e3433508fc4375666734f596e747341513c090252fecc21ef27d.json b/lean/.sqlx/query-592b2cf584e4e3433508fc4375666734f596e747341513c090252fecc21ef27d.json new file mode 100644 index 0000000..bb30c7f --- /dev/null +++ b/lean/.sqlx/query-592b2cf584e4e3433508fc4375666734f596e747341513c090252fecc21ef27d.json @@ -0,0 +1,18 @@ +{ + "db_name": "PostgreSQL", + "query": "\n INSERT INTO log_entry (timestamp, server, transaction_num, username, log) \n SELECT * FROM UNNEST ($1::timestamp[],$2::text[],$3::int[],$4::text[],$5::jsonb[])\n ", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "TimestampArray", + "TextArray", + "Int4Array", + "TextArray", + "JsonbArray" + ] + }, + "nullable": [] + }, + "hash": "592b2cf584e4e3433508fc4375666734f596e747341513c090252fecc21ef27d" +} diff --git a/lean/.sqlx/query-614119b1e86a7ed3a6eb4befbd250fa2e582869bcfafb72285b0ff427ce9dd34.json b/lean/.sqlx/query-614119b1e86a7ed3a6eb4befbd250fa2e582869bcfafb72285b0ff427ce9dd34.json new file mode 100644 index 0000000..a842d58 --- /dev/null +++ b/lean/.sqlx/query-614119b1e86a7ed3a6eb4befbd250fa2e582869bcfafb72285b0ff427ce9dd34.json @@ -0,0 +1,15 @@ +{ + "db_name": "PostgreSQL", + "query": "INSERT INTO trader (user_id, balance) VALUES ($1, $2) ON CONFLICT (user_id) DO UPDATE SET balance = trader.balance + $2", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Text", + "Float8" + ] + }, + "nullable": [] + }, + "hash": "614119b1e86a7ed3a6eb4befbd250fa2e582869bcfafb72285b0ff427ce9dd34" +} diff --git a/lean/.sqlx/query-61773af25838b0d523415f08caf580e2184c19ed177c3d5f2e9c30baa3f222d4.json b/lean/.sqlx/query-61773af25838b0d523415f08caf580e2184c19ed177c3d5f2e9c30baa3f222d4.json new file mode 100644 index 0000000..9f1b95c --- /dev/null +++ b/lean/.sqlx/query-61773af25838b0d523415f08caf580e2184c19ed177c3d5f2e9c30baa3f222d4.json @@ -0,0 +1,40 @@ +{ + "db_name": "PostgreSQL", + "query": "\n SELECT\n owner_id as username,\n stock_symbol as stock,\n amount_stock as shares_to_sell,\n trigger_price as \"trigger_amount!\"\n FROM sell_trigger\n WHERE owner_id = $1 AND trigger_price IS NOT NULL\n ", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "username", + "type_info": "Text" + }, + { + "ordinal": 1, + "name": "stock", + "type_info": "Text" + }, + { + "ordinal": 2, + "name": "shares_to_sell", + "type_info": "Float8" + }, + { + "ordinal": 3, + "name": "trigger_amount!", + "type_info": "Float8" + } + ], + "parameters": { + "Left": [ + "Text" + ] + }, + "nullable": [ + false, + false, + false, + true + ] + }, + "hash": "61773af25838b0d523415f08caf580e2184c19ed177c3d5f2e9c30baa3f222d4" +} diff --git a/lean/.sqlx/query-667ed4c9ceccf223358b6665d30f028ac3ca594ad1ff8f99b1801144aae86417.json b/lean/.sqlx/query-667ed4c9ceccf223358b6665d30f028ac3ca594ad1ff8f99b1801144aae86417.json new file mode 100644 index 0000000..1652c9a --- /dev/null +++ b/lean/.sqlx/query-667ed4c9ceccf223358b6665d30f028ac3ca594ad1ff8f99b1801144aae86417.json @@ -0,0 +1,40 @@ +{ + "db_name": "PostgreSQL", + "query": "DELETE FROM queued_sell WHERE user_id = $1 RETURNING amount_dollars, time_created, quoted_price, stock_symbol", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "amount_dollars", + "type_info": "Float8" + }, + { + "ordinal": 1, + "name": "time_created", + "type_info": "Timestamp" + }, + { + "ordinal": 2, + "name": "quoted_price", + "type_info": "Float8" + }, + { + "ordinal": 3, + "name": "stock_symbol", + "type_info": "Text" + } + ], + "parameters": { + "Left": [ + "Text" + ] + }, + "nullable": [ + false, + false, + false, + false + ] + }, + "hash": "667ed4c9ceccf223358b6665d30f028ac3ca594ad1ff8f99b1801144aae86417" +} diff --git a/lean/.sqlx/query-67fad622f62c146d64639531cae508b513e0ac300dd7b6457d2f111c59a35b64.json b/lean/.sqlx/query-67fad622f62c146d64639531cae508b513e0ac300dd7b6457d2f111c59a35b64.json new file mode 100644 index 0000000..07321cd --- /dev/null +++ b/lean/.sqlx/query-67fad622f62c146d64639531cae508b513e0ac300dd7b6457d2f111c59a35b64.json @@ -0,0 +1,16 @@ +{ + "db_name": "PostgreSQL", + "query": "INSERT INTO stock (owner_id, stock_symbol, amount) VALUES ($1, $2, $3) ON CONFLICT (owner_id, stock_symbol) DO UPDATE SET amount = stock.amount + $3", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Text", + "Text", + "Float8" + ] + }, + "nullable": [] + }, + "hash": "67fad622f62c146d64639531cae508b513e0ac300dd7b6457d2f111c59a35b64" +} diff --git a/lean/.sqlx/query-6b623b19a091fefa1f5224e98d924a1af01b7d6d991cacd0d46adf8ee0ba6845.json b/lean/.sqlx/query-6b623b19a091fefa1f5224e98d924a1af01b7d6d991cacd0d46adf8ee0ba6845.json new file mode 100644 index 0000000..18e4603 --- /dev/null +++ b/lean/.sqlx/query-6b623b19a091fefa1f5224e98d924a1af01b7d6d991cacd0d46adf8ee0ba6845.json @@ -0,0 +1,46 @@ +{ + "db_name": "PostgreSQL", + "query": "SELECT timestamp, server, transaction_num, username, log FROM log_entry WHERE username = $1", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "timestamp", + "type_info": "Timestamp" + }, + { + "ordinal": 1, + "name": "server", + "type_info": "Text" + }, + { + "ordinal": 2, + "name": "transaction_num", + "type_info": "Int4" + }, + { + "ordinal": 3, + "name": "username", + "type_info": "Text" + }, + { + "ordinal": 4, + "name": "log", + "type_info": "Jsonb" + } + ], + "parameters": { + "Left": [ + "Text" + ] + }, + "nullable": [ + false, + false, + false, + false, + false + ] + }, + "hash": "6b623b19a091fefa1f5224e98d924a1af01b7d6d991cacd0d46adf8ee0ba6845" +} diff --git a/lean/.sqlx/query-708bc80d9b3ee8d7e660954e7cd6dd6edaa4aac1c46b5c9b2b64800a49895480.json b/lean/.sqlx/query-708bc80d9b3ee8d7e660954e7cd6dd6edaa4aac1c46b5c9b2b64800a49895480.json new file mode 100644 index 0000000..a47bacd --- /dev/null +++ b/lean/.sqlx/query-708bc80d9b3ee8d7e660954e7cd6dd6edaa4aac1c46b5c9b2b64800a49895480.json @@ -0,0 +1,28 @@ +{ + "db_name": "PostgreSQL", + "query": "DELETE FROM queued_buy WHERE user_id = $1 RETURNING amount_dollars, time_created", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "amount_dollars", + "type_info": "Float8" + }, + { + "ordinal": 1, + "name": "time_created", + "type_info": "Timestamp" + } + ], + "parameters": { + "Left": [ + "Text" + ] + }, + "nullable": [ + false, + false + ] + }, + "hash": "708bc80d9b3ee8d7e660954e7cd6dd6edaa4aac1c46b5c9b2b64800a49895480" +} diff --git a/lean/.sqlx/query-70bc7b299211efca9ed60559752901da8bf354a7547b715eed0d4941e1a21874.json b/lean/.sqlx/query-70bc7b299211efca9ed60559752901da8bf354a7547b715eed0d4941e1a21874.json new file mode 100644 index 0000000..8914ebd --- /dev/null +++ b/lean/.sqlx/query-70bc7b299211efca9ed60559752901da8bf354a7547b715eed0d4941e1a21874.json @@ -0,0 +1,16 @@ +{ + "db_name": "PostgreSQL", + "query": "UPDATE sell_trigger SET trigger_price = $1 WHERE owner_id = $2 AND stock_symbol = $3", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Float8", + "Text", + "Text" + ] + }, + "nullable": [] + }, + "hash": "70bc7b299211efca9ed60559752901da8bf354a7547b715eed0d4941e1a21874" +} diff --git a/lean/.sqlx/query-71c63ae06c7e2ac29c5fb821279a9fbb14c646f71408d7cd95b3822daa0a8ac3.json b/lean/.sqlx/query-71c63ae06c7e2ac29c5fb821279a9fbb14c646f71408d7cd95b3822daa0a8ac3.json new file mode 100644 index 0000000..b655da5 --- /dev/null +++ b/lean/.sqlx/query-71c63ae06c7e2ac29c5fb821279a9fbb14c646f71408d7cd95b3822daa0a8ac3.json @@ -0,0 +1,23 @@ +{ + "db_name": "PostgreSQL", + "query": "DELETE FROM sell_trigger WHERE owner_id = $1 AND stock_symbol = $2 RETURNING amount_stock", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "amount_stock", + "type_info": "Float8" + } + ], + "parameters": { + "Left": [ + "Text", + "Text" + ] + }, + "nullable": [ + false + ] + }, + "hash": "71c63ae06c7e2ac29c5fb821279a9fbb14c646f71408d7cd95b3822daa0a8ac3" +} diff --git a/lean/.sqlx/query-745eb81b99a74f49dcc4b587bd42fe8c0bf3e5339b12420dbfac087b9a166a76.json b/lean/.sqlx/query-745eb81b99a74f49dcc4b587bd42fe8c0bf3e5339b12420dbfac087b9a166a76.json new file mode 100644 index 0000000..2549cf0 --- /dev/null +++ b/lean/.sqlx/query-745eb81b99a74f49dcc4b587bd42fe8c0bf3e5339b12420dbfac087b9a166a76.json @@ -0,0 +1,23 @@ +{ + "db_name": "PostgreSQL", + "query": "DELETE FROM buy_trigger WHERE owner_id = $1 AND stock_symbol = $2 RETURNING amount_dollars", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "amount_dollars", + "type_info": "Float8" + } + ], + "parameters": { + "Left": [ + "Text", + "Text" + ] + }, + "nullable": [ + false + ] + }, + "hash": "745eb81b99a74f49dcc4b587bd42fe8c0bf3e5339b12420dbfac087b9a166a76" +} diff --git a/lean/.sqlx/query-75266347bd72da8e5e44147bdd8d218a1f81ea9aef7568b4eb2b14d857e667c7.json b/lean/.sqlx/query-75266347bd72da8e5e44147bdd8d218a1f81ea9aef7568b4eb2b14d857e667c7.json new file mode 100644 index 0000000..1d00dc9 --- /dev/null +++ b/lean/.sqlx/query-75266347bd72da8e5e44147bdd8d218a1f81ea9aef7568b4eb2b14d857e667c7.json @@ -0,0 +1,16 @@ +{ + "db_name": "PostgreSQL", + "query": "INSERT INTO buy_trigger (owner_id, stock_symbol, amount_dollars) VALUES ($1, $2, $3)", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Text", + "Text", + "Float8" + ] + }, + "nullable": [] + }, + "hash": "75266347bd72da8e5e44147bdd8d218a1f81ea9aef7568b4eb2b14d857e667c7" +} diff --git a/lean/.sqlx/query-798f395f93b28ee53bd4c42f6a050d87f33af14ae49a474047e20aa66550b626.json b/lean/.sqlx/query-798f395f93b28ee53bd4c42f6a050d87f33af14ae49a474047e20aa66550b626.json new file mode 100644 index 0000000..64c1fb7 --- /dev/null +++ b/lean/.sqlx/query-798f395f93b28ee53bd4c42f6a050d87f33af14ae49a474047e20aa66550b626.json @@ -0,0 +1,23 @@ +{ + "db_name": "PostgreSQL", + "query": "UPDATE trader SET balance = balance - $1 WHERE user_id = $2 AND balance >= $1 RETURNING balance", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "balance", + "type_info": "Float8" + } + ], + "parameters": { + "Left": [ + "Float8", + "Text" + ] + }, + "nullable": [ + false + ] + }, + "hash": "798f395f93b28ee53bd4c42f6a050d87f33af14ae49a474047e20aa66550b626" +} diff --git a/lean/.sqlx/query-85021a9a4c3c6353de87fee695a3780addfba267652475017084b1a283e58576.json b/lean/.sqlx/query-85021a9a4c3c6353de87fee695a3780addfba267652475017084b1a283e58576.json new file mode 100644 index 0000000..fb9f660 --- /dev/null +++ b/lean/.sqlx/query-85021a9a4c3c6353de87fee695a3780addfba267652475017084b1a283e58576.json @@ -0,0 +1,29 @@ +{ + "db_name": "PostgreSQL", + "query": "\n DELETE FROM buy_trigger\n WHERE trigger_price >= $1 AND stock_symbol = $2 RETURNING owner_id, amount_dollars\n ", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "owner_id", + "type_info": "Text" + }, + { + "ordinal": 1, + "name": "amount_dollars", + "type_info": "Float8" + } + ], + "parameters": { + "Left": [ + "Float8", + "Text" + ] + }, + "nullable": [ + false, + false + ] + }, + "hash": "85021a9a4c3c6353de87fee695a3780addfba267652475017084b1a283e58576" +} diff --git a/lean/.sqlx/query-89a57d157606bce9674a48092115a9ba055aa8caff90cff417a2ec7bbce01a22.json b/lean/.sqlx/query-89a57d157606bce9674a48092115a9ba055aa8caff90cff417a2ec7bbce01a22.json new file mode 100644 index 0000000..b940b58 --- /dev/null +++ b/lean/.sqlx/query-89a57d157606bce9674a48092115a9ba055aa8caff90cff417a2ec7bbce01a22.json @@ -0,0 +1,15 @@ +{ + "db_name": "PostgreSQL", + "query": "\n UPDATE trader SET balance = balance + $1 WHERE user_id = $2;\n ", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Float8", + "Text" + ] + }, + "nullable": [] + }, + "hash": "89a57d157606bce9674a48092115a9ba055aa8caff90cff417a2ec7bbce01a22" +} diff --git a/lean/.sqlx/query-9842e265cf3f4009847049f64e60f8591c319bcbb7131975b0d21940e8c8d32f.json b/lean/.sqlx/query-9842e265cf3f4009847049f64e60f8591c319bcbb7131975b0d21940e8c8d32f.json new file mode 100644 index 0000000..617acc9 --- /dev/null +++ b/lean/.sqlx/query-9842e265cf3f4009847049f64e60f8591c319bcbb7131975b0d21940e8c8d32f.json @@ -0,0 +1,17 @@ +{ + "db_name": "PostgreSQL", + "query": "\n INSERT INTO queued_sell (user_id, stock_symbol, quoted_price, amount_dollars)\n VALUES ($1, $2, $3, $4)\n ON CONFLICT (user_id)\n DO UPDATE SET\n stock_symbol = $2,\n quoted_price = $3,\n amount_dollars = $4,\n time_created = NOW()\n ", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Text", + "Text", + "Float8", + "Float8" + ] + }, + "nullable": [] + }, + "hash": "9842e265cf3f4009847049f64e60f8591c319bcbb7131975b0d21940e8c8d32f" +} diff --git a/lean/.sqlx/query-99bd329ede7aa25bfae7b91c620b115a3d851abfa4b18e1d6b2ebf5a828d34b0.json b/lean/.sqlx/query-99bd329ede7aa25bfae7b91c620b115a3d851abfa4b18e1d6b2ebf5a828d34b0.json new file mode 100644 index 0000000..feedcde --- /dev/null +++ b/lean/.sqlx/query-99bd329ede7aa25bfae7b91c620b115a3d851abfa4b18e1d6b2ebf5a828d34b0.json @@ -0,0 +1,34 @@ +{ + "db_name": "PostgreSQL", + "query": "DELETE FROM queued_sell WHERE user_id = $1 returning quoted_price, amount_dollars, stock_symbol", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "quoted_price", + "type_info": "Float8" + }, + { + "ordinal": 1, + "name": "amount_dollars", + "type_info": "Float8" + }, + { + "ordinal": 2, + "name": "stock_symbol", + "type_info": "Text" + } + ], + "parameters": { + "Left": [ + "Text" + ] + }, + "nullable": [ + false, + false, + false + ] + }, + "hash": "99bd329ede7aa25bfae7b91c620b115a3d851abfa4b18e1d6b2ebf5a828d34b0" +} diff --git a/lean/.sqlx/query-a03d253639396d19444c53793cc723b86a904386d45381a167f73b17980ba19c.json b/lean/.sqlx/query-a03d253639396d19444c53793cc723b86a904386d45381a167f73b17980ba19c.json new file mode 100644 index 0000000..88a5822 --- /dev/null +++ b/lean/.sqlx/query-a03d253639396d19444c53793cc723b86a904386d45381a167f73b17980ba19c.json @@ -0,0 +1,15 @@ +{ + "db_name": "PostgreSQL", + "query": "UPDATE trader SET balance = balance + $1 WHERE user_id = $2", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Float8", + "Text" + ] + }, + "nullable": [] + }, + "hash": "a03d253639396d19444c53793cc723b86a904386d45381a167f73b17980ba19c" +} diff --git a/lean/.sqlx/query-b01118474a60d5212c0986dc18b6b7060adcf8d5c94a4883fd6cecca33809ca1.json b/lean/.sqlx/query-b01118474a60d5212c0986dc18b6b7060adcf8d5c94a4883fd6cecca33809ca1.json new file mode 100644 index 0000000..7b3c900 --- /dev/null +++ b/lean/.sqlx/query-b01118474a60d5212c0986dc18b6b7060adcf8d5c94a4883fd6cecca33809ca1.json @@ -0,0 +1,22 @@ +{ + "db_name": "PostgreSQL", + "query": "DELETE FROM queued_buy WHERE user_id = $1 RETURNING amount_dollars", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "amount_dollars", + "type_info": "Float8" + } + ], + "parameters": { + "Left": [ + "Text" + ] + }, + "nullable": [ + false + ] + }, + "hash": "b01118474a60d5212c0986dc18b6b7060adcf8d5c94a4883fd6cecca33809ca1" +} diff --git a/lean/.sqlx/query-b95f5efd8e3c302373ee2e1c63e83882068b2f15066bd4397524c25629186b1e.json b/lean/.sqlx/query-b95f5efd8e3c302373ee2e1c63e83882068b2f15066bd4397524c25629186b1e.json new file mode 100644 index 0000000..c5ba5c0 --- /dev/null +++ b/lean/.sqlx/query-b95f5efd8e3c302373ee2e1c63e83882068b2f15066bd4397524c25629186b1e.json @@ -0,0 +1,29 @@ +{ + "db_name": "PostgreSQL", + "query": "DELETE FROM sell_trigger WHERE trigger_price <= $1 AND stock_symbol = $2 RETURNING owner_id, amount_stock", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "owner_id", + "type_info": "Text" + }, + { + "ordinal": 1, + "name": "amount_stock", + "type_info": "Float8" + } + ], + "parameters": { + "Left": [ + "Float8", + "Text" + ] + }, + "nullable": [ + false, + false + ] + }, + "hash": "b95f5efd8e3c302373ee2e1c63e83882068b2f15066bd4397524c25629186b1e" +} diff --git a/lean/.sqlx/query-c733e387ec2e631933472a750a1f69845519228e9a0e54efbde7d3383411ba25.json b/lean/.sqlx/query-c733e387ec2e631933472a750a1f69845519228e9a0e54efbde7d3383411ba25.json new file mode 100644 index 0000000..6358166 --- /dev/null +++ b/lean/.sqlx/query-c733e387ec2e631933472a750a1f69845519228e9a0e54efbde7d3383411ba25.json @@ -0,0 +1,22 @@ +{ + "db_name": "PostgreSQL", + "query": "SELECT user_id FROM trader WHERE user_id = $1", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "user_id", + "type_info": "Text" + } + ], + "parameters": { + "Left": [ + "Text" + ] + }, + "nullable": [ + false + ] + }, + "hash": "c733e387ec2e631933472a750a1f69845519228e9a0e54efbde7d3383411ba25" +} diff --git a/lean/.sqlx/query-cb96b90995ac76ea0a68ff99c71866804ab99775b4424fd70dc61d26db2d7f9c.json b/lean/.sqlx/query-cb96b90995ac76ea0a68ff99c71866804ab99775b4424fd70dc61d26db2d7f9c.json new file mode 100644 index 0000000..5468c8e --- /dev/null +++ b/lean/.sqlx/query-cb96b90995ac76ea0a68ff99c71866804ab99775b4424fd70dc61d26db2d7f9c.json @@ -0,0 +1,40 @@ +{ + "db_name": "PostgreSQL", + "query": "DELETE FROM queued_buy WHERE user_id = $1 RETURNING stock_symbol, quoted_price, amount_dollars, time_created", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "stock_symbol", + "type_info": "Text" + }, + { + "ordinal": 1, + "name": "quoted_price", + "type_info": "Float8" + }, + { + "ordinal": 2, + "name": "amount_dollars", + "type_info": "Float8" + }, + { + "ordinal": 3, + "name": "time_created", + "type_info": "Timestamp" + } + ], + "parameters": { + "Left": [ + "Text" + ] + }, + "nullable": [ + false, + false, + false, + false + ] + }, + "hash": "cb96b90995ac76ea0a68ff99c71866804ab99775b4424fd70dc61d26db2d7f9c" +} diff --git a/lean/.sqlx/query-cc09091adee059150ddc5dacc2727285ce50359b79029b6e9cf2d54492efd05a.json b/lean/.sqlx/query-cc09091adee059150ddc5dacc2727285ce50359b79029b6e9cf2d54492efd05a.json new file mode 100644 index 0000000..ad5f067 --- /dev/null +++ b/lean/.sqlx/query-cc09091adee059150ddc5dacc2727285ce50359b79029b6e9cf2d54492efd05a.json @@ -0,0 +1,44 @@ +{ + "db_name": "PostgreSQL", + "query": "SELECT * FROM log_entry ORDER BY timestamp ASC", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "timestamp", + "type_info": "Timestamp" + }, + { + "ordinal": 1, + "name": "server", + "type_info": "Text" + }, + { + "ordinal": 2, + "name": "transaction_num", + "type_info": "Int4" + }, + { + "ordinal": 3, + "name": "username", + "type_info": "Text" + }, + { + "ordinal": 4, + "name": "log", + "type_info": "Jsonb" + } + ], + "parameters": { + "Left": [] + }, + "nullable": [ + false, + false, + false, + false, + false + ] + }, + "hash": "cc09091adee059150ddc5dacc2727285ce50359b79029b6e9cf2d54492efd05a" +} diff --git a/lean/.sqlx/query-d04627255755f5151a83750b65c8bed9b5ba64d692e3d82764a4075140b54fed.json b/lean/.sqlx/query-d04627255755f5151a83750b65c8bed9b5ba64d692e3d82764a4075140b54fed.json new file mode 100644 index 0000000..76cea23 --- /dev/null +++ b/lean/.sqlx/query-d04627255755f5151a83750b65c8bed9b5ba64d692e3d82764a4075140b54fed.json @@ -0,0 +1,22 @@ +{ + "db_name": "PostgreSQL", + "query": "SELECT balance FROM trader WHERE user_id = $1", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "balance", + "type_info": "Float8" + } + ], + "parameters": { + "Left": [ + "Text" + ] + }, + "nullable": [ + false + ] + }, + "hash": "d04627255755f5151a83750b65c8bed9b5ba64d692e3d82764a4075140b54fed" +} diff --git a/lean/.sqlx/query-e01e7b653209f8b4c361c63105aa5e1e693845675253d88acf750247aad17dd4.json b/lean/.sqlx/query-e01e7b653209f8b4c361c63105aa5e1e693845675253d88acf750247aad17dd4.json new file mode 100644 index 0000000..e07ef09 --- /dev/null +++ b/lean/.sqlx/query-e01e7b653209f8b4c361c63105aa5e1e693845675253d88acf750247aad17dd4.json @@ -0,0 +1,40 @@ +{ + "db_name": "PostgreSQL", + "query": "\n SELECT\n owner_id as username,\n stock_symbol as stock,\n amount_dollars as buy_amount,\n trigger_price as \"trigger_amount!\"\n FROM buy_trigger\n WHERE owner_id = $1 AND trigger_price IS NOT NULL\n ", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "username", + "type_info": "Text" + }, + { + "ordinal": 1, + "name": "stock", + "type_info": "Text" + }, + { + "ordinal": 2, + "name": "buy_amount", + "type_info": "Float8" + }, + { + "ordinal": 3, + "name": "trigger_amount!", + "type_info": "Float8" + } + ], + "parameters": { + "Left": [ + "Text" + ] + }, + "nullable": [ + false, + false, + false, + true + ] + }, + "hash": "e01e7b653209f8b4c361c63105aa5e1e693845675253d88acf750247aad17dd4" +} diff --git a/lean/.sqlx/query-e060004a9682688fd2c9c362e7d4291b42d5e24224792000635bc05aca0d4994.json b/lean/.sqlx/query-e060004a9682688fd2c9c362e7d4291b42d5e24224792000635bc05aca0d4994.json new file mode 100644 index 0000000..efedcea --- /dev/null +++ b/lean/.sqlx/query-e060004a9682688fd2c9c362e7d4291b42d5e24224792000635bc05aca0d4994.json @@ -0,0 +1,16 @@ +{ + "db_name": "PostgreSQL", + "query": "UPDATE stock SET amount = amount + $1 WHERE owner_id = $2 AND stock_symbol = $3", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Float8", + "Text", + "Text" + ] + }, + "nullable": [] + }, + "hash": "e060004a9682688fd2c9c362e7d4291b42d5e24224792000635bc05aca0d4994" +} diff --git a/lean/.sqlx/query-e442247ab078298dbf3843d6be2d65d8031562d74b6639b23b56927b2a3365b2.json b/lean/.sqlx/query-e442247ab078298dbf3843d6be2d65d8031562d74b6639b23b56927b2a3365b2.json new file mode 100644 index 0000000..d83f75e --- /dev/null +++ b/lean/.sqlx/query-e442247ab078298dbf3843d6be2d65d8031562d74b6639b23b56927b2a3365b2.json @@ -0,0 +1,16 @@ +{ + "db_name": "PostgreSQL", + "query": "INSERT INTO sell_trigger (owner_id, stock_symbol, amount_stock) VALUES ($1, $2, $3)", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Text", + "Text", + "Float8" + ] + }, + "nullable": [] + }, + "hash": "e442247ab078298dbf3843d6be2d65d8031562d74b6639b23b56927b2a3365b2" +} diff --git a/lean/.sqlx/query-edb02b47e2d4d4a7b5767900edb1d7ad937eed0e95511035ca2e4adeaea80a8a.json b/lean/.sqlx/query-edb02b47e2d4d4a7b5767900edb1d7ad937eed0e95511035ca2e4adeaea80a8a.json new file mode 100644 index 0000000..15fa815 --- /dev/null +++ b/lean/.sqlx/query-edb02b47e2d4d4a7b5767900edb1d7ad937eed0e95511035ca2e4adeaea80a8a.json @@ -0,0 +1,16 @@ +{ + "db_name": "PostgreSQL", + "query": "UPDATE buy_trigger SET trigger_price = $3 WHERE owner_id = $1 AND stock_symbol = $2", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Text", + "Text", + "Float8" + ] + }, + "nullable": [] + }, + "hash": "edb02b47e2d4d4a7b5767900edb1d7ad937eed0e95511035ca2e4adeaea80a8a" +} diff --git a/lean/.sqlx/query-f45afc55b6686ff912cda716d606311cb880ca17d1de59046bbda34b1e7873ba.json b/lean/.sqlx/query-f45afc55b6686ff912cda716d606311cb880ca17d1de59046bbda34b1e7873ba.json new file mode 100644 index 0000000..593e566 --- /dev/null +++ b/lean/.sqlx/query-f45afc55b6686ff912cda716d606311cb880ca17d1de59046bbda34b1e7873ba.json @@ -0,0 +1,17 @@ +{ + "db_name": "PostgreSQL", + "query": "INSERT INTO queued_buy (user_id, stock_symbol, quoted_price, amount_dollars)VALUES ($1, $2, $3, $4)", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Text", + "Text", + "Float8", + "Float8" + ] + }, + "nullable": [] + }, + "hash": "f45afc55b6686ff912cda716d606311cb880ca17d1de59046bbda34b1e7873ba" +} diff --git a/lean/sqlx-data.json b/lean/sqlx-data.json deleted file mode 100644 index 9929ea3..0000000 --- a/lean/sqlx-data.json +++ /dev/null @@ -1,815 +0,0 @@ -{ - "db": "PostgreSQL", - "0b5d046f13b15fb90bcdcf53ef2f3b00e2261f74a42c0ef9c2bd845e9fefc15f": { - "describe": { - "columns": [], - "nullable": [], - "parameters": { - "Left": [ - "Float8", - "Text", - "Text" - ] - } - }, - "query": "\n UPDATE stock SET amount = amount - $1\n WHERE \n owner_id = $2 AND\n stock_symbol = $3 AND\n amount >= $1\n " - }, - "18f12ed04bbb17c9111c1dbe3a282df9287f4a7f05da6edf7b63600a38a3ddb0": { - "describe": { - "columns": [ - { - "name": "timestamp", - "ordinal": 0, - "type_info": "Timestamp" - }, - { - "name": "server", - "ordinal": 1, - "type_info": "Text" - }, - { - "name": "transaction_num", - "ordinal": 2, - "type_info": "Int4" - }, - { - "name": "username", - "ordinal": 3, - "type_info": "Text" - }, - { - "name": "log", - "ordinal": 4, - "type_info": "Jsonb" - } - ], - "nullable": [ - false, - false, - false, - false, - false - ], - "parameters": { - "Left": [ - "Text" - ] - } - }, - "query": "SELECT * FROM log_entry WHERE username = $1" - }, - "1f441590542da84b8d7f0936f0a4253a04434425554a7e08252b48ba9f1054a9": { - "describe": { - "columns": [], - "nullable": [], - "parameters": { - "Left": [ - "Float8", - "Text", - "Text" - ] - } - }, - "query": "UPDATE stock SET amount = amount - $1 WHERE owner_id = $2 AND stock_symbol = $3 AND amount >= $1" - }, - "3eb5f90d0397982e5bb58b7bb53116a855c2e8090aeef40ed17af107950adf40": { - "describe": { - "columns": [], - "nullable": [], - "parameters": { - "Left": [ - "Text", - "Float8" - ] - } - }, - "query": "UPDATE trader SET balance = balance + $2 WHERE user_id = $1" - }, - "474ee94334afdb02642decd9e8964845b355dce81d1c6837d77c44f7fa1bbb81": { - "describe": { - "columns": [ - { - "name": "amount_dollars", - "ordinal": 0, - "type_info": "Float8" - }, - { - "name": "stock_symbol", - "ordinal": 1, - "type_info": "Text" - }, - { - "name": "quoted_price", - "ordinal": 2, - "type_info": "Float8" - } - ], - "nullable": [ - false, - false, - false - ], - "parameters": { - "Left": [ - "Text" - ] - } - }, - "query": "DELETE FROM queued_sell WHERE user_id = $1 RETURNING amount_dollars, stock_symbol, quoted_price" - }, - "478d505a821d9719f2b06e7a17e16227481753d71d934fe35d26f65d73493015": { - "describe": { - "columns": [], - "nullable": [], - "parameters": { - "Left": [ - "Text", - "Text", - "Float8" - ] - } - }, - "query": "\n INSERT INTO stock (owner_id, stock_symbol, amount)\n VALUES ($1, $2, $3)\n ON CONFLICT (owner_id, stock_symbol)\n DO UPDATE SET\n amount = stock.amount + $3\n " - }, - "4e55ae2d91f13f6e2c10f36cd455d029957c852e65a31c7ed23067f143e0085d": { - "describe": { - "columns": [], - "nullable": [], - "parameters": { - "Left": [ - "Float8", - "Text" - ] - } - }, - "query": "UPDATE trader SET balance = balance - $1 WHERE user_id = $2 AND balance >= $1" - }, - "4f05eb8d55adc5ffb6f2c3bd698813f1b7d34f99985b3937e4077060e3c82e41": { - "describe": { - "columns": [ - { - "name": "name", - "ordinal": 0, - "type_info": "Text" - }, - { - "name": "price", - "ordinal": 1, - "type_info": "Float8" - } - ], - "nullable": [ - false, - false - ], - "parameters": { - "Left": [ - "Text" - ] - } - }, - "query": "SELECT stock_symbol as name, amount as price FROM stock WHERE owner_id = $1" - }, - "592b2cf584e4e3433508fc4375666734f596e747341513c090252fecc21ef27d": { - "describe": { - "columns": [], - "nullable": [], - "parameters": { - "Left": [ - "TimestampArray", - "TextArray", - "Int4Array", - "TextArray", - "JsonbArray" - ] - } - }, - "query": "\n INSERT INTO log_entry (timestamp, server, transaction_num, username, log) \n SELECT * FROM UNNEST ($1::timestamp[],$2::text[],$3::int[],$4::text[],$5::jsonb[])\n " - }, - "614119b1e86a7ed3a6eb4befbd250fa2e582869bcfafb72285b0ff427ce9dd34": { - "describe": { - "columns": [], - "nullable": [], - "parameters": { - "Left": [ - "Text", - "Float8" - ] - } - }, - "query": "INSERT INTO trader (user_id, balance) VALUES ($1, $2) ON CONFLICT (user_id) DO UPDATE SET balance = trader.balance + $2" - }, - "61773af25838b0d523415f08caf580e2184c19ed177c3d5f2e9c30baa3f222d4": { - "describe": { - "columns": [ - { - "name": "username", - "ordinal": 0, - "type_info": "Text" - }, - { - "name": "stock", - "ordinal": 1, - "type_info": "Text" - }, - { - "name": "shares_to_sell", - "ordinal": 2, - "type_info": "Float8" - }, - { - "name": "trigger_amount!", - "ordinal": 3, - "type_info": "Float8" - } - ], - "nullable": [ - false, - false, - false, - true - ], - "parameters": { - "Left": [ - "Text" - ] - } - }, - "query": "\n SELECT\n owner_id as username,\n stock_symbol as stock,\n amount_stock as shares_to_sell,\n trigger_price as \"trigger_amount!\"\n FROM sell_trigger\n WHERE owner_id = $1 AND trigger_price IS NOT NULL\n " - }, - "667ed4c9ceccf223358b6665d30f028ac3ca594ad1ff8f99b1801144aae86417": { - "describe": { - "columns": [ - { - "name": "amount_dollars", - "ordinal": 0, - "type_info": "Float8" - }, - { - "name": "time_created", - "ordinal": 1, - "type_info": "Timestamp" - }, - { - "name": "quoted_price", - "ordinal": 2, - "type_info": "Float8" - }, - { - "name": "stock_symbol", - "ordinal": 3, - "type_info": "Text" - } - ], - "nullable": [ - false, - false, - false, - false - ], - "parameters": { - "Left": [ - "Text" - ] - } - }, - "query": "DELETE FROM queued_sell WHERE user_id = $1 RETURNING amount_dollars, time_created, quoted_price, stock_symbol" - }, - "67fad622f62c146d64639531cae508b513e0ac300dd7b6457d2f111c59a35b64": { - "describe": { - "columns": [], - "nullable": [], - "parameters": { - "Left": [ - "Text", - "Text", - "Float8" - ] - } - }, - "query": "INSERT INTO stock (owner_id, stock_symbol, amount) VALUES ($1, $2, $3) ON CONFLICT (owner_id, stock_symbol) DO UPDATE SET amount = stock.amount + $3" - }, - "6b623b19a091fefa1f5224e98d924a1af01b7d6d991cacd0d46adf8ee0ba6845": { - "describe": { - "columns": [ - { - "name": "timestamp", - "ordinal": 0, - "type_info": "Timestamp" - }, - { - "name": "server", - "ordinal": 1, - "type_info": "Text" - }, - { - "name": "transaction_num", - "ordinal": 2, - "type_info": "Int4" - }, - { - "name": "username", - "ordinal": 3, - "type_info": "Text" - }, - { - "name": "log", - "ordinal": 4, - "type_info": "Jsonb" - } - ], - "nullable": [ - false, - false, - false, - false, - false - ], - "parameters": { - "Left": [ - "Text" - ] - } - }, - "query": "SELECT timestamp, server, transaction_num, username, log FROM log_entry WHERE username = $1" - }, - "708bc80d9b3ee8d7e660954e7cd6dd6edaa4aac1c46b5c9b2b64800a49895480": { - "describe": { - "columns": [ - { - "name": "amount_dollars", - "ordinal": 0, - "type_info": "Float8" - }, - { - "name": "time_created", - "ordinal": 1, - "type_info": "Timestamp" - } - ], - "nullable": [ - false, - false - ], - "parameters": { - "Left": [ - "Text" - ] - } - }, - "query": "DELETE FROM queued_buy WHERE user_id = $1 RETURNING amount_dollars, time_created" - }, - "70bc7b299211efca9ed60559752901da8bf354a7547b715eed0d4941e1a21874": { - "describe": { - "columns": [], - "nullable": [], - "parameters": { - "Left": [ - "Float8", - "Text", - "Text" - ] - } - }, - "query": "UPDATE sell_trigger SET trigger_price = $1 WHERE owner_id = $2 AND stock_symbol = $3" - }, - "71c63ae06c7e2ac29c5fb821279a9fbb14c646f71408d7cd95b3822daa0a8ac3": { - "describe": { - "columns": [ - { - "name": "amount_stock", - "ordinal": 0, - "type_info": "Float8" - } - ], - "nullable": [ - false - ], - "parameters": { - "Left": [ - "Text", - "Text" - ] - } - }, - "query": "DELETE FROM sell_trigger WHERE owner_id = $1 AND stock_symbol = $2 RETURNING amount_stock" - }, - "745eb81b99a74f49dcc4b587bd42fe8c0bf3e5339b12420dbfac087b9a166a76": { - "describe": { - "columns": [ - { - "name": "amount_dollars", - "ordinal": 0, - "type_info": "Float8" - } - ], - "nullable": [ - false - ], - "parameters": { - "Left": [ - "Text", - "Text" - ] - } - }, - "query": "DELETE FROM buy_trigger WHERE owner_id = $1 AND stock_symbol = $2 RETURNING amount_dollars" - }, - "75266347bd72da8e5e44147bdd8d218a1f81ea9aef7568b4eb2b14d857e667c7": { - "describe": { - "columns": [], - "nullable": [], - "parameters": { - "Left": [ - "Text", - "Text", - "Float8" - ] - } - }, - "query": "INSERT INTO buy_trigger (owner_id, stock_symbol, amount_dollars) VALUES ($1, $2, $3)" - }, - "798f395f93b28ee53bd4c42f6a050d87f33af14ae49a474047e20aa66550b626": { - "describe": { - "columns": [ - { - "name": "balance", - "ordinal": 0, - "type_info": "Float8" - } - ], - "nullable": [ - false - ], - "parameters": { - "Left": [ - "Float8", - "Text" - ] - } - }, - "query": "UPDATE trader SET balance = balance - $1 WHERE user_id = $2 AND balance >= $1 RETURNING balance" - }, - "85021a9a4c3c6353de87fee695a3780addfba267652475017084b1a283e58576": { - "describe": { - "columns": [ - { - "name": "owner_id", - "ordinal": 0, - "type_info": "Text" - }, - { - "name": "amount_dollars", - "ordinal": 1, - "type_info": "Float8" - } - ], - "nullable": [ - false, - false - ], - "parameters": { - "Left": [ - "Float8", - "Text" - ] - } - }, - "query": "\n DELETE FROM buy_trigger\n WHERE trigger_price >= $1 AND stock_symbol = $2 RETURNING owner_id, amount_dollars\n " - }, - "89a57d157606bce9674a48092115a9ba055aa8caff90cff417a2ec7bbce01a22": { - "describe": { - "columns": [], - "nullable": [], - "parameters": { - "Left": [ - "Float8", - "Text" - ] - } - }, - "query": "\n UPDATE trader SET balance = balance + $1 WHERE user_id = $2;\n " - }, - "9842e265cf3f4009847049f64e60f8591c319bcbb7131975b0d21940e8c8d32f": { - "describe": { - "columns": [], - "nullable": [], - "parameters": { - "Left": [ - "Text", - "Text", - "Float8", - "Float8" - ] - } - }, - "query": "\n INSERT INTO queued_sell (user_id, stock_symbol, quoted_price, amount_dollars)\n VALUES ($1, $2, $3, $4)\n ON CONFLICT (user_id)\n DO UPDATE SET\n stock_symbol = $2,\n quoted_price = $3,\n amount_dollars = $4,\n time_created = NOW()\n " - }, - "99bd329ede7aa25bfae7b91c620b115a3d851abfa4b18e1d6b2ebf5a828d34b0": { - "describe": { - "columns": [ - { - "name": "quoted_price", - "ordinal": 0, - "type_info": "Float8" - }, - { - "name": "amount_dollars", - "ordinal": 1, - "type_info": "Float8" - }, - { - "name": "stock_symbol", - "ordinal": 2, - "type_info": "Text" - } - ], - "nullable": [ - false, - false, - false - ], - "parameters": { - "Left": [ - "Text" - ] - } - }, - "query": "DELETE FROM queued_sell WHERE user_id = $1 returning quoted_price, amount_dollars, stock_symbol" - }, - "a03d253639396d19444c53793cc723b86a904386d45381a167f73b17980ba19c": { - "describe": { - "columns": [], - "nullable": [], - "parameters": { - "Left": [ - "Float8", - "Text" - ] - } - }, - "query": "UPDATE trader SET balance = balance + $1 WHERE user_id = $2" - }, - "b01118474a60d5212c0986dc18b6b7060adcf8d5c94a4883fd6cecca33809ca1": { - "describe": { - "columns": [ - { - "name": "amount_dollars", - "ordinal": 0, - "type_info": "Float8" - } - ], - "nullable": [ - false - ], - "parameters": { - "Left": [ - "Text" - ] - } - }, - "query": "DELETE FROM queued_buy WHERE user_id = $1 RETURNING amount_dollars" - }, - "b95f5efd8e3c302373ee2e1c63e83882068b2f15066bd4397524c25629186b1e": { - "describe": { - "columns": [ - { - "name": "owner_id", - "ordinal": 0, - "type_info": "Text" - }, - { - "name": "amount_stock", - "ordinal": 1, - "type_info": "Float8" - } - ], - "nullable": [ - false, - false - ], - "parameters": { - "Left": [ - "Float8", - "Text" - ] - } - }, - "query": "DELETE FROM sell_trigger WHERE trigger_price <= $1 AND stock_symbol = $2 RETURNING owner_id, amount_stock" - }, - "c733e387ec2e631933472a750a1f69845519228e9a0e54efbde7d3383411ba25": { - "describe": { - "columns": [ - { - "name": "user_id", - "ordinal": 0, - "type_info": "Text" - } - ], - "nullable": [ - false - ], - "parameters": { - "Left": [ - "Text" - ] - } - }, - "query": "SELECT user_id FROM trader WHERE user_id = $1" - }, - "cb96b90995ac76ea0a68ff99c71866804ab99775b4424fd70dc61d26db2d7f9c": { - "describe": { - "columns": [ - { - "name": "stock_symbol", - "ordinal": 0, - "type_info": "Text" - }, - { - "name": "quoted_price", - "ordinal": 1, - "type_info": "Float8" - }, - { - "name": "amount_dollars", - "ordinal": 2, - "type_info": "Float8" - }, - { - "name": "time_created", - "ordinal": 3, - "type_info": "Timestamp" - } - ], - "nullable": [ - false, - false, - false, - false - ], - "parameters": { - "Left": [ - "Text" - ] - } - }, - "query": "DELETE FROM queued_buy WHERE user_id = $1 RETURNING stock_symbol, quoted_price, amount_dollars, time_created" - }, - "cc09091adee059150ddc5dacc2727285ce50359b79029b6e9cf2d54492efd05a": { - "describe": { - "columns": [ - { - "name": "timestamp", - "ordinal": 0, - "type_info": "Timestamp" - }, - { - "name": "server", - "ordinal": 1, - "type_info": "Text" - }, - { - "name": "transaction_num", - "ordinal": 2, - "type_info": "Int4" - }, - { - "name": "username", - "ordinal": 3, - "type_info": "Text" - }, - { - "name": "log", - "ordinal": 4, - "type_info": "Jsonb" - } - ], - "nullable": [ - false, - false, - false, - false, - false - ], - "parameters": { - "Left": [] - } - }, - "query": "SELECT * FROM log_entry ORDER BY timestamp ASC" - }, - "d04627255755f5151a83750b65c8bed9b5ba64d692e3d82764a4075140b54fed": { - "describe": { - "columns": [ - { - "name": "balance", - "ordinal": 0, - "type_info": "Float8" - } - ], - "nullable": [ - false - ], - "parameters": { - "Left": [ - "Text" - ] - } - }, - "query": "SELECT balance FROM trader WHERE user_id = $1" - }, - "e01e7b653209f8b4c361c63105aa5e1e693845675253d88acf750247aad17dd4": { - "describe": { - "columns": [ - { - "name": "username", - "ordinal": 0, - "type_info": "Text" - }, - { - "name": "stock", - "ordinal": 1, - "type_info": "Text" - }, - { - "name": "buy_amount", - "ordinal": 2, - "type_info": "Float8" - }, - { - "name": "trigger_amount!", - "ordinal": 3, - "type_info": "Float8" - } - ], - "nullable": [ - false, - false, - false, - true - ], - "parameters": { - "Left": [ - "Text" - ] - } - }, - "query": "\n SELECT\n owner_id as username,\n stock_symbol as stock,\n amount_dollars as buy_amount,\n trigger_price as \"trigger_amount!\"\n FROM buy_trigger\n WHERE owner_id = $1 AND trigger_price IS NOT NULL\n " - }, - "e060004a9682688fd2c9c362e7d4291b42d5e24224792000635bc05aca0d4994": { - "describe": { - "columns": [], - "nullable": [], - "parameters": { - "Left": [ - "Float8", - "Text", - "Text" - ] - } - }, - "query": "UPDATE stock SET amount = amount + $1 WHERE owner_id = $2 AND stock_symbol = $3" - }, - "e442247ab078298dbf3843d6be2d65d8031562d74b6639b23b56927b2a3365b2": { - "describe": { - "columns": [], - "nullable": [], - "parameters": { - "Left": [ - "Text", - "Text", - "Float8" - ] - } - }, - "query": "INSERT INTO sell_trigger (owner_id, stock_symbol, amount_stock) VALUES ($1, $2, $3)" - }, - "edb02b47e2d4d4a7b5767900edb1d7ad937eed0e95511035ca2e4adeaea80a8a": { - "describe": { - "columns": [], - "nullable": [], - "parameters": { - "Left": [ - "Text", - "Text", - "Float8" - ] - } - }, - "query": "UPDATE buy_trigger SET trigger_price = $3 WHERE owner_id = $1 AND stock_symbol = $2" - }, - "f45afc55b6686ff912cda716d606311cb880ca17d1de59046bbda34b1e7873ba": { - "describe": { - "columns": [], - "nullable": [], - "parameters": { - "Left": [ - "Text", - "Text", - "Float8", - "Float8" - ] - } - }, - "query": "INSERT INTO queued_buy (user_id, stock_symbol, quoted_price, amount_dollars)VALUES ($1, $2, $3, $4)" - } -} \ No newline at end of file diff --git a/lean/src/buy/cancel_buy.rs b/lean/src/buy/cancel_buy.rs index ab2c222..57ea9f6 100644 --- a/lean/src/buy/cancel_buy.rs +++ b/lean/src/buy/cancel_buy.rs @@ -1,3 +1,4 @@ +use std::ops::DerefMut; use crate::log::AccountTransaction; use crate::{begin_transaction, commit_transaction}; use sqlx::types::time::{OffsetDateTime, PrimitiveDateTime}; @@ -42,7 +43,7 @@ async fn update_trader_balance( amount_dollars_time_created.amount_dollars, user_id ) - .execute(transaction) + .execute(transaction.deref_mut()) .await?; Ok(AccountTransaction( @@ -60,7 +61,7 @@ async fn delete_queued_buy( "DELETE FROM queued_buy WHERE user_id = $1 RETURNING amount_dollars, time_created", user_id ) - .fetch_optional(transaction) + .fetch_optional(transaction.deref_mut()) .await? else { anyhow::bail!("no queued buy for user_id {user_id}"); }; diff --git a/lean/src/buy/commit_buy.rs b/lean/src/buy/commit_buy.rs index 939b16d..0be0e7e 100644 --- a/lean/src/buy/commit_buy.rs +++ b/lean/src/buy/commit_buy.rs @@ -1,3 +1,4 @@ +use std::ops::DerefMut; use crate::{begin_transaction, commit_transaction}; use sqlx::types::time::{OffsetDateTime, PrimitiveDateTime}; use sqlx::{PgPool, Postgres, Transaction}; @@ -38,12 +39,13 @@ async fn update_trader_balance( transaction: &mut Transaction<'static, Postgres>, queued_buy_no_user_id: &QueuedBuyNoUserId, ) -> anyhow::Result<()> { + let connection = transaction.deref_mut(); sqlx::query!( "UPDATE trader SET balance = balance + $1 WHERE user_id = $2", queued_buy_no_user_id.amount_dollars, user_id ) - .execute(transaction) + .execute(&mut *connection) .await?; Ok(()) } @@ -54,13 +56,14 @@ async fn update_stock( transaction: &mut Transaction<'static, Postgres>, queued_buy_no_user_id: QueuedBuyNoUserId, ) -> anyhow::Result<()> { + let connection = transaction.deref_mut(); sqlx::query!( "INSERT INTO stock (owner_id, stock_symbol, amount) VALUES ($1, $2, $3) ON CONFLICT (owner_id, stock_symbol) DO UPDATE SET amount = stock.amount + $3", user_id, queued_buy_no_user_id.stock_symbol, queued_buy_no_user_id.amount_dollars / queued_buy_no_user_id.quoted_price, ) - .execute(transaction) + .execute(&mut *connection) .await?; Ok(()) @@ -71,12 +74,13 @@ async fn delete_queued_buy( user_id: &str, transaction: &mut Transaction<'static, Postgres>, ) -> anyhow::Result { + let connection = transaction.deref_mut(); let Some(queued_buy_no_user_id) = sqlx::query_as!( QueuedBuyNoUserId, "DELETE FROM queued_buy WHERE user_id = $1 RETURNING stock_symbol, quoted_price, amount_dollars, time_created", user_id ) - .fetch_optional(transaction) + .fetch_optional(&mut *connection) .await? else { anyhow::bail!("no queued buy for user_id {user_id}"); }; diff --git a/lean/src/buy/init_buy.rs b/lean/src/buy/init_buy.rs index a93799c..fb5bb09 100644 --- a/lean/src/buy/init_buy.rs +++ b/lean/src/buy/init_buy.rs @@ -1,6 +1,7 @@ +use std::ops::DerefMut; use crate::log::AccountTransaction; use crate::{begin_transaction, commit_transaction}; -use sqlx::{PgPool, Postgres, Transaction}; +use sqlx::{PgConnection, PgPool, Postgres, Transaction}; #[derive(Debug, PartialEq)] pub struct AmountDollars { @@ -44,6 +45,7 @@ async fn insert_queued_buy( amount_dollars: f64, transaction: &mut Transaction<'static, Postgres>, ) -> anyhow::Result<()> { + let connection: &mut PgConnection = &mut *transaction; sqlx::query!( "INSERT INTO queued_buy (user_id, stock_symbol, quoted_price, amount_dollars)\ VALUES ($1, $2, $3, $4)", @@ -52,7 +54,7 @@ async fn insert_queued_buy( quoted_price, amount_dollars, ) - .execute(transaction) + .execute(connection) .await?; Ok(()) @@ -64,12 +66,13 @@ async fn update_trader_balance( amount_dollars: f64, transaction: &mut Transaction<'static, Postgres>, ) -> anyhow::Result { + let connection = transaction.deref_mut(); let postgres_result = sqlx::query!( "UPDATE trader SET balance = balance - $1 WHERE user_id = $2 AND balance >= $1", amount_dollars, user_id, ) - .execute(transaction) + .execute(connection) .await?; if postgres_result.rows_affected() == 0 { @@ -84,12 +87,13 @@ async fn delete_and_maybe_update( user_id: &str, transaction: &mut Transaction<'static, Postgres>, ) -> anyhow::Result { + let connection = transaction.deref_mut(); let old_buy = sqlx::query_as!( AmountDollars, "DELETE FROM queued_buy WHERE user_id = $1 RETURNING amount_dollars", user_id ) - .fetch_optional(&mut *transaction) + .fetch_optional(&mut *connection) .await?; match old_buy { @@ -99,7 +103,7 @@ async fn delete_and_maybe_update( amount_dollars, user_id ) - .execute(&mut *transaction) + .execute(&mut *connection) .await?; Ok(AccountTransaction(amount_dollars)) } diff --git a/lean/src/log.rs b/lean/src/log.rs index 967411d..b49a5e5 100644 --- a/lean/src/log.rs +++ b/lean/src/log.rs @@ -122,7 +122,7 @@ impl Logger { Some(c) => c, }; - save_log_entry_bulk(&mut conn, timestamp, server, transaction_num, username, log).await?; + save_log_entry_bulk(&mut *conn, timestamp, server, transaction_num, username, log).await?; *connection = Some(conn); diff --git a/lean/src/main.rs b/lean/src/main.rs index 25a1ed1..deaa493 100644 --- a/lean/src/main.rs +++ b/lean/src/main.rs @@ -127,15 +127,16 @@ async fn main() -> anyhow::Result<()> { ); Server::builder() - .layer(tower_http::request_id::SetRequestIdLayer::x_request_id( - MakeRequestUuid, - )) - .layer(metrics_layer) - .layer( - tower_http::trace::TraceLayer::new_for_grpc() - .on_response(DefaultOnResponse::default().latency_unit(LatencyUnit::Micros)) - .make_span_with(DefaultMakeSpan::new().include_headers(true)), - ) + // https://github.com/hyperium/tonic/issues/1579 + // .layer(tower_http::request_id::SetRequestIdLayer::x_request_id( + // MakeRequestUuid, + // )) + // .layer(metrics_layer) + // .layer( + // tower_http::trace::TraceLayer::new_for_grpc() + // .on_response(DefaultOnResponse::default().latency_unit(LatencyUnit::Micros)) + // .make_span_with(DefaultMakeSpan::new().include_headers(true)), + // ) .add_service(DayTraderServer::new(DayTraderImpl::new(pool, quote_client))) .serve_with_shutdown(server_addr, async { tokio::signal::ctrl_c().await.unwrap(); diff --git a/lean/src/sell/cancel_sell.rs b/lean/src/sell/cancel_sell.rs index 199c82b..2e52d61 100644 --- a/lean/src/sell/cancel_sell.rs +++ b/lean/src/sell/cancel_sell.rs @@ -1,3 +1,4 @@ +use std::ops::DerefMut; use crate::{begin_transaction, commit_transaction}; use sqlx::{PgPool, Postgres, Transaction}; @@ -32,7 +33,7 @@ async fn update_stock_holdings( record.stock_symbol, record.amount_dollars / record.quoted_price ) - .execute(transaction) + .execute(transaction.deref_mut()) .await?; Ok(()) @@ -53,7 +54,7 @@ async fn delete_queued_sell( "DELETE FROM queued_sell WHERE user_id = $1 RETURNING amount_dollars, stock_symbol, quoted_price", user_id ) - .fetch_one(transaction) + .fetch_one(transaction.deref_mut()) .await?; Ok(record) } @@ -89,13 +90,13 @@ mod tests { "marcus", "AAPL" ) - .fetch_one(&pool) + .fetch_one(&mut *pool) .await?; assert_eq!(stock.amount, 1_f64); let queued_sell = sqlx::query!("SELECT * FROM queued_sell WHERE user_id = $1", "marcus") - .fetch_optional(&pool) + .fetch_optional(&mut *pool) .await?; assert!( diff --git a/lean/src/sell/commit_sell.rs b/lean/src/sell/commit_sell.rs index 0ee0428..36051bc 100644 --- a/lean/src/sell/commit_sell.rs +++ b/lean/src/sell/commit_sell.rs @@ -1,3 +1,4 @@ +use std::ops::DerefMut; use crate::log::AccountTransaction; use crate::{begin_transaction, commit_transaction}; use anyhow::bail; @@ -38,7 +39,7 @@ async fn update_balance( queued_sell.amount_dollars, user_id ) - .execute(transaction) + .execute(transaction.deref_mut()) .await?; Ok(AccountTransaction(queued_sell.amount_dollars)) @@ -56,7 +57,7 @@ async fn restore_stock( user_id, queued_sell.stock_symbol ) - .execute(transaction) + .execute(transaction.deref_mut()) .await?; Ok(()) @@ -78,7 +79,7 @@ async fn delete_queued_sell_by_user( "DELETE FROM queued_sell WHERE user_id = $1 RETURNING amount_dollars, time_created, quoted_price, stock_symbol", user_id ) - .fetch_optional(transaction) + .fetch_optional(transaction.deref_mut()) .await? else { bail!("no queued sell for user_id {user_id}"); }; diff --git a/lean/src/sell/init_sell.rs b/lean/src/sell/init_sell.rs index 2ea5877..719c0f1 100644 --- a/lean/src/sell/init_sell.rs +++ b/lean/src/sell/init_sell.rs @@ -1,3 +1,4 @@ +use std::ops::{Deref, DerefMut}; use crate::{begin_transaction, commit_transaction}; use anyhow::bail; use sqlx::postgres::PgQueryResult; @@ -56,6 +57,7 @@ async fn resolve_old_queued_sell( user_id: &str, transaction: &mut Transaction<'static, Postgres>, ) -> anyhow::Result<()> { + let transaction = transaction.deref_mut(); if let Some(record) = sqlx::query!("DELETE FROM queued_sell WHERE user_id = $1 returning quoted_price, amount_dollars, stock_symbol", user_id) .fetch_optional(&mut *transaction) .await? { @@ -91,7 +93,7 @@ async fn created_queued_sell( quote, dollar_amount ) - .execute(transaction) + .execute(transaction.deref_mut()) .await?; Ok(()) @@ -117,7 +119,7 @@ async fn update_stock_holdings( user_id, stock_symbol ) - .execute(transaction) + .execute(transaction.deref_mut()) .await?; Ok(query_result) @@ -161,7 +163,7 @@ mod tests { "marcus", "APPL", ) - .fetch_optional(&pool) + .fetch_optional(&mut *pool) .await? .expect("expected sell to exist"); @@ -177,7 +179,7 @@ mod tests { ); let stock = sqlx::query_as!(Stock, "SELECT * FROM stock WHERE owner_id = 'marcus'") - .fetch_optional(&pool) + .fetch_optional(&mut *pool) .await? .expect("expected stock to exist"); @@ -203,7 +205,7 @@ mod tests { assert!(sell.is_err(), "expected error but was {sell:?}"); let queued_sell = sqlx::query!("SELECT * FROM queued_sell WHERE user_id = 'marcus'") - .fetch_optional(&pool) + .fetch_optional(&mut *pool) .await?; assert!( @@ -212,7 +214,7 @@ mod tests { ); let stock = sqlx::query_as!(Stock, "SELECT * FROM stock WHERE owner_id = 'marcus'") - .fetch_one(&pool) + .fetch_one(&mut *pool) .await?; assert_eq!( diff --git a/lean/src/trigger/buy/cancel_set_buy.rs b/lean/src/trigger/buy/cancel_set_buy.rs index d4fa970..96b6ba7 100644 --- a/lean/src/trigger/buy/cancel_set_buy.rs +++ b/lean/src/trigger/buy/cancel_set_buy.rs @@ -1,3 +1,4 @@ +use std::ops::DerefMut; use crate::log::AccountTransaction; use crate::{begin_transaction, commit_transaction}; use sqlx::{PgPool, Postgres, Transaction}; @@ -30,7 +31,7 @@ async fn update_trader_balance( record.amount_dollars, user_id ) - .execute(transaction) + .execute(transaction.deref_mut()) .await?; Ok(AccountTransaction(record.amount_dollars)) @@ -51,7 +52,7 @@ async fn delete_buy_trigger( user_id, stock_symbol ) - .fetch_one(transaction) + .fetch_one(transaction.deref_mut()) .await?; Ok(record) diff --git a/lean/src/trigger/buy/set_buy_amount.rs b/lean/src/trigger/buy/set_buy_amount.rs index ed86069..171c4e4 100644 --- a/lean/src/trigger/buy/set_buy_amount.rs +++ b/lean/src/trigger/buy/set_buy_amount.rs @@ -1,3 +1,4 @@ +use std::ops::DerefMut; use crate::log::AccountTransaction; use crate::{begin_transaction, commit_transaction}; use anyhow::bail; @@ -38,7 +39,7 @@ async fn create_buy_trigger( stock_symbol, amount_dollars, ) - .execute(transaction) + .execute(transaction.deref_mut()) .await?; Ok(()) @@ -49,6 +50,7 @@ async fn remove_previous_buy_trigger( stock_symbol: &str, transaction: &mut Transaction<'static, Postgres>, ) -> anyhow::Result { + let transaction = transaction.deref_mut(); Ok(match sqlx::query!("DELETE FROM buy_trigger WHERE owner_id = $1 AND stock_symbol = $2 RETURNING amount_dollars", user_id, stock_symbol) .fetch_optional(&mut *transaction) .await? { @@ -78,7 +80,7 @@ async fn remove_requisite_balance( amount_dollars, user_id, ) - .fetch_one(transaction) + .fetch_one(transaction.deref_mut()) .await?; if result.balance.is_sign_positive() { diff --git a/lean/src/trigger/sell/set_sell_amount.rs b/lean/src/trigger/sell/set_sell_amount.rs index 3507003..936fec3 100644 --- a/lean/src/trigger/sell/set_sell_amount.rs +++ b/lean/src/trigger/sell/set_sell_amount.rs @@ -1,3 +1,4 @@ +use std::ops::DerefMut; use crate::{begin_transaction, commit_transaction}; use anyhow::bail; use sqlx::postgres::PgQueryResult; @@ -40,7 +41,7 @@ async fn insert_sell_trigger( stock_symbol, amount_stock ) - .execute(transaction) + .execute(transaction.deref_mut()) .await?; Ok(()) @@ -58,7 +59,7 @@ async fn remove_stock( amount_stock, user_id, stock_symbol - ).execute(transaction).await?; + ).execute(transaction.deref_mut()).await?; Ok(result) } @@ -68,6 +69,7 @@ async fn remove_prev_sell_trigger( stock_symbol: &str, transaction: &mut Transaction<'static, Postgres>, ) -> anyhow::Result<()> { + let transaction = transaction.deref_mut(); if let Some(record) = sqlx::query!( "DELETE FROM sell_trigger WHERE owner_id = $1 AND stock_symbol = $2 RETURNING amount_stock", user_id, diff --git a/quote-server-adaptor/src/main.rs b/quote-server-adaptor/src/main.rs index 6260129..bd3717f 100644 --- a/quote-server-adaptor/src/main.rs +++ b/quote-server-adaptor/src/main.rs @@ -19,6 +19,7 @@ use tokio::net::TcpStream; use tokio::task::JoinSet; use tonic::transport::Server; use tonic::{async_trait, Request, Response, Status}; +use tower::ServiceBuilder; use tower_http::trace::{DefaultOnRequest, DefaultOnResponse}; use tower_http::LatencyUnit; use tracing::{info, instrument}; @@ -64,15 +65,16 @@ async fn main() -> Result<(), Box> { .parse()?; let server = Server::builder() - .layer( - tower_http::trace::TraceLayer::new_for_grpc() - .on_request(DefaultOnRequest::default().level(tracing::Level::INFO)) - .on_response( - DefaultOnResponse::default() - .level(tracing::Level::INFO) - .latency_unit(LatencyUnit::Micros), - ), - ) + // https://github.com/hyperium/tonic/issues/1579 + // .layer( + // tower_http::trace::TraceLayer::new_for_grpc() + // .on_request(DefaultOnRequest::default().level(tracing::Level::INFO)) + // .on_response( + // DefaultOnResponse::default() + // .level(tracing::Level::INFO) + // .latency_unit(LatencyUnit::Micros), + // ) + // ) .add_service(QuoteServer::new(quoter)) .serve_with_shutdown(addr, async { tokio::signal::ctrl_c().await.unwrap(); @@ -256,7 +258,7 @@ where W: AsyncWrite + Unpin + Debug, R: AsyncBufRead + Unpin + Debug, { - if (writer.write_all(message.as_bytes()).await).is_err() { + if writer.write_all(message.as_bytes()).await.is_err() { return Err("Failed to write to socket."); }