Skip to content

Commit 1a0130a

Browse files
committed
_
1 parent 33f2088 commit 1a0130a

File tree

9 files changed

+37
-40
lines changed

9 files changed

+37
-40
lines changed

Cargo.lock

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
[<img alt="ci warnings" src="https://img.shields.io/github/actions/workflow/status/valeratrades/discretionary_engine/warnings.yml?branch=master&style=for-the-badge&style=flat-square&label=warnings&labelColor=d16002" height="20">](https://github.com/valeratrades/discretionary_engine/actions?query=branch%3Amaster) <!--NB: Won't find it if repo is private-->
99

1010
Places and follows a position from a definition of _what the target position is_
11-
If the broader architecture is of interest, see [ARCHITECTURE.md](./docs/ARCHITECTURE.md).
1211

1312
## Usage
1413
Example query:
@@ -45,7 +44,7 @@ An example config can be found in ./examples/config.toml
4544
<br>
4645

4746
<sup>
48-
This repository follows <a href="https://github.com/valeratrades/.github/tree/master/best_practices">my best practices</a> and <a href="https://github.com/tigerbeetle/tigerbeetle/blob/main/docs/TIGER_STYLE.md">Tiger Style</a> (except "proper capitalization for acronyms": (VsrState, not VSRState) and formatting).
47+
This repository follows <a href="https://github.com/valeratrades/.github/tree/master/best_practices">my best practices</a> and <a href="https://github.com/tigerbeetle/tigerbeetle/blob/main/docs/TIGER_STYLE.md">Tiger Style</a> (except "proper capitalization for acronyms": (VsrState, not VSRState) and formatting). For project's architecture, see <a href="./docs/ARCHITECTURE.md">ARCHITECTURE.md</a>.
4948
</sup>
5049

5150
#### License

discretionary_engine/build.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
use std::process::Command;
2-
31
fn main() {
2+
git_version();
3+
log_directives();
4+
}
5+
6+
fn git_version() {
47
// Embed git commit hash (fallback to "unknown" if git unavailable, e.g., in Nix sandbox)
5-
let git_hash = Command::new("git")
8+
let git_hash = std::process::Command::new("git")
69
.args(["rev-parse", "--short", "HEAD"])
710
.output()
811
.ok()
@@ -11,7 +14,9 @@ fn main() {
1114
.map(|s| s.trim().to_string())
1215
.unwrap_or_else(|| "unknown".to_string());
1316
println!("cargo:rustc-env=GIT_HASH={git_hash}");
17+
}
1418

19+
fn log_directives() {
1520
// Embed log directives if .cargo/log_directives exists
1621
println!("cargo:rerun-if-changed=.cargo/log_directives");
1722
if let Ok(directives) = std::fs::read_to_string(".cargo/log_directives") {

discretionary_engine_strategy/src/commands.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ use crate::{protocols::interpret_protocol_specs, redis_bus};
1010
pub struct SubmitArgs {
1111
pub size_usdt: f64,
1212
pub coin: String,
13-
pub acquisition_protocols: Vec<String>,
14-
pub followup_protocols: Vec<String>,
13+
pub protocols: Vec<String>,
1514
pub testnet: bool,
1615
}
1716

@@ -27,10 +26,7 @@ fn build_cli_string(args: &SubmitArgs) -> String {
2726
parts.push(format!("-s {}", args.size_usdt));
2827
parts.push(format!("-c {}", args.coin));
2928

30-
for proto in &args.acquisition_protocols {
31-
parts.push(format!("-a {}", proto));
32-
}
33-
for proto in &args.followup_protocols {
29+
for proto in &args.protocols {
3430
parts.push(format!("-f {}", proto));
3531
}
3632

@@ -40,8 +36,7 @@ fn build_cli_string(args: &SubmitArgs) -> String {
4036
/// Submit a position request via Redis.
4137
pub async fn submit(args: SubmitArgs, redis_port: u16) -> Result<()> {
4238
// Validate protocols first
43-
let _acquisition_protocols = interpret_protocol_specs(args.acquisition_protocols.clone()).wrap_err("Invalid acquisition protocols")?;
44-
let _followup_protocols = interpret_protocol_specs(args.followup_protocols.clone()).wrap_err("Invalid followup protocols")?;
39+
let _protocols = interpret_protocol_specs(args.protocols.clone()).wrap_err("Invalid acquisition protocols")?;
4540

4641
// Build CLI string and publish to Redis
4742
let cli_string = build_cli_string(&args);

discretionary_engine_strategy/src/config.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//! Strategy configuration.
2-
31
use v_utils::macros as v_macros;
42

53
fn __default_redis_port() -> u16 {

discretionary_engine_strategy/src/redis_bus.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub const CONSUMER_GROUP: &str = "strategy_consumers";
1414

1515
/// Connect to Redis asynchronously.
1616
pub async fn connect(port: u16) -> Result<MultiplexedConnection> {
17-
let url = format!("redis://127.0.0.1:{}/", port);
17+
let url = format!("redis://127.0.0.1:{port}/");
1818
let client = Client::open(url.as_str()).wrap_err("Failed to create Redis client")?;
1919
let conn = client.get_multiplexed_async_connection().await.wrap_err("Failed to connect to Redis")?;
2020
Ok(conn)
@@ -82,13 +82,13 @@ impl CommandSubscriber {
8282
for stream_key in reply.keys {
8383
for entry in stream_key.ids {
8484
let id = entry.id.clone();
85-
if let Some(cmd) = entry.map.get("cmd") {
86-
if let redis::Value::BulkString(bytes) = cmd {
87-
let cmd_str = String::from_utf8_lossy(bytes).to_string();
88-
// Acknowledge the message
89-
let _: () = self.conn.xack(STREAM_KEY, CONSUMER_GROUP, &[&id]).await?;
90-
return Ok(Some((id, cmd_str)));
91-
}
85+
if let Some(cmd) = entry.map.get("cmd")
86+
&& let redis::Value::BulkString(bytes) = cmd
87+
{
88+
let cmd_str = String::from_utf8_lossy(bytes).to_string();
89+
// Acknowledge the message
90+
let _: () = self.conn.xack(STREAM_KEY, CONSUMER_GROUP, &[&id]).await?;
91+
return Ok(Some((id, cmd_str)));
9292
}
9393
}
9494
}

discretionary_engine_strategy/src/start.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,12 @@ use crate::{
1212
strategy::PrintTradesStrategy,
1313
};
1414

15-
/// Start the strategy with Bybit data feed.
15+
/// Start the strategy with trade data feed.
1616
pub async fn start() -> Result<()> {
1717
// Create channel for trades (the bridge between data layer and strategy)
1818
let (trade_tx, trade_rx) = mpsc::unbounded_channel();
1919

20-
// Initialize exchange-specific data feed
21-
// This is the ONLY place where we mention Bybit
20+
// we ONLY talk about specifics in DataFeed initialization
2221
let config = BybitDataConfig::default();
2322
let data_handle = init_data(config, trade_tx).await?;
2423

flake.lock

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
rust-overlay.url = "github:oxalica/rust-overlay";
55
flake-utils.url = "github:numtide/flake-utils";
66
pre-commit-hooks.url = "github:cachix/git-hooks.nix";
7-
v-utils.url = "github:valeratrades/.github";
7+
v-utils.url = "github:valeratrades/.github?ref=v1.4";
88
};
99

1010
outputs = { self, nixpkgs, rust-overlay, flake-utils, pre-commit-hooks, v-utils, ... }:

0 commit comments

Comments
 (0)