Home Features Markets Blog
Guide Contact
Telegram icon Twitter icon Facebook icon

Foxbot - A simple market making software

Foxbot is written in JavaScript (Node.js) and should serve as an example for how to use our API. It depends on the simplistic JavaScript libraries FoxHttps and FoxSocket that you can reuse for you own projects.

Foxbot calls the 1Fox HTTPS API once a minute to fetch the current index price and also connects to the Websocket API to react to any order or position changes. The software places an order both on the buy and the sell side of the order book, hoping to make a profit on the bid-ask spread. If you do not understand the concept behind market making, take a look at the Wikipedia article.

Download & Installation

This software should run on Windows, macOS and Linux based platforms without any issues. Download and extract the foxbot.zip archive to a local directory:
Download foxbot.zip

Before running Foxbot you also need to install Node.js on your system.

After extracting the zip file, the Node.js dependencies need to be installed. Open a terminal in the directory of your foxbot.js file and enter the following command:
> npm install

Once you configured Foxbot, you can start it by entering the following command:
> node foxbot.js

If you want to keep a Node.js script running in the background on a server, we recommend using a process manager like PM2.

Configuration & Features

The bot acts as a simple market maker and places an order both on the buy (long) and the sell (short) side of the order book. It calls the 1Fox HTTPS API once a minute to fetch the current index price and also connects to our WebSocket server to listen for user channel updates to react to any order or position changes. On each iteration the bot closes existing orders and creates new ones with the appropriate margin at the set distance from the index price. It also adjusts the Take Profit value of existing positions and merges them if possible.

The configuration of the bot happens directly at the top of the foxbot.js file:
const token = 'YOUR_API_TOKEN';
You need to set your personal API token here. You can generate it in the trading panel.

const symbol = 'BTCUSD';
The symbol variable should be self-explanatory. You can change the market symbol, if you want to operate on another market.

const order_margin = 0.1; // BTC
The bot will open Limit orders with this margin. If a position exists, then the order margin is adjusted in such a way, so that the sum of the Take Profit order (which is a Limit order) and the Limit order do not exceed this value. If the long/short exposure (=margin sum of open positions) exceeds the order_margin, no order is created on respective side of the order book and only the Take Profit is adjusted.

const maximum_exposure = 1; // BTC
If the long/short exposure exceeds the maximum_exposure, only the Take Profit of open positions is adjusted. The market maker now stops placing Limit orders on both sides of the order book until the exposure drops below the threshold again.

const spread = 0.5; // Percent
The spread describes the distance (in percentage of the current price) between your two opposing Limit orders. A spread of 0.5% will result in a short Limit order 0.25% above the index price and a long Limit order 0.25% below the index price. The lower the spread the more trades the software will make, but also the less profitable it will be - so choose it wisely.

const leverage = 2;
You can set the leverage that will be used here. A higher leverage can increase the potential profits, but increases the risk of forced liquidations.

Improvement Suggestions

Foxbot only has basic market making functionality for demonstration purposes. It is only meant as a template to build upon. There are many improvement possibilities:
  • The index price can be fetched in real-time instead of polling our HTTPS API. (WebSocket connection to Coinbase Pro for our BTCUSD market)
  • Spread can be adjusted depending on exposure, profit requirements or price volatility.
  • The current order book can be used to optimize the prices of your orders.
  • With post-only limit orders paying the taker fee can be avoided.
  • More than two orders can be opened at different prices to better profit from fat finger errors.
  • The funding rate is neglected in this example. A software can try to move the funding rate to the favorable direction or place orders at different prices depending on the funding rate.


This library can be found in the node_modules directory of foxbot.zip - you can use it for your own 1Fox projects. It simplifies making calls to the HTTPS API.

After including the library it needs to be instantiated with your API token:
const FoxHttps = require('foxhttps');
var foxHttps = new FoxHttps(API_TOKEN);

Calling one of the API endpoints is quite simple:
foxHttps.marketGet(parameters, callback_function);
	function (response) {
		if (response.error === false) {
		} else {
Every function call takes URL parameters as a string and a callback function that is called once a server response has been received. You should always check the error flag inside the callback function and either execute your code or print an error message.


This library can be found in the node_modules directory of foxbot.zip - you can use it for your own 1Fox projects. It simplifies communication with the Websocket API.


After including the library you can easily connect to our Websocket API like this:
const FoxSocket = require('foxsocket');
foxSocket = new FoxSocket(

Here is an example that prints all WebSocket messages to the console:
foxSocket = new FoxSocket(
	function(event) {
		console.log('Connected to websocket.');
	function (message) {
	function (event) {
		console.error('Lost connection to websocket server.');
	function (event) {
		console.error('Websocket error.');


Subscribing to a WebSocket channel works like this:
	function (data) {


Unsubscribing from a WebSocket channel is similar:


If you activate heartbeat messages, the server will send a heartbeat every second with the current server UNIX time in milliseconds since 1970-01-01. You can use this to synchronize clocks or to check connectivity.

What are you waiting for?

Trading Panel

Take us with you

Get it on
Google Play