Xfighter
A library API for the programming game Stockfighter
Warning: the Xfighter code is in flux at the moment. Until version 1.0 expect breakage and backward-incompatible changes.
Installation
To use Xfighter in your Mix projects:
-
Add xfighter to your list of dependencies in
mix.exs:
def deps do
[{:xfighter, "~> 0.2.1"}]
end- Ensure xfighter is started before your application:
def application do
[applications: [:xfighter]]
end-
Add the following line to your
config/config.exsand insert your API key:
config :xfighter, api_key: "INSERT_YOUR_API_KEY_HERE"- To download and install the package run:
mix deps.get
mix deps.compileOverview
Once the installation is complete, type the following command in your terminal:
iex -S mixYou should now be able to play Stockfighter. You can find a complete documentation here for function return types.
Check if the API is up
iex> Xfighter.heartbeatCheck if a venue is up
iex> Xfighter.Venue.heartbeat("TESTEX")Stocks on a venue
iex> Xfighter.Stock.list("TESTEX")The state of the orderbook for a stock
iex> Xfighter.Orderbook.state("FOOBAR", "TESTEX")Place an order for a stock
#Buy order
iex> Xfighter.Stock.buy(10, "FOOBAR", "TESTEX", "EXB123456", "market")
iex> Xfighter.Stock.buy(10, "FOOBAR", "TESTEX", "EXB123456", "limit", 50.16)
iex> Xfighter.Stock.buy(10, "FOOBAR", "TESTEX", "EXB123456", "fok", 40)
iex> Xfighter.Stock.buy(10, "FOOBAR", "TESTEX", "EXB123456", "ioc", 20.5)
#Sell order
iex> Xfighter.Stock.sell(10, "FOOBAR", "TESTEX", "EXB123456", "market")
iex> Xfighter.Stock.sell(10, "FOOBAR", "TESTEX", "EXB123456", "limit", 50.16)
iex> Xfighter.Stock.sell(10, "FOOBAR", "TESTEX", "EXB123456", "fok", 40)
iex> Xfighter.Stock.sell(10, "FOOBAR", "TESTEX", "EXB123456", "ioc", 20.5)A quote for a stock
iex> Xfighter.Stock.quote("FOOBAR", "TESTEX")Status for an existing order
iex> Xfighter.Order.status(1649, "FOOBAR", "TESTEX")
Or if you have an existing order of type Xfighter.Order.t.
iex> order = %Xfighter.Order(:id => 1649, :symbol => "FOOBAR", :venue => "TESTEX")
iex> Xfighter.Order.status(order)Status of a list of orders
iex> order1 = %Xfighter.Order(:id => 1648, :symbol => "FOOBAR", :venue => "TESTEX")
iex> order2 = %Xfighter.Order(:id => 1649, :symbol => "FOOBAR", :venue => "TESTEX")
iex> Xfighter.Order.status([order1, order2])Cancel an order
iex> Xfighter.Order.cancel(1649, "FOOBAR", "TESTEX")
Or if you have an existing order of type Xfighter.Order.t.
iex> order = %Xfighter.Order(:id => 1649, :symbol => "FOOBAR", :venue => "TESTEX")
iex> Xfighter.Order.cancel(order)Cancel a list of orders
iex> order1 = %Xfighter.Order(:id => 1648, :symbol => "FOOBAR", :venue => "TESTEX")
iex> order2 = %Xfighter.Order(:id => 1649, :symbol => "FOOBAR", :venue => "TESTEX")
iex> Xfighter.Order.cancel([order1, order2])Status for all orders in an account
iex> Xfighter.Account.status("EXB123456", "TESTEX")Status for all orders in a stock
iex> Xfighter.Account.orders("EXB123456", "FOOBAR", "TESTEX")License
This project is licensed under the terms of the MIT License.