Skip to content
Tim Olson edited this page Feb 7, 2015 · 3 revisions

Amount

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.) Amounts which are not tied to a Market, Currency, or other object which has a discrete basis are represented by DecimalAmounts, 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.

Account

An Account represents external accounting: an Account is held with an Exchange differs from a Fund in a couple ways: Accounts do not have an Owner, and they are reconciled 1-for-1 against external records (account data gathered from XChange). Accounts generally relate to balances on exchanges, but there may be Accounts attached to Exchanges.SELF, meaning the account is internal to this organization.

Bar

The common OHLC or open/high/low/close for a standard duration of time like one minute. These can be generated from Trades or Ticks and are not collected from data providers.

Book

All the Bids and Asks for a Market at a given point in time. Books are one of the two main types of MarketData we collect, the other being Trades.

Context

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.

Currency

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

DecimalAmounts are used when the Amount to be represented are free-floating and tied to a discrete basis.

DiscreteAmount

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. Markets record both a priceBasis and a volumeBasis which indicate the step sizes for trading a particular Listing on that Market. Operations on DiscreteAmounts 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.

EntityBase

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).

Event

A subtype of EntityBase. Any subclass of Event may be published to Esper.

Exchange

An Exchange is anywhere with Listings of tradeable Fungibles. 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 Accounts are also linked to Exchanges. A collection of Exchange singletons is found in Exchanges.

Fill

A Fill represent part or all of an Order being matched in a Market. They are RemoteEvents and the order service will detect published Fills and update the Orders status accordingly.

Fund

Funds are internal accounting if you have multiple Owners 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 Owners 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.

FundManager

Every Fund has a FundManager who dictates the trading of the Fund's Positions. Owners are the FundManagers of their deposit Fund, and every Strategy is a FundManager for the Stategy's Fund whose positions it trades.

Fungible

A Fungible is anything that can be replaced by another similar item of the same type. Fungibles include Currency, Stocks, Bonds, Options, etc.

Listing

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 Exchanges. 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

Market

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 Exchanges.

MarketData

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.

GeneralOrder

A GeneralOrder specifies a volume and a Listing but does not specify an Exchange. GeneralOrders are intended to be routed and cleared in a "best effort" attempt by an order execution algorithm. See SpecificOrder.

Offer

This is a bid or ask, generally reported within a Book although in the future, account transfers may also be modeled as Offers.

Owner

A simple way to identify the holders of internal funds. Owners 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 Stakes in other Fund. This is how Owners may participate in various Funds managed by Strategys

Position

A Position is a DiscreteAmount of a Fungible. All Positions have both an Account and a Fund. The total of all Positions in an Account should match the external entity's records, while the internal ownership of the Positions is tracked through the Fund via Stakes and Owners.

RemoteEvent

Many Events, like MarketDatas, 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.

SpecificOrder

A SpecificOrder specifies a Market and a volume, and may optionally specify a price limit. SpecificOrders carry the intent of immediate placement as-is, without breaking the order apart or routing it to alternative Markets. See GeneralOrder

Stake

Stakes record ownership in a Fund by an Owner

Strategy

Represents an approach to trading. Every Strategy has a corresponding Fund which holds the Positions the Strategy is allowed to trade.

Tick

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 Trades may happen. Ticks may be generated from a stream of Trades and Books, and Ticks are not collected from data providers. To generate Ticks from Trade and Book data, attach a TickWindow to your Context.

Trade

Trade describes a single transaction: the time, Market, price, and volume.