Skip to content

charonviz/AuctoScript

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AuctoScript

An interpreted language for stochastic market simulation and algorithmic trading.

Python 3.9+ MIT License C C++ Bindings


AuctoScript Architecture

AuctoScript is a complete platform for simulating stochastic auction markets. It consists of a TCP-based multiplayer auction server (C), a custom scripting language interpreter for writing automated trading bots (C++), and a Python toolkit for orchestrating competitions, visualizing results, and developing strategies.

The project implements the stochastic auction model described in:

Model of stochastic auctions using level market index Nikonov M., Shishkin A., Konev D., Dolmatov A. Financial Statistical Journal, 2023 DOI link

Features

  • Custom scripting language — AuctoScript (.as) is algorithmically complete with variables, arrays, loops, conditionals, and a built-in market API
  • Multiplayer TCP server — connects any number of bots (or human players via telnet) for head-to-head competition
  • Two market modes — built-in stochastic model or replay from real FINAM/OHLCV data files
  • Python Arena — orchestrate bot-vs-bot competitions with a single function call
  • Live dashboard — real-time matplotlib charts for price, balance, and holdings
  • Multi-language clients — connect from Python, Java, Julia, or Scala via TCP

The Language

AuctoScript Code

AuctoScript is a domain-specific language designed for writing trading strategies. Programs run in a loop — once per market tick — and interact with the server through built-in functions prefixed with ?.

Variables use $ prefix, support arrays, and are dynamically typed. Control flow includes while loops and if conditionals. Market functions let you query prices, balances, other players' positions, and place buy/sell orders.

// Buy raw materials, produce, sell products
?buy(2, ?raw_price());
?prod(?factories(?my_id()));
?sell(?production(?my_id()), ?production_price());

Full language reference: docs/LANGUAGE.md

Live Dashboard

AuctoScript Dashboard

The built-in viewer provides real-time charts showing market price, player balances, and stock holdings during a simulation. Works with both live arenas and replayed protocol files.

Quick Start

1. Build

git clone https://github.com/charonviz/AuctoScript.git
cd AuctoScript
make all
pip install -e .

2. Run an Arena (Python)

from auctoscript import Arena

arena = Arena(
    strategies=[
        "examples/strategies/smart_trader.as",
        "examples/strategies/simple_buyer.as",
    ],
    port=4000,
)
arena.run()

for entry in arena.leaderboard():
    print(f"#{entry['rank']} {entry['strategy']} — ${entry['money']:,}")

3. Run Manually (Terminal)

Start the server:

# Stochastic model (no data file)
./build/bin/auctoscript-server 3000 2

# Replay from FINAM data
./build/bin/auctoscript-server-finam 3000 2 examples/data/SBER_sample.csv

Connect bots:

./build/bin/auctoscript-interpreter 0 3000 examples/strategies/smart_trader.as
./build/bin/auctoscript-interpreter 0 3000 examples/strategies/simple_buyer.as

Or connect as a human player via telnet:

telnet localhost 3000

4. Watch Live

from auctoscript import Viewer

viewer = Viewer(players=2)
viewer.show_dashboard()

Project Structure

AuctoScript/
├── src/
│   ├── server/
│   │   ├── server.c              # Stochastic model server
│   │   └── server_finam.c        # FINAM data replay server
│   └── interpreter/
│       └── interpreter.cpp       # AuctoScript language interpreter
├── auctoscript/                  # Python package
│   ├── __init__.py
│   ├── server.py                 # Server process manager
│   ├── bot.py                    # Bot process manager
│   ├── arena.py                  # Multiplayer orchestrator
│   ├── viewer.py                 # Real-time visualization
│   └── data.py                   # Sample dataset management
├── examples/
│   ├── strategies/               # Example .as strategy scripts
│   │   ├── smart_trader.as
│   │   └── simple_buyer.as
│   └── data/                     # Sample market data (OHLCV)
├── bindings/
│   ├── java/                     # Java TCP client (planned)
│   ├── julia/                    # Julia TCP client (planned)
│   └── scala/                    # Scala TCP client (planned)
├── docs/
│   └── LANGUAGE.md               # AuctoScript language reference
├── tests/
├── Makefile
├── pyproject.toml
└── LICENSE

Python API

Server

from auctoscript import Server

# Context manager — auto-stops on exit
with Server(port=3000, players=2) as server:
    # ... connect bots ...
    server.wait()

# With real market data
server = Server(port=3000, players=2, data_file="data/SBER.csv")

Bot

from auctoscript import Bot

bot = Bot("strategies/smart_trader.as", port=3000)
bot.start()
bot.wait()

Arena

from auctoscript import Arena

arena = Arena(
    strategies=["smart.as", "simple.as", "random.as"],
    port=5000,
    data_file="examples/data/EURUSD_sample.csv",  # optional replay mode
)
arena.run(timeout=60)  # optional timeout in seconds
print(arena.leaderboard())

Viewer

from auctoscript import Viewer

viewer = Viewer(players=3)
viewer.show_price()         # price chart only
viewer.show_money()         # all player balances
viewer.show_dashboard()     # full 3-panel dashboard
viewer.snapshot("out.png")  # save static image

Server Commands

These commands are available to any TCP client (bots, telnet, or custom clients):

Command Description
market Current market state (supply, demand, prices)
player <id> Info about a specific player
me Your own player info
buy <count> <price> Place a buy order for raw materials
sell <count> <price> Place a sell order for products
prod <count> Convert raw materials into products
build Build a new factory (costs money)
turn End your turn
help List available commands

Writing Custom Strategies

Create a .as file with your trading logic:

{
    // Simple momentum strategy
    $price = ?raw_price();
    $my_money = ?money(?my_id());

    if $price < $last_price {
        ?buy(3, $price);
    };
    if $price > $last_price {
        ?sell(?production(?my_id()), ?production_price());
    };
    ?prod(?raw(?my_id()));
    $last_price = $price;
}
end

Test it in an arena:

from auctoscript import Arena

arena = Arena(strategies=["my_strategy.as", "examples/strategies/smart_trader.as"])
arena.run()

Building from Source

Requirements: GCC, G++, Python 3.9+, Make.

make all          # build server + interpreter
make server       # server only
make interpreter  # interpreter only
make clean        # remove build artifacts

Connecting from Other Languages

AuctoScript uses a plain TCP protocol — any language that can open a socket can play. See the bindings/ directory for client examples in Java, Julia, and Scala.

# Even a raw Python socket works
import socket
s = socket.socket()
s.connect(("localhost", 3000))
s.send(b"market\n")
print(s.recv(1024).decode())

Academic Reference

If you use AuctoScript in research, please cite:

@article{nikonov2023stochastic,
  title={Model of stochastic auctions using level market index},
  author={Nikonov, Maksim and Shishkin, Alexei and Konev, Dmitry and Dolmatov, Aleksandr},
  journal={Financial Statistical Journal},
  year={2023},
  publisher={EnPress Publisher},
  url={https://systems.enpress-publisher.com/index.php/FSJ/article/view/2931}
}

License

MIT — Copyright (c) 2023-2025 Maksim Nikonov. See LICENSE.

About

DOI: https://doi.org/10.24294/fsj.v6i2.2931

DOI: https://doi.org/10.24294/fsj.v6i2.2931

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published