diff --git a/.sqlx/query-1375fb240bc6dc5a884902b622dec6ee35c4feff6156946fa0beb5f99bdcd79a.json b/.sqlx/query-1375fb240bc6dc5a884902b622dec6ee35c4feff6156946fa0beb5f99bdcd79a.json new file mode 100644 index 000000000..23c6c4140 --- /dev/null +++ b/.sqlx/query-1375fb240bc6dc5a884902b622dec6ee35c4feff6156946fa0beb5f99bdcd79a.json @@ -0,0 +1,12 @@ +{ + "db_name": "PostgreSQL", + "query": "DELETE FROM scaling_tier_history WHERE reason LIKE 'TEST:%'", + "describe": { + "columns": [], + "parameters": { + "Left": [] + }, + "nullable": [] + }, + "hash": "1375fb240bc6dc5a884902b622dec6ee35c4feff6156946fa0beb5f99bdcd79a" +} diff --git a/.sqlx/query-2a88bd43a5df2a9f9c5bbcfadf6c869f0d273f8063411e49f6691c4d20655a14.json b/.sqlx/query-2a88bd43a5df2a9f9c5bbcfadf6c869f0d273f8063411e49f6691c4d20655a14.json new file mode 100644 index 000000000..7e820fcad --- /dev/null +++ b/.sqlx/query-2a88bd43a5df2a9f9c5bbcfadf6c869f0d273f8063411e49f6691c4d20655a14.json @@ -0,0 +1,58 @@ +{ + "db_name": "PostgreSQL", + "query": "\n SELECT\n strategy_id,\n strategy_name,\n strategy_type,\n parameters,\n status,\n created_at,\n updated_at\n FROM strategy_configs\n WHERE strategy_id = $1\n ", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "strategy_id", + "type_info": "Uuid" + }, + { + "ordinal": 1, + "name": "strategy_name", + "type_info": "Text" + }, + { + "ordinal": 2, + "name": "strategy_type", + "type_info": "Text" + }, + { + "ordinal": 3, + "name": "parameters", + "type_info": "Jsonb" + }, + { + "ordinal": 4, + "name": "status", + "type_info": "Text" + }, + { + "ordinal": 5, + "name": "created_at", + "type_info": "Timestamptz" + }, + { + "ordinal": 6, + "name": "updated_at", + "type_info": "Timestamptz" + } + ], + "parameters": { + "Left": [ + "Uuid" + ] + }, + "nullable": [ + false, + false, + false, + false, + false, + false, + false + ] + }, + "hash": "2a88bd43a5df2a9f9c5bbcfadf6c869f0d273f8063411e49f6691c4d20655a14" +} diff --git a/.sqlx/query-445c39a3d8a1aa87aebe840f1ac1469476e10b38c50bdb2b79b38666f2b6aed3.json b/.sqlx/query-445c39a3d8a1aa87aebe840f1ac1469476e10b38c50bdb2b79b38666f2b6aed3.json new file mode 100644 index 000000000..949ec579f --- /dev/null +++ b/.sqlx/query-445c39a3d8a1aa87aebe840f1ac1469476e10b38c50bdb2b79b38666f2b6aed3.json @@ -0,0 +1,32 @@ +{ + "db_name": "PostgreSQL", + "query": "\n SELECT from_tier, to_tier, reason\n FROM scaling_tier_history\n WHERE reason LIKE 'TEST:%'\n ORDER BY timestamp ASC\n ", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "from_tier", + "type_info": "Int4" + }, + { + "ordinal": 1, + "name": "to_tier", + "type_info": "Int4" + }, + { + "ordinal": 2, + "name": "reason", + "type_info": "Text" + } + ], + "parameters": { + "Left": [] + }, + "nullable": [ + true, + false, + false + ] + }, + "hash": "445c39a3d8a1aa87aebe840f1ac1469476e10b38c50bdb2b79b38666f2b6aed3" +} diff --git a/.sqlx/query-658af28c6af7ce5f0dc9709b7d46b495707680bde6f03920621a0fb4982b8f39.json b/.sqlx/query-658af28c6af7ce5f0dc9709b7d46b495707680bde6f03920621a0fb4982b8f39.json new file mode 100644 index 000000000..217802e46 --- /dev/null +++ b/.sqlx/query-658af28c6af7ce5f0dc9709b7d46b495707680bde6f03920621a0fb4982b8f39.json @@ -0,0 +1,40 @@ +{ + "db_name": "PostgreSQL", + "query": "\n SELECT from_tier, to_tier, capital, reason\n FROM scaling_tier_history\n WHERE capital::TEXT = $1\n ORDER BY timestamp DESC\n LIMIT 1\n ", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "from_tier", + "type_info": "Int4" + }, + { + "ordinal": 1, + "name": "to_tier", + "type_info": "Int4" + }, + { + "ordinal": 2, + "name": "capital", + "type_info": "Numeric" + }, + { + "ordinal": 3, + "name": "reason", + "type_info": "Text" + } + ], + "parameters": { + "Left": [ + "Text" + ] + }, + "nullable": [ + true, + false, + false, + false + ] + }, + "hash": "658af28c6af7ce5f0dc9709b7d46b495707680bde6f03920621a0fb4982b8f39" +} diff --git a/.sqlx/query-764647d36aa58c8e2fd3d740fa2e7d4fa5c2399f0e8e04c03dccccf422fc4406.json b/.sqlx/query-764647d36aa58c8e2fd3d740fa2e7d4fa5c2399f0e8e04c03dccccf422fc4406.json new file mode 100644 index 000000000..3e9e3c810 --- /dev/null +++ b/.sqlx/query-764647d36aa58c8e2fd3d740fa2e7d4fa5c2399f0e8e04c03dccccf422fc4406.json @@ -0,0 +1,22 @@ +{ + "db_name": "PostgreSQL", + "query": "\n INSERT INTO autonomous_scaling_config (\n config_id, enabled, current_tier, current_capital,\n current_symbols, last_rebalance, performance_30d,\n created_at, updated_at\n )\n VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)\n ON CONFLICT (config_id) DO UPDATE\n SET current_tier = EXCLUDED.current_tier,\n current_capital = EXCLUDED.current_capital,\n performance_30d = EXCLUDED.performance_30d,\n updated_at = EXCLUDED.updated_at\n ", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Uuid", + "Bool", + "Int4", + "Numeric", + "Int4", + "Timestamptz", + "Jsonb", + "Timestamptz", + "Timestamptz" + ] + }, + "nullable": [] + }, + "hash": "764647d36aa58c8e2fd3d740fa2e7d4fa5c2399f0e8e04c03dccccf422fc4406" +} diff --git a/.sqlx/query-84222bb2af8e47b914b2230ae95895f9bb79da2047daea7c42ce5c870f8d3d53.json b/.sqlx/query-84222bb2af8e47b914b2230ae95895f9bb79da2047daea7c42ce5c870f8d3d53.json new file mode 100644 index 000000000..79c4fb928 --- /dev/null +++ b/.sqlx/query-84222bb2af8e47b914b2230ae95895f9bb79da2047daea7c42ce5c870f8d3d53.json @@ -0,0 +1,19 @@ +{ + "db_name": "PostgreSQL", + "query": "\n INSERT INTO scaling_tier_history (\n event_id, from_tier, to_tier, capital, reason, timestamp\n )\n VALUES ($1, $2, $3, $4, $5, $6)\n ", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Uuid", + "Int4", + "Int4", + "Numeric", + "Text", + "Timestamptz" + ] + }, + "nullable": [] + }, + "hash": "84222bb2af8e47b914b2230ae95895f9bb79da2047daea7c42ce5c870f8d3d53" +} diff --git a/.sqlx/query-887f5a4d58a911c2ad2bc33d86bf57816c410415b666482852d233d88b8b63ee.json b/.sqlx/query-887f5a4d58a911c2ad2bc33d86bf57816c410415b666482852d233d88b8b63ee.json new file mode 100644 index 000000000..dd0bd518a --- /dev/null +++ b/.sqlx/query-887f5a4d58a911c2ad2bc33d86bf57816c410415b666482852d233d88b8b63ee.json @@ -0,0 +1,52 @@ +{ + "db_name": "PostgreSQL", + "query": "\n SELECT universe_id, criteria, instruments, metrics, created_at, updated_at\n FROM trading_universes\n WHERE universe_id = $1\n ", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "universe_id", + "type_info": "Text" + }, + { + "ordinal": 1, + "name": "criteria", + "type_info": "Jsonb" + }, + { + "ordinal": 2, + "name": "instruments", + "type_info": "Jsonb" + }, + { + "ordinal": 3, + "name": "metrics", + "type_info": "Jsonb" + }, + { + "ordinal": 4, + "name": "created_at", + "type_info": "Timestamptz" + }, + { + "ordinal": 5, + "name": "updated_at", + "type_info": "Timestamptz" + } + ], + "parameters": { + "Left": [ + "Text" + ] + }, + "nullable": [ + false, + false, + false, + false, + false, + false + ] + }, + "hash": "887f5a4d58a911c2ad2bc33d86bf57816c410415b666482852d233d88b8b63ee" +} diff --git a/.sqlx/query-91de6a60159626c5cb3ee1c3d8c66c0e2ec33c32bdc6510c235931b3cd509f2d.json b/.sqlx/query-91de6a60159626c5cb3ee1c3d8c66c0e2ec33c32bdc6510c235931b3cd509f2d.json new file mode 100644 index 000000000..5909bb2c8 --- /dev/null +++ b/.sqlx/query-91de6a60159626c5cb3ee1c3d8c66c0e2ec33c32bdc6510c235931b3cd509f2d.json @@ -0,0 +1,26 @@ +{ + "db_name": "PostgreSQL", + "query": "\n INSERT INTO agent_orders (\n order_id, allocation_id, symbol, side, quantity, price,\n order_type, status, time_in_force, filled_quantity,\n client_order_id, created_at, metadata\n )\n VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13)\n ", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Text", + "Text", + "Text", + "Text", + "Numeric", + "Numeric", + "Text", + "Text", + "Text", + "Numeric", + "Text", + "Timestamptz", + "Jsonb" + ] + }, + "nullable": [] + }, + "hash": "91de6a60159626c5cb3ee1c3d8c66c0e2ec33c32bdc6510c235931b3cd509f2d" +} diff --git a/.sqlx/query-adc202700591650ef4881556c12f30324d1479bbd3c182361b7d3f6e0c12bdcf.json b/.sqlx/query-adc202700591650ef4881556c12f30324d1479bbd3c182361b7d3f6e0c12bdcf.json new file mode 100644 index 000000000..dcb4b71f4 --- /dev/null +++ b/.sqlx/query-adc202700591650ef4881556c12f30324d1479bbd3c182361b7d3f6e0c12bdcf.json @@ -0,0 +1,19 @@ +{ + "db_name": "PostgreSQL", + "query": "\n INSERT INTO trading_universes (\n universe_id, criteria, instruments, metrics, created_at, updated_at\n )\n VALUES ($1, $2, $3, $4, $5, $6)\n ON CONFLICT (universe_id) DO UPDATE\n SET criteria = EXCLUDED.criteria,\n instruments = EXCLUDED.instruments,\n metrics = EXCLUDED.metrics,\n updated_at = EXCLUDED.updated_at\n ", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Text", + "Jsonb", + "Jsonb", + "Jsonb", + "Timestamptz", + "Timestamptz" + ] + }, + "nullable": [] + }, + "hash": "adc202700591650ef4881556c12f30324d1479bbd3c182361b7d3f6e0c12bdcf" +} diff --git a/.sqlx/query-afbc1a6d33f49ee59b0a5a69c1a9f1ba688b85b9450a382b24ff775314296c17.json b/.sqlx/query-afbc1a6d33f49ee59b0a5a69c1a9f1ba688b85b9450a382b24ff775314296c17.json new file mode 100644 index 000000000..0002a0aa6 --- /dev/null +++ b/.sqlx/query-afbc1a6d33f49ee59b0a5a69c1a9f1ba688b85b9450a382b24ff775314296c17.json @@ -0,0 +1,68 @@ +{ + "db_name": "PostgreSQL", + "query": "\n SELECT config_id, enabled, current_tier, current_capital,\n current_symbols, last_rebalance, performance_30d,\n created_at, updated_at\n FROM autonomous_scaling_config\n ORDER BY created_at DESC\n LIMIT 1\n ", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "config_id", + "type_info": "Uuid" + }, + { + "ordinal": 1, + "name": "enabled", + "type_info": "Bool" + }, + { + "ordinal": 2, + "name": "current_tier", + "type_info": "Int4" + }, + { + "ordinal": 3, + "name": "current_capital", + "type_info": "Numeric" + }, + { + "ordinal": 4, + "name": "current_symbols", + "type_info": "Int4" + }, + { + "ordinal": 5, + "name": "last_rebalance", + "type_info": "Timestamptz" + }, + { + "ordinal": 6, + "name": "performance_30d", + "type_info": "Jsonb" + }, + { + "ordinal": 7, + "name": "created_at", + "type_info": "Timestamptz" + }, + { + "ordinal": 8, + "name": "updated_at", + "type_info": "Timestamptz" + } + ], + "parameters": { + "Left": [] + }, + "nullable": [ + false, + true, + false, + false, + false, + false, + false, + true, + true + ] + }, + "hash": "afbc1a6d33f49ee59b0a5a69c1a9f1ba688b85b9450a382b24ff775314296c17" +} diff --git a/.sqlx/query-c8320f997235a57e61bdeac6551035e5d11eceed0cf26e43b8c2f3c9c465eb9f.json b/.sqlx/query-c8320f997235a57e61bdeac6551035e5d11eceed0cf26e43b8c2f3c9c465eb9f.json new file mode 100644 index 000000000..ab2557a0f --- /dev/null +++ b/.sqlx/query-c8320f997235a57e61bdeac6551035e5d11eceed0cf26e43b8c2f3c9c465eb9f.json @@ -0,0 +1,22 @@ +{ + "db_name": "PostgreSQL", + "query": "\n INSERT INTO autonomous_scaling_config (\n config_id, enabled, current_tier, current_capital,\n current_symbols, last_rebalance, performance_30d,\n created_at, updated_at\n )\n VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)\n ON CONFLICT (config_id) DO UPDATE\n SET enabled = EXCLUDED.enabled\n ", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Uuid", + "Bool", + "Int4", + "Numeric", + "Int4", + "Timestamptz", + "Jsonb", + "Timestamptz", + "Timestamptz" + ] + }, + "nullable": [] + }, + "hash": "c8320f997235a57e61bdeac6551035e5d11eceed0cf26e43b8c2f3c9c465eb9f" +} diff --git a/.sqlx/query-cf57dcbbff80d4dbfcbbed76c34109f8c93afd1325f37d368911793d75f354b6.json b/.sqlx/query-cf57dcbbff80d4dbfcbbed76c34109f8c93afd1325f37d368911793d75f354b6.json new file mode 100644 index 000000000..28a9a0891 --- /dev/null +++ b/.sqlx/query-cf57dcbbff80d4dbfcbbed76c34109f8c93afd1325f37d368911793d75f354b6.json @@ -0,0 +1,58 @@ +{ + "db_name": "PostgreSQL", + "query": "\n SELECT order_id, allocation_id, symbol, side, quantity, order_type, status\n FROM agent_orders\n WHERE order_id = $1\n ", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "order_id", + "type_info": "Text" + }, + { + "ordinal": 1, + "name": "allocation_id", + "type_info": "Text" + }, + { + "ordinal": 2, + "name": "symbol", + "type_info": "Text" + }, + { + "ordinal": 3, + "name": "side", + "type_info": "Text" + }, + { + "ordinal": 4, + "name": "quantity", + "type_info": "Numeric" + }, + { + "ordinal": 5, + "name": "order_type", + "type_info": "Text" + }, + { + "ordinal": 6, + "name": "status", + "type_info": "Text" + } + ], + "parameters": { + "Left": [ + "Text" + ] + }, + "nullable": [ + false, + false, + false, + false, + false, + false, + false + ] + }, + "hash": "cf57dcbbff80d4dbfcbbed76c34109f8c93afd1325f37d368911793d75f354b6" +} diff --git a/.sqlx/query-e46c13c52515f385c54e1a459788f9ea927c5f99c3eec214ee11972e5c859586.json b/.sqlx/query-e46c13c52515f385c54e1a459788f9ea927c5f99c3eec214ee11972e5c859586.json new file mode 100644 index 000000000..e7377b96a --- /dev/null +++ b/.sqlx/query-e46c13c52515f385c54e1a459788f9ea927c5f99c3eec214ee11972e5c859586.json @@ -0,0 +1,12 @@ +{ + "db_name": "PostgreSQL", + "query": "DELETE FROM autonomous_scaling_config WHERE current_tier = 999", + "describe": { + "columns": [], + "parameters": { + "Left": [] + }, + "nullable": [] + }, + "hash": "e46c13c52515f385c54e1a459788f9ea927c5f99c3eec214ee11972e5c859586" +} diff --git a/.sqlx/query-e88a192d1ad771838a473e16a677146f3fef9346ea88d294a97352282384fd5c.json b/.sqlx/query-e88a192d1ad771838a473e16a677146f3fef9346ea88d294a97352282384fd5c.json new file mode 100644 index 000000000..346506d05 --- /dev/null +++ b/.sqlx/query-e88a192d1ad771838a473e16a677146f3fef9346ea88d294a97352282384fd5c.json @@ -0,0 +1,15 @@ +{ + "db_name": "PostgreSQL", + "query": "\n UPDATE strategy_configs\n SET status = $1\n WHERE strategy_id = $2\n ", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Text", + "Uuid" + ] + }, + "nullable": [] + }, + "hash": "e88a192d1ad771838a473e16a677146f3fef9346ea88d294a97352282384fd5c" +} diff --git a/.sqlx/query-e9013bc9177b77530f34663e184c24698bd7b4c8d63f59dc051f087e45d66c1b.json b/.sqlx/query-e9013bc9177b77530f34663e184c24698bd7b4c8d63f59dc051f087e45d66c1b.json new file mode 100644 index 000000000..b53da938e --- /dev/null +++ b/.sqlx/query-e9013bc9177b77530f34663e184c24698bd7b4c8d63f59dc051f087e45d66c1b.json @@ -0,0 +1,22 @@ +{ + "db_name": "PostgreSQL", + "query": "\n INSERT INTO autonomous_scaling_config (\n config_id, enabled, current_tier, current_capital,\n current_symbols, last_rebalance, performance_30d,\n created_at, updated_at\n )\n VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)\n ON CONFLICT (config_id) DO UPDATE\n SET enabled = EXCLUDED.enabled,\n current_tier = EXCLUDED.current_tier,\n current_capital = EXCLUDED.current_capital,\n current_symbols = EXCLUDED.current_symbols,\n last_rebalance = EXCLUDED.last_rebalance,\n performance_30d = EXCLUDED.performance_30d,\n updated_at = EXCLUDED.updated_at\n ", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Uuid", + "Bool", + "Int4", + "Numeric", + "Int4", + "Timestamptz", + "Jsonb", + "Timestamptz", + "Timestamptz" + ] + }, + "nullable": [] + }, + "hash": "e9013bc9177b77530f34663e184c24698bd7b4c8d63f59dc051f087e45d66c1b" +} diff --git a/.sqlx/query-f0ca1fdc20012d2aa12fdebf8b2f005851b71a820580587b8315fe430a574333.json b/.sqlx/query-f0ca1fdc20012d2aa12fdebf8b2f005851b71a820580587b8315fe430a574333.json new file mode 100644 index 000000000..80629bf10 --- /dev/null +++ b/.sqlx/query-f0ca1fdc20012d2aa12fdebf8b2f005851b71a820580587b8315fe430a574333.json @@ -0,0 +1,22 @@ +{ + "db_name": "PostgreSQL", + "query": "\n INSERT INTO autonomous_scaling_config (\n config_id, enabled, current_tier, current_capital,\n current_symbols, last_rebalance, performance_30d,\n created_at, updated_at\n )\n VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)\n ON CONFLICT (config_id) DO UPDATE\n SET current_tier = EXCLUDED.current_tier,\n performance_30d = EXCLUDED.performance_30d,\n updated_at = EXCLUDED.updated_at\n ", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Uuid", + "Bool", + "Int4", + "Numeric", + "Int4", + "Timestamptz", + "Jsonb", + "Timestamptz", + "Timestamptz" + ] + }, + "nullable": [] + }, + "hash": "f0ca1fdc20012d2aa12fdebf8b2f005851b71a820580587b8315fe430a574333" +} diff --git a/.sqlx/query-f218fc76780ca39d146674eae4bab7707bedc41d641545d8ea96df69ee5a36e9.json b/.sqlx/query-f218fc76780ca39d146674eae4bab7707bedc41d641545d8ea96df69ee5a36e9.json new file mode 100644 index 000000000..67a7a2c4f --- /dev/null +++ b/.sqlx/query-f218fc76780ca39d146674eae4bab7707bedc41d641545d8ea96df69ee5a36e9.json @@ -0,0 +1,56 @@ +{ + "db_name": "PostgreSQL", + "query": "\n SELECT\n strategy_id,\n strategy_name,\n strategy_type,\n parameters,\n status,\n created_at,\n updated_at\n FROM strategy_configs\n ORDER BY created_at DESC\n ", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "strategy_id", + "type_info": "Uuid" + }, + { + "ordinal": 1, + "name": "strategy_name", + "type_info": "Text" + }, + { + "ordinal": 2, + "name": "strategy_type", + "type_info": "Text" + }, + { + "ordinal": 3, + "name": "parameters", + "type_info": "Jsonb" + }, + { + "ordinal": 4, + "name": "status", + "type_info": "Text" + }, + { + "ordinal": 5, + "name": "created_at", + "type_info": "Timestamptz" + }, + { + "ordinal": 6, + "name": "updated_at", + "type_info": "Timestamptz" + } + ], + "parameters": { + "Left": [] + }, + "nullable": [ + false, + false, + false, + false, + false, + false, + false + ] + }, + "hash": "f218fc76780ca39d146674eae4bab7707bedc41d641545d8ea96df69ee5a36e9" +} diff --git a/.sqlx/query-f63e4cd5aff2bf33961383e53c5bfb559b5a3fcf75ee897e38ca024bdf1ce745.json b/.sqlx/query-f63e4cd5aff2bf33961383e53c5bfb559b5a3fcf75ee897e38ca024bdf1ce745.json new file mode 100644 index 000000000..3d240e86d --- /dev/null +++ b/.sqlx/query-f63e4cd5aff2bf33961383e53c5bfb559b5a3fcf75ee897e38ca024bdf1ce745.json @@ -0,0 +1,56 @@ +{ + "db_name": "PostgreSQL", + "query": "\n SELECT\n strategy_id,\n strategy_name,\n strategy_type,\n parameters,\n status,\n created_at,\n updated_at\n FROM strategy_configs\n WHERE status = 'Active'\n ORDER BY created_at DESC\n ", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "strategy_id", + "type_info": "Uuid" + }, + { + "ordinal": 1, + "name": "strategy_name", + "type_info": "Text" + }, + { + "ordinal": 2, + "name": "strategy_type", + "type_info": "Text" + }, + { + "ordinal": 3, + "name": "parameters", + "type_info": "Jsonb" + }, + { + "ordinal": 4, + "name": "status", + "type_info": "Text" + }, + { + "ordinal": 5, + "name": "created_at", + "type_info": "Timestamptz" + }, + { + "ordinal": 6, + "name": "updated_at", + "type_info": "Timestamptz" + } + ], + "parameters": { + "Left": [] + }, + "nullable": [ + false, + false, + false, + false, + false, + false, + false + ] + }, + "hash": "f63e4cd5aff2bf33961383e53c5bfb559b5a3fcf75ee897e38ca024bdf1ce745" +} diff --git a/.sqlx/query-f6e6de13c5202107e4d26e19af7a80dd5186eac2ac77e0a6cb7edd4ea0e792d3.json b/.sqlx/query-f6e6de13c5202107e4d26e19af7a80dd5186eac2ac77e0a6cb7edd4ea0e792d3.json new file mode 100644 index 000000000..db26ad734 --- /dev/null +++ b/.sqlx/query-f6e6de13c5202107e4d26e19af7a80dd5186eac2ac77e0a6cb7edd4ea0e792d3.json @@ -0,0 +1,25 @@ +{ + "db_name": "PostgreSQL", + "query": "\n INSERT INTO strategy_configs (strategy_name, strategy_type, parameters, status)\n VALUES ($1, $2, $3, $4)\n RETURNING strategy_id\n ", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "strategy_id", + "type_info": "Uuid" + } + ], + "parameters": { + "Left": [ + "Text", + "Text", + "Jsonb", + "Text" + ] + }, + "nullable": [ + false + ] + }, + "hash": "f6e6de13c5202107e4d26e19af7a80dd5186eac2ac77e0a6cb7edd4ea0e792d3" +} diff --git a/API_DOCUMENTATION.md b/API_DOCUMENTATION.md new file mode 100644 index 000000000..0c89205ac --- /dev/null +++ b/API_DOCUMENTATION.md @@ -0,0 +1,2601 @@ +# Foxhunt API Documentation + +**Version**: 1.0 +**Last Updated**: 2025-10-16 +**API Gateway**: `localhost:50051` +**Protocol**: gRPC with TLS/mTLS (RSA 4096-bit) + +--- + +## Table of Contents + +1. [Overview](#overview) +2. [Authentication & Authorization](#authentication--authorization) +3. [Rate Limiting](#rate-limiting) +4. [Error Handling](#error-handling) +5. [Service APIs](#service-apis) + - [Trading Service (7 methods)](#trading-service) + - [Trading Agent Service (18 methods)](#trading-agent-service) + - [ML Training Service (12 methods)](#ml-training-service) + - [Backtesting Service (6 methods)](#backtesting-service) + - [Risk Management Service (6 methods)](#risk-management-service) + - [Monitoring Service (10 methods)](#monitoring-service) + - [Configuration Service (4 methods)](#configuration-service) +6. [TLI Command Reference](#tli-command-reference) +7. [Common Data Types](#common-data-types) + +--- + +## Overview + +The Foxhunt HFT Trading System exposes **37 gRPC methods** across **7 microservices**, all accessible through a single API Gateway at port **50051**. The API Gateway provides: + +- **Authentication**: JWT + MFA (multi-factor authentication) +- **Rate Limiting**: Token bucket algorithm (100 req/sec default) +- **Audit Logging**: All requests logged to PostgreSQL +- **Request Routing**: Automatic service discovery and load balancing +- **TLS Encryption**: RSA 4096-bit certificates for all connections + +### Service Architecture + +``` +┌──────────────────────────────────────────────────────────────┐ +│ API Gateway (Port 50051) │ +│ Auth, Rate Limiting, Audit Logging, Routing │ +└──┬──────────────┬──────────────┬──────────────┬──────────────┘ + │ │ │ │ + ▼ ▼ ▼ ▼ +Trading Trading Agent ML Training Backtesting +Service Service Service Service +(50052) (50055) (50054) (50053) +``` + +--- + +## Authentication & Authorization + +### JWT Authentication + +All API requests require a valid JWT token in the `authorization` metadata header: + +``` +authorization: Bearer +``` + +### Obtaining a JWT Token (via TLI) + +```bash +# Login with username and password +tli auth login --username --password + +# MFA verification (if enabled) +tli auth verify-mfa --code <6-digit-code> + +# Token is automatically stored in ~/.config/foxhunt-tli/tokens/ +``` + +### Token Lifetime + +- **Access Token**: 1 hour (3600 seconds) +- **Refresh Token**: 7 days (604800 seconds) +- **MFA Grace Period**: 10 minutes after login + +### Required Permissions + +| Operation | Required Role | +|-----------|--------------| +| Submit Order | `TRADER`, `ADMIN` | +| Cancel Order | `TRADER`, `ADMIN` | +| Get Positions | `TRADER`, `VIEWER`, `ADMIN` | +| Emergency Stop | `ADMIN` only | +| Update Config | `ADMIN` only | +| View Metrics | `TRADER`, `VIEWER`, `ADMIN` | + +--- + +## Rate Limiting + +The API Gateway enforces rate limits using a token bucket algorithm: + +### Default Limits + +| Endpoint Type | Requests/Second | Burst Capacity | +|---------------|----------------|----------------| +| Trading Operations | 100 | 200 | +| Market Data Streams | 10 streams | 20 streams | +| Backtesting | 5 | 10 | +| ML Training | 2 | 5 | +| Configuration | 10 | 20 | + +### Rate Limit Headers + +Response headers indicate rate limit status: + +``` +X-RateLimit-Limit: 100 +X-RateLimit-Remaining: 87 +X-RateLimit-Reset: 1729123456 +``` + +### Rate Limit Exceeded Error + +```json +{ + "code": "RESOURCE_EXHAUSTED", + "message": "Rate limit exceeded: 100 requests/second", + "details": { + "retry_after_seconds": 1 + } +} +``` + +--- + +## Error Handling + +### gRPC Status Codes + +| gRPC Code | HTTP Equivalent | Description | +|-----------|----------------|-------------| +| `OK` (0) | 200 | Success | +| `INVALID_ARGUMENT` (3) | 400 | Invalid request parameters | +| `UNAUTHENTICATED` (16) | 401 | Missing or invalid JWT token | +| `PERMISSION_DENIED` (7) | 403 | Insufficient permissions | +| `NOT_FOUND` (5) | 404 | Resource not found | +| `ALREADY_EXISTS` (6) | 409 | Resource already exists | +| `RESOURCE_EXHAUSTED` (8) | 429 | Rate limit exceeded | +| `INTERNAL` (13) | 500 | Internal server error | +| `UNAVAILABLE` (14) | 503 | Service temporarily unavailable | + +### Error Response Format + +```protobuf +message ErrorResponse { + string code = 1; // gRPC status code name + string message = 2; // Human-readable error message + map details = 3; // Additional error context + int64 timestamp = 4; // Error timestamp (nanoseconds) +} +``` + +--- + +## Service APIs + +### Trading Service + +**Base Package**: `trading` +**Backend Port**: 50052 +**Total Methods**: 15 (12 core + 3 ML) + +#### Core Trading Operations + +##### 1. SubmitOrder + +Submit a new trading order with validation and risk checks. + +**Method**: `TradingService.SubmitOrder` + +**Request**: +```protobuf +message SubmitOrderRequest { + string symbol = 1; // Trading symbol (e.g., "AAPL", "BTC-USD", "ES.FUT") + OrderSide side = 2; // BUY or SELL + double quantity = 3; // Number of shares/units to trade + OrderType order_type = 4; // MARKET, LIMIT, STOP, STOP_LIMIT + optional double price = 5; // Limit price (required for LIMIT orders) + optional double stop_price = 6; // Stop price (required for STOP orders) + string account_id = 7; // Trading account identifier + map metadata = 8; // Additional order metadata (strategy, tags, etc.) +} +``` + +**Response**: +```protobuf +message SubmitOrderResponse { + string order_id = 1; // Unique order identifier + OrderStatus status = 2; // PENDING, SUBMITTED, etc. + string message = 3; // Status message or error description + int64 timestamp = 4; // Order submission timestamp (nanoseconds) +} +``` + +**TLI Command**: `tli trade submit --symbol --side --quantity --type ` + +**Example**: +```bash +tli trade submit --symbol ES.FUT --side BUY --quantity 10 --type MARKET +``` + +**Performance**: P99 latency ~15.96ms (target: <100ms) + +--- + +##### 2. CancelOrder + +Cancel an existing order by order ID. + +**Method**: `TradingService.CancelOrder` + +**Request**: +```protobuf +message CancelOrderRequest { + string order_id = 1; // Order ID to cancel + string account_id = 2; // Account ID for verification +} +``` + +**Response**: +```protobuf +message CancelOrderResponse { + bool success = 1; // True if cancellation was successful + string message = 2; // Success confirmation or error message + int64 timestamp = 3; // Cancellation timestamp (nanoseconds) +} +``` + +**TLI Command**: `tli trade cancel --order-id ` + +**Example**: +```bash +tli trade cancel --order-id "550e8400-e29b-41d4-a716-446655440000" +``` + +--- + +##### 3. GetOrderStatus + +Get current status of a specific order. + +**Method**: `TradingService.GetOrderStatus` + +**Request**: +```protobuf +message GetOrderStatusRequest { + string order_id = 1; // Order ID to query +} +``` + +**Response**: +```protobuf +message GetOrderStatusResponse { + Order order = 1; // Complete order details with current status +} +``` + +**TLI Command**: `tli trade status --order-id ` + +**Example**: +```bash +tli trade status --order-id "550e8400-e29b-41d4-a716-446655440000" +``` + +--- + +##### 4. StreamOrders + +Stream real-time order events for monitoring order lifecycle. + +**Method**: `TradingService.StreamOrders` (Server Streaming) + +**Request**: +```protobuf +message StreamOrdersRequest { + optional string account_id = 1; // Filter by account (all accounts if not specified) + optional string symbol = 2; // Filter by symbol (all symbols if not specified) +} +``` + +**Response Stream**: +```protobuf +message OrderEvent { + string order_id = 1; // Order identifier + Order order = 2; // Complete order details + OrderEventType event_type = 3; // CREATED, UPDATED, FILLED, CANCELLED, etc. + int64 timestamp = 4; // Event timestamp (nanoseconds) + string message = 5; // Event message or additional details +} +``` + +**TLI Command**: `tli trade stream --type orders [--symbol ]` + +--- + +##### 5. GetPositions + +Get current positions for account and/or symbol. + +**Method**: `TradingService.GetPositions` + +**Request**: +```protobuf +message GetPositionsRequest { + optional string account_id = 1; // Filter by account (all accounts if not specified) + optional string symbol = 2; // Filter by symbol (all symbols if not specified) +} +``` + +**Response**: +```protobuf +message GetPositionsResponse { + repeated Position positions = 1; // List of current positions +} +``` + +**TLI Command**: `tli trade positions [--symbol ]` + +**Example**: +```bash +tli trade positions --symbol ES.FUT +``` + +--- + +##### 6. StreamPositions + +Stream real-time position updates as trades execute. + +**Method**: `TradingService.StreamPositions` (Server Streaming) + +**Request**: +```protobuf +message StreamPositionsRequest { + optional string account_id = 1; // Filter by account (all accounts if not specified) +} +``` + +**Response Stream**: +```protobuf +message PositionEvent { + string symbol = 1; // Trading symbol + Position position = 2; // Updated position details + PositionEventType event_type = 3; // OPENED, UPDATED, CLOSED + int64 timestamp = 4; // Event timestamp (nanoseconds) + double quantity = 5; // Position quantity (quick access) + double average_price = 6; // Average entry price (quick access) + double unrealized_pnl = 7; // Unrealized P&L (quick access) +} +``` + +**TLI Command**: `tli trade stream --type positions` + +--- + +##### 7. GetPortfolioSummary + +Get comprehensive portfolio summary with P&L and risk metrics. + +**Method**: `TradingService.GetPortfolioSummary` + +**Request**: +```protobuf +message GetPortfolioSummaryRequest { + string account_id = 1; // Account ID for portfolio summary +} +``` + +**Response**: +```protobuf +message GetPortfolioSummaryResponse { + double total_value = 1; // Total portfolio value in USD + double unrealized_pnl = 2; // Unrealized profit/loss + double realized_pnl = 3; // Realized profit/loss for the day + double day_pnl = 4; // Total P&L for the current trading day + double buying_power = 5; // Available buying power + double margin_used = 6; // Amount of margin currently used + repeated Position positions = 7; // Detailed position information +} +``` + +**TLI Command**: `tli trade portfolio` + +--- + +#### Market Data Operations + +##### 8. StreamMarketData + +Stream real-time market data (trades, quotes, order book). + +**Method**: `TradingService.StreamMarketData` (Server Streaming) + +**Request**: +```protobuf +message StreamMarketDataRequest { + repeated string symbols = 1; // List of symbols to subscribe to + repeated MarketDataType data_types = 2; // TRADE, QUOTE, ORDER_BOOK +} +``` + +**Response Stream**: +```protobuf +message MarketDataEvent { + string symbol = 1; // Trading symbol + MarketDataType data_type = 2; // Type of market data + oneof data { + Trade trade = 3; // Trade data (when data_type = TRADE) + Quote quote = 4; // Quote data (when data_type = QUOTE) + OrderBook order_book = 5; // Order book data (when data_type = ORDER_BOOK) + } + int64 timestamp = 6; // Market data timestamp (nanoseconds) +} +``` + +**TLI Command**: `tli market stream --symbols --types ` + +--- + +##### 9. GetOrderBook + +Get current order book snapshot for a symbol. + +**Method**: `TradingService.GetOrderBook` + +**Request**: +```protobuf +message GetOrderBookRequest { + string symbol = 1; // Symbol to get order book for + optional int32 depth = 2; // Number of price levels (default: full book) +} +``` + +**Response**: +```protobuf +message GetOrderBookResponse { + OrderBook order_book = 1; // Current order book snapshot +} +``` + +**TLI Command**: `tli market book --symbol [--depth ]` + +--- + +#### Execution Operations + +##### 10. StreamExecutions + +Stream real-time trade executions as they occur. + +**Method**: `TradingService.StreamExecutions` (Server Streaming) + +**Request**: +```protobuf +message StreamExecutionsRequest { + optional string account_id = 1; // Filter by account (all accounts if not specified) + optional string symbol = 2; // Filter by symbol (all symbols if not specified) +} +``` + +**Response Stream**: +```protobuf +message ExecutionEvent { + string execution_id = 1; // Execution identifier + Execution execution = 2; // Execution details + int64 timestamp = 3; // Event timestamp (nanoseconds) + string order_id = 4; // Associated order ID (quick access) + string symbol = 5; // Trading symbol (quick access) + double quantity = 6; // Executed quantity (quick access) + double price = 7; // Execution price (quick access) +} +``` + +**TLI Command**: `tli trade stream --type executions` + +--- + +##### 11. GetExecutionHistory + +Get historical execution data with filtering options. + +**Method**: `TradingService.GetExecutionHistory` + +**Request**: +```protobuf +message GetExecutionHistoryRequest { + optional string account_id = 1; // Filter by account (all accounts if not specified) + optional string symbol = 2; // Filter by symbol (all symbols if not specified) + optional int64 start_time = 3; // Start time for query (nanoseconds) + optional int64 end_time = 4; // End time for query (nanoseconds) + optional int32 limit = 5; // Maximum number of executions to return +} +``` + +**Response**: +```protobuf +message GetExecutionHistoryResponse { + repeated Execution executions = 1; // List of historical executions +} +``` + +**TLI Command**: `tli trade history [--symbol ] [--limit ]` + +--- + +#### ML Trading Operations + +##### 12. SubmitMLOrder + +Submit ML-generated trading order with ensemble predictions. + +**Method**: `TradingService.SubmitMLOrder` + +**Request**: +```protobuf +message MLOrderRequest { + string symbol = 1; // Trading symbol (e.g., "ES.FUT") + string account_id = 2; // Trading account identifier + bool use_ensemble = 3; // Use ensemble voting or specific model + optional string model_name = 4; // Specific model name if not using ensemble + repeated double features = 5; // Feature vector for ML prediction (26 features: OHLCV + technicals) +} +``` + +**Response**: +```protobuf +message MLOrderResponse { + string order_id = 1; // Order ID if executed + string prediction_id = 2; // Prediction ID from ensemble_predictions table + string action = 3; // Action taken: BUY, SELL, HOLD + double confidence = 4; // Prediction confidence (0.0-1.0) + string message = 5; // Status message + bool executed = 6; // True if order was executed +} +``` + +**TLI Command**: `tli trade ml submit --symbol [--model ]` + +**Example**: +```bash +# Submit ensemble ML order +tli trade ml submit --symbol ES.FUT + +# Submit order using specific model +tli trade ml submit --symbol ES.FUT --model DQN +``` + +**Performance**: Inference latency ~200μs (DQN), ~500μs (MAMBA-2) + +--- + +##### 13. GetMLPredictions + +Get ML prediction history with outcomes. + +**Method**: `TradingService.GetMLPredictions` + +**Request**: +```protobuf +message MLPredictionsRequest { + string symbol = 1; // Trading symbol to filter by + optional string model_name = 2; // Filter by specific model + int32 limit = 3; // Maximum predictions to return (default: 100) + optional int64 start_time = 4; // Start time filter (nanoseconds) + optional int64 end_time = 5; // End time filter (nanoseconds) +} +``` + +**Response**: +```protobuf +message MLPredictionsResponse { + repeated MLPrediction predictions = 1; // List of predictions with outcomes +} +``` + +**TLI Command**: `tli trade ml predictions --symbol [--model ] [--limit ]` + +**Example**: +```bash +tli trade ml predictions --symbol ES.FUT --limit 50 +``` + +--- + +##### 14. GetMLPerformance + +Get ML model performance metrics. + +**Method**: `TradingService.GetMLPerformance` + +**Request**: +```protobuf +message MLPerformanceRequest { + optional string model_name = 1; // Filter by specific model (or all if not specified) + optional int64 start_time = 2; // Start time for metrics (nanoseconds) + optional int64 end_time = 3; // End time for metrics (nanoseconds) +} +``` + +**Response**: +```protobuf +message MLPerformanceResponse { + repeated ModelPerformance models = 1; // Performance metrics per model +} +``` + +**TLI Command**: `tli trade ml performance [--model ]` + +**Example**: +```bash +# Get all model performance +tli trade ml performance + +# Get specific model performance +tli trade ml performance --model MAMBA2 +``` + +--- + +### Trading Agent Service + +**Base Package**: `trading_agent` +**Backend Port**: 50055 +**Total Methods**: 18 + +The Trading Agent Service orchestrates portfolio management decisions through universe selection, asset ranking, capital allocation, and order generation. + +#### Universe Management + +##### 1. SelectUniverse + +Select tradable universe based on liquidity, volatility, and ML signals. + +**Method**: `TradingAgentService.SelectUniverse` + +**Request**: +```protobuf +message SelectUniverseRequest { + UniverseCriteria criteria = 1; // Selection criteria + optional uint32 max_instruments = 2; // Maximum instruments in universe + bool force_refresh = 3; // Force recalculation +} +``` + +**Response**: +```protobuf +message SelectUniverseResponse { + repeated Instrument instruments = 1; // Selected instruments + UniverseMetrics metrics = 2; // Universe quality metrics + int64 timestamp = 3; // Selection timestamp (nanoseconds) + string universe_id = 4; // Unique universe identifier +} +``` + +**TLI Command**: `tli agent universe select [--max-instruments ]` + +**Performance**: <1s (target met) + +--- + +##### 2. GetUniverse + +Get current trading universe configuration. + +**Method**: `TradingAgentService.GetUniverse` + +**Request**: +```protobuf +message GetUniverseRequest { + optional string universe_id = 1; // Get specific universe, or current if not specified +} +``` + +**Response**: +```protobuf +message GetUniverseResponse { + string universe_id = 1; + repeated Instrument instruments = 2; + UniverseCriteria criteria = 3; + UniverseMetrics metrics = 4; + int64 created_at = 5; + int64 updated_at = 6; +} +``` + +**TLI Command**: `tli agent universe show` + +--- + +##### 3. UpdateUniverseCriteria + +Update universe selection criteria. + +**Method**: `TradingAgentService.UpdateUniverseCriteria` + +**Request**: +```protobuf +message UpdateUniverseCriteriaRequest { + UniverseCriteria criteria = 1; +} +``` + +**Response**: +```protobuf +message UpdateUniverseCriteriaResponse { + bool success = 1; + string message = 2; + string universe_id = 3; // New universe ID after update +} +``` + +**TLI Command**: `tli agent universe update --min-liquidity --min-volatility ` + +--- + +#### Asset Selection + +##### 4. SelectAssets + +Select specific assets to trade within universe using ML-driven ranking. + +**Method**: `TradingAgentService.SelectAssets` + +**Request**: +```protobuf +message SelectAssetsRequest { + string universe_id = 1; // Universe to select from + AssetSelectionCriteria criteria = 2; // Selection criteria + uint32 max_assets = 3; // Maximum assets to select +} +``` + +**Response**: +```protobuf +message SelectAssetsResponse { + repeated AssetScore assets = 1; // Selected assets with scores + SelectionMetrics metrics = 2; // Selection quality metrics + int64 timestamp = 3; +} +``` + +**TLI Command**: `tli agent assets select --max-assets ` + +**Performance**: <2s (target met) + +**Multi-Factor Scoring**: +- ML Score: 40% weight +- Momentum Score: 30% weight +- Value Score: 20% weight +- Liquidity Score: 10% weight + +--- + +##### 5. GetSelectedAssets + +Get current asset selection with scores. + +**Method**: `TradingAgentService.GetSelectedAssets` + +**Request**: +```protobuf +message GetSelectedAssetsRequest { + optional string universe_id = 1; +} +``` + +**Response**: +```protobuf +message GetSelectedAssetsResponse { + repeated AssetScore assets = 1; + SelectionMetrics metrics = 2; + int64 timestamp = 3; +} +``` + +**TLI Command**: `tli agent assets show` + +--- + +#### Portfolio Allocation + +##### 6. AllocatePortfolio + +Allocate capital across selected assets using one of 5 strategies. + +**Method**: `TradingAgentService.AllocatePortfolio` + +**Request**: +```protobuf +message AllocatePortfolioRequest { + repeated AssetScore assets = 1; // Assets to allocate across + AllocationStrategy strategy = 2; // EQUAL_WEIGHT, RISK_PARITY, MEAN_VARIANCE, ML_OPTIMIZED, KELLY + RiskConstraints risk_constraints = 3; // Risk limits + double total_capital = 4; // Total capital to allocate +} +``` + +**Response**: +```protobuf +message AllocatePortfolioResponse { + repeated AssetAllocation allocations = 1; // Allocation per asset + AllocationMetrics metrics = 2; // Allocation quality metrics + int64 timestamp = 3; + string allocation_id = 4; +} +``` + +**TLI Command**: `tli agent allocate --strategy --capital ` + +**Performance**: <500ms (target met) + +**Supported Allocation Strategies**: +1. **Equal Weight**: 1/N allocation +2. **Risk Parity**: Equal risk contribution per asset +3. **Mean-Variance**: Markowitz optimization +4. **ML-Optimized**: ML model-driven allocation +5. **Kelly Criterion**: Optimal bet sizing + +--- + +##### 7. GetAllocation + +Get current portfolio allocation. + +**Method**: `TradingAgentService.GetAllocation` + +**Request**: +```protobuf +message GetAllocationRequest { + optional string allocation_id = 1; // Get specific allocation, or current if not specified +} +``` + +**Response**: +```protobuf +message GetAllocationResponse { + string allocation_id = 1; + repeated AssetAllocation allocations = 2; + AllocationMetrics metrics = 3; + int64 created_at = 4; + double total_capital = 5; +} +``` + +**TLI Command**: `tli agent allocate show` + +--- + +##### 8. RebalancePortfolio + +Rebalance portfolio based on target allocation. + +**Method**: `TradingAgentService.RebalancePortfolio` + +**Request**: +```protobuf +message RebalancePortfolioRequest { + string allocation_id = 1; // Target allocation + double rebalance_threshold = 2; // Min deviation to trigger rebalance (%) + bool force_rebalance = 3; // Force rebalance regardless of threshold +} +``` + +**Response**: +```protobuf +message RebalancePortfolioResponse { + repeated RebalanceAction actions = 1; // Required rebalancing actions + RebalanceMetrics metrics = 2; + bool rebalance_required = 3; + int64 timestamp = 4; +} +``` + +**TLI Command**: `tli agent rebalance [--threshold ] [--force]` + +--- + +#### Order Generation + +##### 9. GenerateOrders + +Generate orders based on allocation and ML signals. + +**Method**: `TradingAgentService.GenerateOrders` + +**Request**: +```protobuf +message GenerateOrdersRequest { + string allocation_id = 1; // Target allocation + repeated MLSignal ml_signals = 2; // ML predictions for timing + OrderGenerationStrategy strategy = 3; // Order generation algorithm +} +``` + +**Response**: +```protobuf +message GenerateOrdersResponse { + repeated GeneratedOrder orders = 1; // Generated order instructions + OrderGenerationMetrics metrics = 2; + int64 timestamp = 3; + string order_batch_id = 4; +} +``` + +**TLI Command**: `tli agent orders generate` + +--- + +##### 10. SubmitAgentOrders + +Submit generated orders to Trading Service. + +**Method**: `TradingAgentService.SubmitAgentOrders` + +**Request**: +```protobuf +message SubmitAgentOrdersRequest { + string order_batch_id = 1; // Batch ID from GenerateOrders + repeated GeneratedOrder orders = 2; // Orders to submit + bool dry_run = 3; // Test without actual submission +} +``` + +**Response**: +```protobuf +message SubmitAgentOrdersResponse { + repeated OrderSubmissionResult results = 1; // Submission results per order + OrderSubmissionMetrics metrics = 2; + int64 timestamp = 3; +} +``` + +**TLI Command**: `tli agent orders submit --batch-id [--dry-run]` + +--- + +#### Strategy Coordination + +##### 11. RegisterStrategy + +Register a trading strategy with the agent. + +**Method**: `TradingAgentService.RegisterStrategy` + +**Request**: +```protobuf +message RegisterStrategyRequest { + string strategy_name = 1; // Unique strategy name + StrategyType strategy_type = 2; // ML_ENSEMBLE, MEAN_REVERSION, MOMENTUM, ARBITRAGE, MARKET_MAKING + StrategyConfig config = 3; // Strategy configuration + bool auto_enable = 4; // Enable immediately after registration +} +``` + +**Response**: +```protobuf +message RegisterStrategyResponse { + bool success = 1; + string strategy_id = 2; + string message = 3; +} +``` + +**TLI Command**: `tli agent strategy register --name --type ` + +--- + +##### 12. ListStrategies + +Get list of active strategies. + +**Method**: `TradingAgentService.ListStrategies` + +**Request**: +```protobuf +message ListStrategiesRequest { + optional StrategyStatus status_filter = 1; // ENABLED, DISABLED, PAUSED, ERROR +} +``` + +**Response**: +```protobuf +message ListStrategiesResponse { + repeated Strategy strategies = 1; +} +``` + +**TLI Command**: `tli agent strategy list [--status ]` + +--- + +##### 13. UpdateStrategyStatus + +Enable/disable a strategy. + +**Method**: `TradingAgentService.UpdateStrategyStatus` + +**Request**: +```protobuf +message UpdateStrategyStatusRequest { + string strategy_id = 1; + StrategyStatus new_status = 2; // ENABLED, DISABLED, PAUSED + optional string reason = 3; +} +``` + +**Response**: +```protobuf +message UpdateStrategyStatusResponse { + bool success = 1; + string message = 2; + Strategy updated_strategy = 3; +} +``` + +**TLI Command**: `tli agent strategy update --id --status ` + +--- + +#### Agent Monitoring + +##### 14. GetAgentStatus + +Get comprehensive agent status and performance. + +**Method**: `TradingAgentService.GetAgentStatus` + +**Request**: +```protobuf +message GetAgentStatusRequest { + bool include_performance = 1; // Include performance metrics + bool include_positions = 2; // Include current positions +} +``` + +**Response**: +```protobuf +message GetAgentStatusResponse { + AgentStatus status = 1; + optional AgentPerformanceMetrics performance = 2; + optional PositionSummary positions = 3; + int64 timestamp = 4; +} +``` + +**TLI Command**: `tli agent status [--with-performance] [--with-positions]` + +--- + +##### 15. StreamAgentActivity + +Stream real-time agent decisions and actions. + +**Method**: `TradingAgentService.StreamAgentActivity` (Server Streaming) + +**Request**: +```protobuf +message StreamAgentActivityRequest { + repeated ActivityType activity_types = 1; // UNIVERSE_SELECTION, ASSET_SELECTION, ALLOCATION, ORDER_GENERATION, STRATEGY +} +``` + +**Response Stream**: +```protobuf +message AgentActivityEvent { + ActivityType activity_type = 1; + oneof event { + UniverseSelectionEvent universe_event = 2; + AssetSelectionEvent asset_event = 3; + AllocationEvent allocation_event = 4; + OrderGenerationEvent order_event = 5; + StrategyEvent strategy_event = 6; + } + int64 timestamp = 7; +} +``` + +**TLI Command**: `tli agent stream [--types ]` + +--- + +##### 16. GetAgentPerformance + +Get agent performance metrics. + +**Method**: `TradingAgentService.GetAgentPerformance` + +**Request**: +```protobuf +message GetAgentPerformanceRequest { + optional int64 start_time = 1; // Performance window start (nanoseconds) + optional int64 end_time = 2; // Performance window end (nanoseconds) + bool include_strategy_breakdown = 3; // Include per-strategy performance +} +``` + +**Response**: +```protobuf +message GetAgentPerformanceResponse { + AgentPerformanceMetrics metrics = 1; + repeated StrategyPerformance strategy_performance = 2; + int64 timestamp = 3; +} +``` + +**TLI Command**: `tli agent performance [--start