Skip to main content

'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}")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tianguix-0.0.1.tar.gz (16.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tianguix-0.0.1-py3-none-any.whl (16.8 kB view details)

Uploaded Python 3

File details

Details for the file tianguix-0.0.1.tar.gz.

File metadata

  • Download URL: tianguix-0.0.1.tar.gz
  • Upload date:
  • Size: 16.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.1

File hashes

Hashes for tianguix-0.0.1.tar.gz
Algorithm Hash digest
SHA256 491e72e47f0bff3c30bcfa73817fc247f751bb75975a791522470ebe310404fd
MD5 42f6d96fa98b38612a6b9e09507cd7b2
BLAKE2b-256 bb88a3b030f383bafd18c9ef6e5af69538249adfb6cf435f55a536c143687b37

See more details on using hashes here.

File details

Details for the file tianguix-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: tianguix-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 16.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.1

File hashes

Hashes for tianguix-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1c20738f1d6f01edc3f7ee731f958c34999efb3b2a413a886831441b5a3ca2b2
MD5 470eb1b7402acc8c2cda9efaf74a57d3
BLAKE2b-256 09c73b95cf504dd4ae6fc5fcdd1c64c2c9d1261b3411443b71d707628a5141e9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page