Skip to content

Commit 9afb4d3

Browse files
committed
ci: naive tracey
1 parent e53aa42 commit 9afb4d3

File tree

6 files changed

+55
-2
lines changed

6 files changed

+55
-2
lines changed

.config/tracey/config.kdl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Protocol contract specification traceability
2+
// Run: `tracey matrix` to see coverage
3+
// Run: `tracey impact <rule>` to see what code implements a rule
4+
5+
spec {
6+
name "protocol"
7+
rules_file "../../docs/spec/_rules.json"
8+
include "discretionary_engine/**/*.rs"
9+
include "discretionary_engine_*/**/*.rs"
10+
exclude "**/target/**"
11+
exclude "**/libs/**"
12+
}

discretionary_engine/src/exchange_apis/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Individual exchange APIs expose methods and frameworks for interacting with their respective exchanges. At this level we have [hub.rs] and [all_exchanges.rs] which interpret the information passed up by the individual exchanges in the manner necessary for the task. [all_exchanges.rs] exposes information for Protocols and Positions, [hub.rs] uses it to construct the optimal execution strategy.
1+
//! Individual exchange APIs expose methods and frameworks for interacting with their respective exchanges. At this level we have `hub` and `exchanges` which interpret the information passed up by the individual exchanges in the manner necessary for the task. `exchanges` exposes information for Protocols and Positions, `hub` uses it to construct the optimal execution strategy.
22
33
pub mod binance;
44
pub mod exchanges;

discretionary_engine/src/positions.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ fn recalculate_protocol_orders(
318318
}
319319
}
320320

321+
// [impl protocol.orders.market-first]
321322
/// NB: Market-like orders MUST be ran first
322323
fn update_order_selection(extendable: &mut Vec<ConceptualOrder<ProtocolOrderId>>, incoming: &[ConceptualOrder<ProtocolOrderId>], left_to_target: &mut f64) {
323324
for order in incoming {

discretionary_engine/src/protocols/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,10 @@ pub struct RecalculateOrdersPerOrderInfo {
199199

200200
/// Wrapper around Orders, which allows for updating the target after a partial fill, without making a new request to the protocol.
201201
///
202-
/// NB: the protocol itself must internally uphold the equality of ids attached to orders to corresponding fields of ProtocolOrders, as well as to ensure that all possible orders the protocol can ether request are initialized in every ProtocolOrders instance it outputs.
202+
/// # Contract
203+
/// - [impl protocol.orders.id-stability]: Protocol must maintain stable order IDs - ordinal indices must remain constant
204+
/// - [impl protocol.orders.id-match]: ProtocolOrderId must match protocol signature and ordinal position
205+
/// - [impl protocol.orders.all-slots-initialized]: All possible orders must have slots, inactive ones as None
203206
#[derive(Clone, Debug, Default)]
204207
pub struct ProtocolOrders {
205208
pub protocol_id: String,
@@ -208,6 +211,7 @@ pub struct ProtocolOrders {
208211
impl ProtocolOrders {
209212
#[instrument(skip(orders))]
210213
pub fn new(protocol_id: String, orders: Vec<Option<ConceptualOrderPercents>>) -> Self {
214+
// [verify protocol.orders.all-slots-initialized]
211215
assert_ne!(
212216
orders.len(),
213217
0,

docs/spec/protocol.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Protocol System Specification
2+
3+
## Order Identity
4+
5+
r[protocol.orders.id-stability]
6+
7+
A protocol MUST maintain stable order IDs across its lifetime. The ordinal index in `ProtocolOrders.__orders` for a given logical order MUST remain constant across all updates.
8+
9+
r[protocol.orders.id-match]
10+
11+
The `ProtocolOrderId` attached to each order MUST match the protocol's signature and the order's ordinal position in the orders vector.
12+
13+
r[protocol.orders.all-slots-initialized]
14+
15+
A protocol MUST always send a `Vec<Option<ConceptualOrderPercents>>` with slots for ALL possible orders it may ever request. Orders not currently active MUST be represented as `None`, not omitted.
16+
17+
## Order Processing
18+
19+
r[protocol.orders.market-first]
20+
21+
When processing orders from protocols, market-like orders MUST be executed before other order types.

flake.nix

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,20 @@
4242
};
4343
};
4444
readme = v-utils.readme-fw { inherit pkgs pname; lastSupportedVersion = "nightly-1.92"; rootDir = ./.; licenses = [{ name = "Blue Oak 1.0.0"; outPath = "LICENSE"; }]; badges = [ "msrv" "crates_io" "docs_rs" "loc" "ci" ]; };
45+
46+
tracey = pkgs.rustPlatform.buildRustPackage {
47+
pname = "tracey";
48+
version = "1.0.0";
49+
src = pkgs.fetchFromGitHub {
50+
owner = "bearcove";
51+
repo = "tracey";
52+
rev = "71cfc9d4115612467b857c868a90cc6d90ed79f7";
53+
hash = "sha256-maVPj9/PZzZDEmtMjemeuOCctDrU3JXaBNDwjFTRpks=";
54+
};
55+
cargoHash = "sha256-pk9Ky+/5P88zAbSJKbUwyvLNFIlHJzwqQCEQrorjlk0=";
56+
cargoBuildFlags = [ "-p" "tracey" ];
57+
doCheck = false;
58+
};
4559
in
4660
{
4761
packages =
@@ -91,6 +105,7 @@
91105
openssl
92106
pkg-config
93107
rust
108+
tracey
94109
] ++ pre-commit-check.enabledPackages ++ github.enabledPackages;
95110
};
96111
}

0 commit comments

Comments
 (0)