Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[workspace]
resolver = "2"
members = ["crates/standx-sdk", "crates/standx-cli"]
members = ["crates/standx-sdk", "crates/standx-maker", "crates/standx-cli"]

[workspace.package]
edition = "2021"
Expand Down
1 change: 1 addition & 0 deletions crates/standx-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ path = "src/main.rs"

[dependencies]
standx-sdk = { path = "../standx-sdk", version = "0.1.0", features = ["tabled"] }
standx-maker = { path = "../standx-maker", version = "0.1.0" }

# CLI
clap = { version = "4.5", features = ["derive", "env", "cargo"] }
Expand Down
13 changes: 7 additions & 6 deletions crates/standx-cli/src/commands/maker/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use super::{
};
use crate::cli::*;
use anyhow::Result;
use standx_maker::{self as maker, MakerConfig, MakerStats, RestingQuote, VolBreaker};
use standx_sdk::client::order::CreateOrderParams;
use standx_sdk::client::StandXClient;
use standx_sdk::models::{OrderSide, OrderType, TimeInForce, Trade};
Expand All @@ -19,7 +20,7 @@ use std::time::Duration;
pub(super) async fn maker_cycle(
client: &StandXClient,
symbol: &str,
cfg: &standx_sdk::maker::MakerConfig,
cfg: &MakerConfig,
live: bool,
cycle: u64,
mark: f64,
Expand All @@ -28,20 +29,20 @@ pub(super) async fn maker_cycle(
max_divergence_bps: f64,
inventory_exit_pct: f64,
inventory_exit_qty: f64,
resting: &mut Vec<standx_sdk::maker::RestingQuote>,
resting: &mut Vec<RestingQuote>,
adopted: &mut HashMap<String, (u32, f64, u64)>,
pending: &mut Vec<PendingPlace>,
inventory_exit_pending: &mut bool,
maker_order_ids: &mut HashSet<u64>,
seen_fill_ids: &mut HashSet<u64>,
session_started_at: i64,
sim_position: &mut f64,
stats: &mut standx_sdk::maker::MakerStats,
breaker: &mut standx_sdk::maker::VolBreaker,
stats: &mut MakerStats,
breaker: &mut VolBreaker,
output_format: OutputFormat,
order_response_health: Option<&AtomicBool>,
) -> Result<(u64, u64, u64, u64)> {
use standx_sdk::maker::{
use maker::{
cap_desired_exposure, compute_desired_quotes, format_decimals, mark_mid_divergence_bps,
paper_quote_filled, reconcile, skew_center, Action, RestingQuote,
};
Expand Down Expand Up @@ -248,7 +249,7 @@ pub(super) async fn maker_cycle(
// an empty desired set makes reconcile cancel every resting quote
// (pull all liquidity) and place none until volatility subsides.
let raw_inventory_exit = if live {
standx_sdk::maker::inventory_exit_plan(
maker::inventory_exit_plan(
position,
cfg.max_position,
inventory_exit_pct,
Expand Down
12 changes: 7 additions & 5 deletions crates/standx-cli/src/commands/maker/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use crate::cli::*;
use anyhow::Result;
use standx_maker::{
self as maker, Alert, AlertMonitor, MakerConfig, MakerStats, RestingQuote, VolBreaker,
};
use standx_sdk::auth::Credentials;
use standx_sdk::client::StandXClient;
use standx_sdk::error::Error as StandxError;
Expand Down Expand Up @@ -224,7 +227,7 @@ async fn notify_lifecycle(

#[allow(clippy::too_many_arguments)]
fn deliver_alert(
alert: &standx_sdk::maker::Alert,
alert: &Alert,
symbol: &str,
output_format: OutputFormat,
http: Option<&reqwest::Client>,
Expand Down Expand Up @@ -353,7 +356,6 @@ struct MakerRunArgs {
}

async fn run_maker(symbol: String, args: MakerRunArgs, output_format: OutputFormat) -> Result<()> {
use standx_sdk::maker::{self, MakerConfig, RestingQuote};
use standx_sdk::order_response::OrderResponseStream;

let order_session_id = args.live.then(|| uuid::Uuid::new_v4().to_string());
Expand Down Expand Up @@ -621,10 +623,10 @@ async fn run_maker(symbol: String, args: MakerRunArgs, output_format: OutputForm
let mut total_fills: u64 = 0;
let mut total_halted: u64 = 0;
let mut sim_position: f64 = 0.0; // paper-mode simulated inventory
let mut stats = maker::MakerStats::default();
let mut breaker = maker::VolBreaker::new(args.vol_window.max(1) as usize, args.vol_pause_bps);
let mut stats = MakerStats::default();
let mut breaker = VolBreaker::new(args.vol_window.max(1) as usize, args.vol_pause_bps);
let mut alerts =
maker::AlertMonitor::new(args.alert_loss, args.alert_inventory_pct, args.alert_uptime);
AlertMonitor::new(args.alert_loss, args.alert_inventory_pct, args.alert_uptime);
let mut last_mark: Option<f64> = None;
let mut last_src: Option<&'static str> = None;

Expand Down
11 changes: 6 additions & 5 deletions crates/standx-cli/src/commands/maker/output.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::*;
use standx_maker::{self as maker, Action, MakerConfig, MakerStats};
use standx_sdk::models::OrderSide;

/// Per-cycle output: one human line + indented actions, or JSON lines.
Expand All @@ -12,15 +13,15 @@ pub(super) fn emit_maker_cycle(
best_bid: Option<f64>,
best_ask: Option<f64>,
position: f64,
actions: &[standx_sdk::maker::Action],
actions: &[Action],
// Paper-mode simulated fills this cycle: (side, price, qty). Empty in live.
fills: &[(OrderSide, f64, f64)],
stats: &standx_sdk::maker::MakerStats,
stats: &MakerStats,
// Some(vol_bps) when the volatility breaker halted quoting this cycle.
halt_vol_bps: Option<f64>,
cfg: &standx_sdk::maker::MakerConfig,
cfg: &MakerConfig,
) {
use standx_sdk::maker::{format_decimals, Action};
use maker::format_decimals;

let pnl = stats.pnl(position, mark);

Expand Down Expand Up @@ -241,7 +242,7 @@ pub(super) fn log_maker_event(
price_decimals: u32,
detail: &str,
) {
use standx_sdk::maker::format_decimals;
use maker::format_decimals;
match output_format {
OutputFormat::Json => {
println!(
Expand Down
12 changes: 12 additions & 0 deletions crates/standx-maker/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "standx-maker"
version = "0.1.0"
description = "Deterministic market-making strategy and risk engine for StandX"
edition.workspace = true
authors.workspace = true
license.workspace = true
repository.workspace = true
rust-version.workspace = true

[dependencies]
standx-sdk = { path = "../standx-sdk", version = "0.1.0" }
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
//! ad-hoc f64 math on the API's string values); if symbols with more than ~8
//! price decimals ever list, revisit with a decimal type.

use crate::models::OrderSide;
use standx_sdk::models::OrderSide;

/// Static per-run configuration (CLI args + symbol metadata).
#[derive(Debug, Clone)]
Expand Down
1 change: 0 additions & 1 deletion crates/standx-sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
pub mod auth;
pub mod client;
pub mod error;
pub mod maker;
pub mod models;
pub mod order_response;
pub mod websocket;
Expand Down
Loading