Rust Types Derived from Proto Files
Context
This project contains protobuf models of financial objects & request/response formats for APIs; as well as language specific bindings.
Generating Types
To generate the types run cargo run --bin gen. This will overwrite the files in ledger-models-rust. Any new file must be exported in lib.rs.
This is included in the compile.sh script which creates types across all languages.
Project structure
Tonic/Prost is used to generate language bindings in Rust. Auto-generated files are created in the format fintekkers...rs.
Hand-written wrappers are included in the folder fintekkers/wrappers/file.rs. The purpose of this code is to make it easier to use the Rust implementation of fintekkers without having gitto understand all the nuance of protobufs, or nuances of performance optimizations made in the proto schema.
DevOps
Preparing Rust to publish
to publish a new version do the following
- generate the new protobus using the compile script
- export any new models in lib.rs
- bump the package version in
Cargo.toml - merge your pr then create a release tagged with the version, if the version = 0.1.1, set the tag to v0.1.1
Security metrics (LM-485)
Shares outstanding, NAV per share and total net assets of a security, read
and written through the SecurityMetric service in native types
(NaiveDate, rust_decimal::Decimal, Uuid). The service address is the
PRICE service's (BROKER_HOST wins, then PRICE_SERVICE_HOST /
PRICE_SERVICE_PORT, API_URL, localhost:8083); each call has a 30 second
deadline (with_timeout changes it).
Build a service with SecurityMetricService::from_env()? (or
from_env_with(lookup) for an injected environment) and pass it to the
_with methods. security.get_metric(..), security.shares_outstanding(..)
and the other shortcuts without _with use the process-wide
SecurityMetricService::default_instance(). Only the security's UUID is
used: a link-mode security is never hydrated.
A value that is not known is None, never 0. on and to default to today.
In the example, service, spy_uuid and qqq_uuid are already defined.
use NaiveDate;
use ;
use ;
use dec;
let monday = from_ymd_opt.ok_or?;
let spy = new;
// The latest value on or before a date: Friday's point, 3 days old.
if let Some = spy.get_metric_with.await?
// The same through a shortcut.
let shares = spy.metrics_with.shares_outstanding.await?;
// Many securities in one call: every UUID is a key, unknown ones are None.
let latest = service.get.await?;
assert!;
// Every point in a range, ascending; gaps stay gaps.
let from = from_ymd_opt.ok_or?;
let history = spy.metrics_with.shares_outstanding_history.await?;
for point in &history.points
// Write points: checked first (whole share counts, no duplicate dates),
// then sent in chunks. Returns the as_of the server stamped.
let as_of = service.record.await?;
println!;