Rudimentary spot market simulator for verifying bidding strategies
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.vscode
jupyter
lib
prices
public
spec
views
.gitignore
.rspec
.rubocop.yml
Gemfile
LICENSE
README.md
Rakefile
app.rb
package.json
tsconfig.json

README.md

What is it?

Rudimentary spot market simulator with an HTTP frontend written in Sinatra.

ui

Why is it?

While working on spotocles I looked around and couldn't find any spot market simulators so decided to take a small detour and write one for my use cases. I'm making it available because it might also be useful to others.

How do I use it?

To start the frontend you'll need npm so make sure npm is installed and then run

npm install
bundle
rake js:bundle
bundle exec ruby app.rb

Make sure you have SQLite installed because the simulation uses an in-memory SQLite database to keep track of its state. When you are done with the simulation you can flush the data to disk by posting to /flush endpoint.

Endpoints

You can use the library directly in your own code if you are writing something in Ruby by importing ./lib/market. It is self-contained other than requiring SQLite for managing internal state. If you are writing your spot bidding strategy in another language then you can use the HTTP frontend and write a small client to drive the simulation through HTTP. Here are the endpoints you can use to drive the simulation

GET /regions

Returns the list of regions that that have non-zero initial capacity, i.e. these are the regions you can create instances in by making bids/requests. You can modify the regions and instances by modifying the JSON file in prices/.

GET /capacities

Returns the current capacities for each region. If you want to change the initial capacities then you can post and modify it. Capacities can be mutated at any time during the simulation to simulate addition and removal of capacity.

POST /capacities

Change the capacities for each region. This will affect spot prices and can be used for simulating addition and removal of capacity.

GET /instance(/:region)?(/:type)?

Grab the instances and their attributes like on-demand price, vCPU, memory, etc. If no parameters are given then all regions and instance types are returned. If the second parameter is given then only instances in that region are returned. If the third parameter is given then only information for that instance type in that region is returned.

GET /spot(/:region)?(/:type)?

Grab the spot prices. If no parameters are given then spot prices in all regions are returned. If the second parameter is given then only spot prices in that region are returned. If the third parameter is given then only the spot price for that instance type in that region is returned.

POST /request

Create a request for an instance. Nothing will happen to the request until /tick is called to advance the state of the simulation.

GET /request/:id

Grab the request object to find out its state.

POST /cancel

Cancel a request by providing the request ID in the post body as a JSON object, e.g. {"id": 123}.

POST /tick

Advance the simulation counter and perform any necessary actions to transition the existing requests to their next state along with updating all the necessary internal state and tables.

POST /flush

The simulation uses an in-memory SQLite instance for speed but when you are done with the simulation you can post to this endpoint to dump the in-memory data to disk for analysis. If you don't provide a name of the backup then by default the backup/dump file will be the time when flush was called.