Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔀 Add example for coinbase FIX50 market data access #14

Merged
merged 8 commits into from
Feb 16, 2024
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
15 changes: 12 additions & 3 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ resolver = "2"
members = [
"examples/coinbase-example",
"examples/coinbase-fix-utils",
"examples/coinbase-fix42",
"examples/coinbase-fix42-order-entry",
"examples/coinbase-fix50-market-data",
"examples/executor",
"examples/single-order-sender",
"quickfix-ffi",
Expand Down
2 changes: 1 addition & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Because it is the simplest one to setup and it has a sandbox to play with.
That is so simple. Just add following lines to your `Cargo.toml` file:

```toml
coinbase-fix42 = { git = "https://github.com/arthurlm/quickfix-rs.git" }
coinbase-fix42-order-entry = { git = "https://github.com/arthurlm/quickfix-rs.git" }
coinbase-fix-utils = { git = "https://github.com/arthurlm/quickfix-rs.git" }
quickfix = { git = "https://github.com/arthurlm/quickfix-rs.git" }
```
Expand Down
2 changes: 1 addition & 1 deletion examples/coinbase-example/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ publish = false

[dependencies]
anyhow = "1.0.79"
coinbase-fix42 = { path = "../coinbase-fix42", version = "0.1.0" }
coinbase-fix42-order-entry = { path = "../coinbase-fix42-order-entry", version = "0.1.0" }
coinbase-fix-utils = { path = "../coinbase-fix-utils", version = "0.1.0" }
quickfix = { path = "../../quickfix", version = "0.1.0" }
uuid = { version = "1.6.1", features = ["v4"] }
Expand Down
391 changes: 391 additions & 0 deletions examples/coinbase-example/data/market-data/FIX50-prod-sand.xml

Large diffs are not rendered by default.

299 changes: 299 additions & 0 deletions examples/coinbase-example/data/market-data/FIXT11-prod-sand.xml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{
};

use coinbase_example::*;
use coinbase_fix42::{
use coinbase_fix42_order_entry::{
field_types::{MsgType, OrdStatus, OrdType, SelfTradePrevention, Side, TimeInForce},
*,
};
Expand Down Expand Up @@ -174,7 +174,7 @@ fn main() -> anyhow::Result<()> {

// Send new order
let order = new_order(&my_app)?;
let session_id = my_app.config.session_id();
let session_id = my_app.config.order_entry_session_id();

println!(">> Sending order 💸");
send_to_target(order.into(), &session_id)?;
Expand Down
19 changes: 16 additions & 3 deletions examples/coinbase-example/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,29 @@ pub fn build_session_settings(config: &CoinbaseConfig) -> anyhow::Result<Session
params
})?;

settings.set(Some(&config.session_id()), {
settings.set(Some(&config.order_entry_session_id()), {
let mut params = Dictionary::new();
params.set("StartTime", "00:00:01")?;
params.set("EndTime", "23:59:59")?;
params.set("HeartBtInt", 30)?;
params.set("SocketConnectPort", 5298)?; // ⚠️ This port should match what you have in your stunnel configuration file.
params.set("SocketConnectHost", "127.0.0.1")?;
params.set("DataDictionary", "data/order-entry/FIX42-prod-sand.xml")?;
params
})?;

settings.set(Some(&config.market_data_session_id()), {
let mut params = Dictionary::new();
params.set("StartTime", "00:00:01")?;
params.set("EndTime", "23:59:59")?;
params.set("HeartBtInt", 30)?;
params.set("SocketConnectPort", 7221)?; // ⚠️ This port should match what you have in your stunnel configuration file.
params.set("SocketConnectHost", "127.0.0.1")?;
params.set("DefaultApplVerID", "9" /* FIX 5.0 SP2 */)?;
params.set("DataDictionary", "data/market-data/FIX50-prod-sand.xml")?;
params.set(
"DataDictionary",
"../coinbase-fix42/src/cb-FIX42-prod-sand.xml",
"TransportDataDictionary",
"data/market-data/FIXT11-prod-sand.xml",
)?;
params
})?;
Expand Down
3 changes: 2 additions & 1 deletion examples/coinbase-fix-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ publish = false

[dependencies]
base64 = "0.21.7"
coinbase-fix42 = { path = "../coinbase-fix42", version = "0.1.0" }
coinbase-fix42-order-entry = { path = "../coinbase-fix42-order-entry", version = "0.1.0" }
coinbase-fix50-market-data = { path = "../coinbase-fix50-market-data", version = "0.1.0" }
hmac = "0.12.1"
quickfix = { path = "../../quickfix", version = "0.1.0" }
sha2 = "0.10.8"
16 changes: 13 additions & 3 deletions examples/coinbase-fix-utils/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,22 @@ impl CoinbaseConfig {
}
}

pub fn session_id(&self) -> SessionId {
pub fn order_entry_session_id(&self) -> SessionId {
SessionId::try_new(
coinbase_fix42::FIX_BEGIN_STRING,
coinbase_fix42_order_entry::FIX_BEGIN_STRING,
&self.api_key,
"Coinbase",
"",
"order-entry",
)
.expect("Fail to build session ID")
}

pub fn market_data_session_id(&self) -> SessionId {
SessionId::try_new(
coinbase_fix50_market_data::FIX_BEGIN_STRING,
&self.api_key,
"Coinbase",
"market-data",
)
.expect("Fail to build session ID")
}
Expand Down
10 changes: 8 additions & 2 deletions examples/coinbase-fix-utils/src/logon_utils.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
use base64::{engine::general_purpose::STANDARD as BASE64, Engine as _};
use coinbase_fix42::{field_id, Logon};
use coinbase_fix42_order_entry::{
field_id::{self, PASSWORD},
Logon,
};
use coinbase_fix50_market_data::field_id::USERNAME;
use hmac::{Hmac, Mac};
use quickfix::*;
use sha2::Sha256;
Expand All @@ -8,7 +12,9 @@ use crate::config::CoinbaseConfig;

pub fn fill_message(msg: &mut Message, config: &CoinbaseConfig) -> Result<(), QuickFixError> {
// Set password
msg.set_field(field_id::PASSWORD, config.api_passphrase.as_str())
msg.set_field(USERNAME, "s.nakamoto")
.expect("Fail to set password");
msg.set_field(PASSWORD, config.api_passphrase.as_str())
.expect("Fail to set password");

Ok(())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "coinbase-fix42"
name = "coinbase-fix42-order-entry"
version = "0.1.3"
edition = "2021"
publish = false
Expand Down
11 changes: 11 additions & 0 deletions examples/coinbase-fix50-market-data/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "coinbase-fix50-market-data"
version = "0.1.0"
edition = "2021"
publish = false

[dependencies]
quickfix = { version = "0.1.3", path = "../../quickfix" }

[build-dependencies]
quickfix-msg-gen = { version = "0.1.3", path = "../../quickfix-msg-gen" }
12 changes: 12 additions & 0 deletions examples/coinbase-fix50-market-data/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use std::{env, io};

use quickfix_msg_gen::*;

const SPEC_FILENAME: &str = "src/cb-FIX50-prod-sand.xml";
const BEGIN_STRING: &str = "FIXT.1.1";

fn main() -> io::Result<()> {
let out_dir = env::var("OUT_DIR").expect("Missing OUT_DIR");
generate(SPEC_FILENAME, format!("{out_dir}/code.rs"), BEGIN_STRING)?;
Ok(())
}
Loading
Loading