'marketplace in a box' - a one-stop shop for all the essential infrastructure and services needed to create a marketplace.
Project description
Tianguix
Tianguix aims to be a "marketplace in a box"- a one-stop shop for all the essential infrastructure needed to create a marketplace. Initially, I envisioned it as just an order book, but adding a few more features will make it useful and more fun to write.
Marketplaces come in many forms, but the two most relevant to me are:
- Simple auctions
- Continuous two-sided (buyer/seller) auctions
At the same time, marketplaces require certain features to be workable in today's infrastructure. Below is a wishlist of capabilities that I would like to see in a "marketplace in a box":
- A flexible yet simple order book with an intuitive interface and limited (no pun intended) but effective order-matching options.
- An auction book supporting English and Dutch auctions.
- A simple mechanism to send orders to the exchange and, in general, to get the state of the order, perhaps taking the best spirit of the FIX protocol but removing the accumulated cruft to leave the actual spirit of the transaction.
- Reliable market data distribution, ideally compact and fast, similar to what financial exchanges provide. All of the above should be able to be used through a REST interface, as crypto exchanges do now, but with a solid, specific transaction core.
Big NOs
I haven't seen how crypto exchanges are implemented, but I pray to Olympus that it is not just a regular messaging service. Certainly, Tianguix can be simple, but it should not just rely on REST protocols.
- Big no to Native FIX protocol implementations.
- I will add things as they pop.
Key Features
- Algorithmic flexibility: While the initial implementation will be in Python (as it’s my strongest language), the design should allow multiple language implementations while maintaining computational efficiency, where we can always copy what we know works, particularly the use of binary trees to give constant complexity to the most common operations. (More to be worked here, of course)
- Single-threaded books/auctions: The current standard in most markets is a single-threaded process where orders are added in a time-based or first-come, first-served manner. This aligns with how most major exchanges operate today.
- Deployment options:
- A modular, dockable architecture for easy deployment as a functional exchange.
- Seamless testing and back-testing capabilities, ensuring ease of simulation and validation.
The Core Idea
The Order book
tianguix.orderbook implements an order book as it is used in financial markets.
I would like to be able to see this sequence executed cleanly
At its core, an order book centralizes buyers' and sellers' interests by aggregating their firm orders (as opposed to a quotation-based market, which may operate differently).
Transactions for a specific instrument (e.g., a stock or concert ticket) can be structured into two ordered lists:
- Buyers list (demand)
- Sellers list (supply)
Each order contains:
- Size: The quantity of the instrument to be transacted.
- Price: The price at which the buyer or seller is willing to execute the trade.
- Priority: (Impliciti) Orders at the same price are filled on best-price first, then FIFO (first-in, first-out) basis, meaning the earliest order takes precedence.
This foundation serves as the basis for auctions and order book mechanics.
Order Book Example: Basic Trade Execution
1. Placing Orders
Two participants enter the market:
- A places a buy order for 100 AMXL shares at $18.13.
- B places a sell order for 100 AMXL shares at $18.13.
2. Order Matching & Execution
A trade is executed since the buy and sell orders match in both quantity and price.
3. Execution Report
Both A and B receive an execution report confirming:
- 100 shares traded at $18.13.
- The orders are now fulfilled.
Python Code Example (Using tianguix.order_book)
from tianguix.order_book import OrderBook, Bid, Offer
# Initialize the order book
order_book = OrderBook()
# Create bid and offer
bid = Bid(id="A", symbol="AMXL", quantity=100, price=18.13)
offer = Offer(id="B", symbol="AMXL", quantity=100, price=18.13)
# Submit orders to the book
order_book.add_order(bid)
order_book.add_order(offer)
# Process matching and generate execution report
executions = order_book.match_orders()
# Print execution reports
for execution in executions:
print(f"Execution Report: {execution.quantity} {execution.symbol} @ {execution.price} for {execution.buyer} and {execution.seller}")
License
This project is licensed under the GNU Affero General Public License v3. See the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tianguix-0.0.2.tar.gz.
File metadata
- Download URL: tianguix-0.0.2.tar.gz
- Upload date:
- Size: 16.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5dec15136e8ad2b61fca687056cbb83a7b96df5a177c59ca3ac4601b9ae134d6
|
|
| MD5 |
cbe13e2a81370bc9f09aab308019fb7f
|
|
| BLAKE2b-256 |
ff4793b0e560238178e415ba11458a64bbaea0799a4fce6197dc38ee52aa6107
|
File details
Details for the file tianguix-0.0.2-py3-none-any.whl.
File metadata
- Download URL: tianguix-0.0.2-py3-none-any.whl
- Upload date:
- Size: 17.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0ad344db59bc6618cbb910f32fee240bb6f76e8f288f4293187ac26ea4c8b41e
|
|
| MD5 |
2e8a8b267dddce791f83352969ca7b1c
|
|
| BLAKE2b-256 |
d2ef401e2fb08b4e5a6d358d9c0c32a68647f8400d8d3f5e5be9b7f81b4c6f67
|