Skip to main content

Module index

Module index 

Source
Expand description

Client order id <-> Finam order id.

Finam cancels and reads orders by its own order_id, while the library API speaks cid. This index remembers the pairs seen in this process (placed here, echoed by streams, listed by GetOrders) and resolves the cid of any order echo.

The index lives in memory. After a restart it is empty and fills again from reconcile and from the comments of order echoes, which carry the cid in a form that survives restarts (see FinamCidCodec).

§Examples

use brokapi_core::{CidCodec, ClientOrderId};
use brokapi_finam::FinamCidCodec;
use brokapi_finam::index::{OrderIndex, foreign_cid};

let index = OrderIndex::new();
let cid = ClientOrderId::new_v4();

// We placed an order: remember the pair when the broker answers with its id.
index.bind(cid, "ORD-1");
assert_eq!(index.order_id(cid).as_deref(), Some("ORD-1"));

// An echo whose comment carries our cid resolves to it.
let comment = FinamCidCodec.encode(cid).unwrap();
assert_eq!(index.resolve("ORD-1", "", comment.as_str()), cid);

// An order placed by someone else gets a stable made-up cid, and `lookup` says it is not ours.
assert_eq!(index.lookup("ORD-2", "set by hand"), None);
assert_eq!(index.resolve("ORD-2", "", "set by hand"), foreign_cid("ORD-2"));

Structs§

OrderIndex
Memory of which Finam order id belongs to which client order id.

Functions§

foreign_cid
Stable cid for an order that is not ours.