Skip to content

Gotchas

Morgan Grant edited this page Nov 13, 2020 · 2 revisions

Gotchas

This page contains some important considerations to keep in mind when using oTree markets.

Integer Price and Volume

In oTree Markets, order prices and volumes are always integers. This is to prevent rounding errors which would greatly complicate the exchange algorithms. This means that player asset and cash holdings are also always integers.

If you'd like players to be able to enter fractional prices and volumes, it's recommended to take an approach of treating prices and volumes as fixed-point decimals. That is, you should choose a power-of-10 multiplier that you can multiply every quantity entered by to convert from a decimal to an integer.

For example if you'd like players to be able to specify prices to the thousandth of a unit, you can have the frontend multiply every entered price by 1000 before submitting it to the backend. Then when you receive order and trade data back from the backend, you divide all the price fields by 1000 when displaying them.

Page Timeouts

When using oTree Markets, you should never set oTree's Page.timeout_seconds on a trading page. You should instead use Group.period_length. This is because Page.timeout_seconds starts its timer as soon as the page loads. Group.timeout_seconds instead starts the timer when all traders have arrived and are ready for trading. Using Group.timeout_seconds ensures every player is allowed to trade for the same amount of time.

If you'd like players to see how much time is remaining in the trading session, you can use the timeRemaining property of the trader-state webcomponent.

Clone this wiki locally