FastMM documentation
FastMM C++ API 0.14.0
Public headers, tier 1 and tier 2
Loading...
Searching...
No Matches
transfer.hpp
Go to the documentation of this file.
1#pragma once
2// An internal transfer: an amount of one asset moved between two accounts of the same exchange
3// (the accounts of a pool, core/account_pool.hpp), as a connector that can do it carries it out
4// (venues::Venue::transfer, VenueCaps::internal_transfer) and the pool treasury asks for it
5// (core/treasury.hpp). Control path only: these types allocate.
6//
7// A transfer is named by `client_id`, unique per transfer and never reused: the venue is asked for
8// it under that id, and its state is asked for by that id after a timeout or a restart, so a
9// transfer whose answer was lost is looked up instead of sent twice.
12
13#include <cstdint>
14#include <string>
15#include <string_view>
16
17namespace fastmm {
18
19enum class TransferState : std::uint8_t {
20 Pending = 0, // the venue took it and has not finished it
21 Done = 1, // the amount has moved
22 Failed = 2, // the venue refused it or gave up: nothing moved
23 NotFound = 3, // the venue has no transfer under this id (status only)
24 Unknown = 4, // no usable answer (a transport error, a timeout, a 5xx): it may have happened
25};
26[[nodiscard]] constexpr std::string_view to_string(TransferState s) noexcept {
27 switch (s) {
29 return "pending";
31 return "done";
33 return "failed";
35 return "not_found";
37 return "unknown";
38 }
39 return "?";
40}
41
42// What the treasury reports through TreasuryPort::record (journal) and its counters.
43enum class TreasuryEventKind : std::uint8_t {
44 Planned = 0, // dry run: what would have been sent
45 Sent = 1, // handed to the venue
46 Done = 2,
47 Failed = 3,
48 TimedOut = 4, // unresolved past timeout_ns; still asked for
49 Reserve = 5, // reserve = true: the engine is to hold the amount out of the payer's balance
50 Released = 6, // ... and give it back: nothing was sent
51 Request = 7, // a pool's transfer lane: the engine holds the amount and asks for the transfer
52};
53
54struct TransferRequest {
55 std::string client_id; // [0-9a-z], at most kMaxClientId characters
56 VenueId from; // the pool account the amount leaves
57 VenueId to; // the pool account it goes to
58 // The venue's names of the two accounts (Venue::transfer_account(): a Binance sub-account's
59 // email, empty for the master account). Filled in by whoever hands the request to the venue.
60 std::string from_account;
61 std::string to_account;
62 std::string asset;
64 std::int64_t created_ms = 0; // wall clock; a venue's history query starts here
66 static constexpr std::size_t kMaxClientId = 30;
67};
69struct TransferResult {
71 std::string venue_ref; // the venue's id of the transfer (Binance tranId), when it gave one
72 std::string detail; // the venue's error or a description of the failure, for the log
73 int code = 0; // the venue's error code (Binance -9000), 0 without one
74 int http_status = 0; // the HTTP status of the answer, 0 without one (429: slow down)
75};
77} // namespace fastmm
Fixed<Tag>: int64 fixed point with a global 1e-8 scale (ADR-0001).
Definition strategy.hpp:23
@ Pending
orders on their way: sent, not yet working, or a requote waiting its turn
TreasuryEventKind
What the treasury reports through TreasuryPort::record (journal) and its counters.
Definition transfer.hpp:45
@ Request
a pool's transfer lane: the engine holds the amount and asks for the transfer
@ Planned
dry run: what would have been sent
@ Reserve
reserve = true: the engine is to hold the amount out of the payer's balance
@ Sent
handed to the venue
@ Released
... and give it back: nothing was sent
@ TimedOut
[engine] flatten_timeout_ms elapsed with a position left; it gave up
constexpr std::string_view to_string(ParamType t) noexcept
Definition params.hpp:63
TransferState
Definition transfer.hpp:21
@ Pending
the venue took it and has not finished it
@ NotFound
the venue has no transfer under this id (status only)
@ Unknown
no usable answer (a transport error, a timeout, a 5xx): it may have happened
@ Failed
the venue refused it or gave up: nothing moved
@ Done
the amount has moved
Strongly typed identifiers.
std::string client_id
[0-9a-z], at most kMaxClientId characters
Definition transfer.hpp:57
std::string asset
Definition transfer.hpp:64
static constexpr std::size_t kMaxClientId
Definition transfer.hpp:68
VenueId from
the pool account the amount leaves
Definition transfer.hpp:58
std::string to_account
Definition transfer.hpp:63
std::int64_t created_ms
wall clock; a venue's history query starts here
Definition transfer.hpp:66
std::string from_account
The venue's names of the two accounts (Venue::transfer_account(): a Binance sub-account's email,...
Definition transfer.hpp:62
VenueId to
the pool account it goes to
Definition transfer.hpp:59
Notional amount
Definition transfer.hpp:65
Definition transfer.hpp:71
std::string venue_ref
the venue's id of the transfer (Binance tranId), when it gave one
Definition transfer.hpp:73
TransferState state
Definition transfer.hpp:72
std::string detail
the venue's error or a description of the failure, for the log
Definition transfer.hpp:74
int code
the venue's error code (Binance -9000), 0 without one
Definition transfer.hpp:75
int http_status
the HTTP status of the answer, 0 without one (429: slow down)
Definition transfer.hpp:76