-
Notifications
You must be signed in to change notification settings - Fork 166
Schema Glossary
Amount
is used to represent all numbers for prices and volumes. If the Amount
relates to a specific Market
, then it will be a DiscreteAmount
which can only take on values which are multiples of the Market
's price or volume basis (see DiscreteAmount
.) Amount
s which are not tied to a Market
, Currency
, or other object which has a discrete basis are represented by DecimalAmount
s, which uses 128-bit decimal accounting. Any operations on an Amount
which may result in rounding or remainders are required to supply a RemainderHandler
which controls rounding modes and handles any remainders after the operation is performed.
An Account
represents external accounting: an Account
is held with an Exchange
differs from a Fund
in a couple ways: Account
s do not have an Owner
, and they are reconciled 1-for-1 against external records (account data gathered from XChange). Account
s generally relate to balances on exchanges, but there may be Account
s attached to Exchanges.SELF
, meaning the account is internal to this organization.
The common OHLC or open/high/low/close for a standard duration of time like one minute. These can be generated from Trade
s or Tick
s and are not collected from data providers.
All the Bid
s and Ask
s for a Market
at a given point in time. Book
s are one of the two main types of MarketData
we collect, the other being Trade
s.
This is the main hub of Coin Trader. A Context
has an Esper
instance, and it also provides dependency injection for any instances attached to the Context
It also holds a Configuration
instance. All operations in Coin Trader are modeled as the creation of a Context
followed by attaching various modules to the Context
. When a module class is attached, any @When annotations it has are bound to the Esper
instance, and any @Inject
fields in the module class are populated with instances of the correct type which are already attached to this Context
.
This class is used instead of java.util.Currency
because the builtin java.util.Currency
class cannot handle non-ISO currency codes like "DOGE" and "42". We also track whether a Currency
is fiat or crypto, and define the smallest unit of settlement, called the basis (see DiscreteAmount
.) A collection of Currency
singletons is found in Currencies
.
DecimalAmount
s are used when the Amount
to be represented are free-floating and tied to a discrete basis.
This class is used to represent all prices and volumes. It acts like an integer counter, except the base step-size is not necessarily 1 (whole numbers). A DiscreteAmount
has both a long count
and a double basis
. The basis
is the "pip size" or what the minimum increment is, and the count
is the number of integer multiples of the value, so that the final value of the DiscreteAmount
is count*basis
. The minimum increment is (count+1)*basis
. This sophistication is required to handle things like trading Swiss Francs, which are rounded to the nearest nickel (0.05). To represent CHF 0.20 as a DiscreteAmount
, we use basis=0.05
and count=4
, meaning we have four nickels or 0.20. This approach is also used for trading volumes, so that we can understand the minimum trade amounts. Market
s record both a priceBasis
and a volumeBasis
which indicate the step sizes for trading a particular Listing
on that Market
.
Operations on DiscreteAmount
s may have remainders or rounding errors, which are optionally passed to a delegate RemainderHandler
, which may apply the fractional amount to another account, ignore the remainder, etc. See Superman 2.
This is the base class for anything which can be persisted. getId()
gives a UUID
, which is stored in the db as a BINARY(16)
.
A subtype of EntityBase
. Any subclass of Event
may be published to Esper
.
An Exchange
is anywhere with Listing
s of tradeable Fungible
s. A Listing
on a specific Exchange
is called a Market
. Technically, none of the existing cryptocurrency exchanges are actually exchanges in the sense of a matchmaking service; they are all broker-dealers with whom you have a deposit account. Thus Account
s are also linked to Exchanges
. A collection of Exchange
singletons is found in Exchanges
.
A Fill
represent part or all of an Order
being matched in a Market
. They are RemoteEvent
s and the order service will detect published Fill
s and update the Order
s status accordingly.
Fund
s are internal accounting if you have multiple Owner
s participating in the same Coin Trader deployment. Each Owner
has a Stake
in the Fund
representing their share. Every Strategy
has a matching Fund
, and Owner
s may participate in the Strategy
by transferring a Position
from their own deposit Fund
into a Strategy
's Fund
, in exchange for a Stake
in the Strategy
's Fund
. The price of the Stake
is marked-to-market at the time of transaction, using the best currently available data.
Every Fund
has a FundManager
who dictates the trading of the Fund
's Position
s. Owner
s are the FundManager
s of their deposit Fund
, and every Strategy
is a FundManager
for the Stategy
's Fund
whose positions it trades.
A Fungible
is anything that can be replaced by another similar item of the same type. Fungibles include Currency
, Stocks, Bonds, Options, etc.
A Listing
has a symbol but is not related to an Exchange
. Generally, it represents a tradeable security like BTC.USD
when there is no need to differentiate between the same security on different Exchange
s. Usually, you want to use Market
instead of just a Listing
, unless you are creating an order which wants to trade a Listing
without regard to the Account
or Exchange
where the trading occurs.
Every Listing
has a baseFungible
and a quoteFungible
. The baseFungible
is what you are buying/selling and the quoteFungible
is used for payment. For currency pairs, these are both currencies: The Listing
for BTC.USD
has a baseFungible
of Currencies.BTC
and a quoteFungible
of Currencies.USD
. A Listing
for a Japan-based stock would have the baseFungible
be the stock like Stocks.SONY
(stocks are not implemented) and the quoteFungible
would be Currencies.JPY
A Market
represents a Listing
(BTC.USD) on a specific Exchange
(BITSTAMP), and this is the primary class for tradeable securities. Note that using a Market
instead of a Listing
facilitates arbitrage by differentiating prices for the same security on different Exchange
s.
MarketData
is the parent class of Trade
, Book
, Tick
, and Bar
, and it represents any information which is joined to a Market
In the future, for example, we could support news feeds by subclassing MarketData
. See RemoteEvent
for notes on event timings.
A GeneralOrder
specifies a volume and a Listing
but does not specify an Exchange
. GeneralOrder
s are intended to be routed and cleared in a "best effort" attempt by an order execution algorithm. See SpecificOrder
.
This is a bid or ask, generally reported within a Book
although in the future, account transfers may also be modeled as Offer
s.
A simple way to identify the holders of internal funds. Owner
s are members or clients of this organization. Each Owner
has a deposit Fund
, and the Owner
may transfer positions from their deposit Fund
to other Funds
, receiving in exchange a Stake
s in other Fund
. This is how Owner
s may participate in various Fund
s managed by Strategy
s
A Position is a DiscreteAmount
of a Fungible
. All Positions
have both an Account
and a Fund
. The total of all Position
s in an Account
should match the external entity's records, while the internal ownership of the Positions
is tracked through the Fund
via Stake
s and Owner
s.
Many Event
s, like MarketData
s, happen remotely. RemoteEvent
allows us to record the time we received an event separately from the time the event happened. The standard Event.getTime()
field returns the time the event originally occured, and additionally, RemoteEvent.getTimeReceived()
records the first instant we heard about the event in the Coin Trader system. This will help us to understand transmission and processing delays between the markets and our trading clients.
A SpecificOrder
specifies a Market
and a volume, and may optionally specify a price limit. SpecificOrder
s carry the intent of immediate placement as-is, without breaking the order apart or routing it to alternative Market
s. See GeneralOrder
Stake
s record ownership in a Fund
by an Owner
Represents an approach to trading. Every Strategy
has a corresponding Fund
which holds the Position
s the Strategy
is allowed to trade.
Tick
reports instantaneous snapshots of the last trade price, current spread, and total volume during the Tick
's time window. It is not a single Trade
but a window in time when one or more Trade
s may happen. Tick
s may be generated from a stream of Trade
s and Book
s, and Tick
s are not collected from data providers. To generate Tick
s from Trade
and Book
data, attach a TickWindow
to your Context
.
Trade
describes a single transaction: the time, Market
, price, and volume.