Board index Bitcoin Qt Bitcoin Trader JL Script - Script language for automated trading

JL Script - Script language for automated trading

Qt Bitcoin Trader is open source application that helps you open and cancel BTC-e, Bitstamp, BTCChina, Bitfinex, orders very fast. Real time data monitoring.

Posts: 11
Location: Ukraine


JL Script is enhanced script language what is developed by me that makes easy to create advanced strategies.
There available full featured JavaScript support and JL Script specific methods.

You can write JL Script code using Qt Bitcoin Trader (Download for Mac, Linux, Windows).

All JL Script specific methods are starting with "trader" command, and it can be three types of usage, Events, Functions and Commands. Example of usual method is trader.get("LastPrice") what return last market price instantly.


Event is a function that linked to indicator and it executing every time indicator value changes.
Structure of event function starts with command "trader.on(", next is name of indicator and end of the method is ").changed()".
So example of event usage is:

//Your code here

Each event does have internal variables what is works only inside of event: symbol, name, value.
symbol is a currency pair name, example is "BTCUSD"
name is a indicator code name, example is "LastPrice"
value is a floating type number that is indicator value
This variables can be used, or ignored.

Example of usage of this variables is:

if(symbol!="BTCUSD")return; // If indicator symbol is not BTCUSD, next code rows will be ignored
if(value>500)than ..; //value is current market last price

Supported events list:
//This event based on indicator division of all bids volume to all asks volume (last trades 10 minutes)

//Last 10 minutes trading volume

//Api Lag - this value is delay between request and response, if it a bigger than 15 seconds, it means exchange or your internet is down

trader.on("LastPrice").changed() // Market last price

trader.on("AskPrice").changed() // Market ask price

trader.on("BidPrice").changed() // Market bid price

trader.on("LastMyBuyPrice").changed() // Account last buy price

trader.on("LastMySellPrice").changed() // Account last sell price

trader.on("Fee").changed() // Account Fee

// There can be any currency, and it return balance of this currency if supported, if not, than it do nothing for selected currency

trader.on("HighPrice").changed() // Market high price for last 24 hours

trader.on("LowPrice").changed() // Market low price for last 24 hours

trader.on("DayVolume").changed() // Exchange 24h volume

trader.on("MyLastTrade").changed() // Your account order filled

trader.on("LastTrade").changed() // Any market order filled

// Any of indicators changed, can make high CPU load, better to use timers (see below)

// This event executing every 1 second

//Open orders count changed

//Open bids count changed

//Open asks count changed


Function is a method what return some indicator value, or result of calculations.
You can get any indicator value by using "get" method. Example is trader.get("LastPrice").
Functions that return indicator values two arguments, first is symbol and second is indicator name. Example: trader.get("BTCUSD","LastPrice").
You can use it in any place of script.

Functions that return indicators value:
trader.get("Balance","BTC") // Used to get balance by any currency if supported, if not supported it return 0

//This function return division of all bids volume to all asks volume (last trades 10 minutes)

//Last 10 minutes trading volume

//Api Lag - this value is delay between request and response, if it a bigger than 15 seconds, it means exchange or your internet is down

trader.get("AskPrice") // Market ask price

trader.get("BidPrice") // Market bid price

trader.get("DayVolume") // Exchange 24h volume

trader.get("Fee") // Account Fee

trader.get("HighPrice")// Market high price for last 24 hours

trader.get("LastMyBuyPrice") // Account last buy price

trader.get("LastMySellPrice") // Account last sell price

trader.get("LastPrice") // Market last price

trader.get("LowPrice") // Market low price for last 24 hours

Special functions
trader.get("Time") // This function return (seconds) current time in unix number format (time_t)

trader.get("AsksPrice",volume) //Asks price by volume
trader.get("BidsPrice",volume) //Bids price by volume
//This functions return calculated order book price for selected volume. For example if you want to know what price will become when someone will sell 1000 BTC at time, function trader.get("BidsPrice",1000) will return price what is in the same row in order book as at least total size 1000 BTC.

trader.get("AsksVolume",price) //Asks volume by price
trader.get("BidsVolume",price) //Bids volume by price
//This functions return values that calculated in another direction. You can get total volume by selected price. For example if you want to know total volume available between last price and selected price you can get it using this code: trader.get("AsksVolume",600)

//Warning! Order Book depend values calculated only using visible order book, if you need more deep, than you should switch to more visible rows

//Your open orders count

//Your open asks count

//Your open bids count


Timers and delays

Using JL Script you can set up timers or delays using this like code:


For example you have function named "myFunction()" and you want start it with delay 1,5 seconds (1500 ms).
It can be done this way:

Timer works in the same way, if you use this code:

In result your "myFunction()" will be executed repeatedly with interval 1.5 seconds.


With JL Script you can use custom log function that will append row in log view.
Log view is individual for each script or rule group.

You can use this function to put log: trader.log()

trader.log("Hello world!"); //Result "Hello world!"

trader.log(200.45); //Result "200.45"

trader.log("Last price is:",trader.get("LastPrice")); //Result is text "Last price is:" and last price value at end

You can use there up to 4 arguments or list of strings with unlimited count.

To clear log output you can use this command trader.logClear()

Sound notifications

There is three commands that makes sound notifications for you:

trader.beep() // Makes beep sound

trader.playWav("C:/mySound.wav") //Play audio file (WAV format only) by full file path as parameter

//This function spell any values and text using system engine. It works great for Mac and Windows, but for Linux it works like starting command "say text" so you should configure it by yourself to make it works.
//You can use code like this: trader.say("Current market price is",trader.get("LastPrice")) and it will talk to you.

Third party applications

You can start any external application by using this command: trader.startApp("C:/PathToMy.exe")

Trading commands

Trading command is order sell, buy, or cancel operation. You can use symbol as first parameter to make it works only to specified currency pair.

// Sell specified amount by price. Example: trader.sell(1,500) - sell 1 BTC at 500 USD - current currency pair will be used.
// Buy works the same way. Also you can add first argument as symbol. For example trader.sell("BTCUSD",1,500) it will sell 1 BTC at 500 USD.

trader.cancelOrders() // Cancel all open orders

trader.cancelAsks() // Cancel all asks

trader.cancelBids() // Cancel all bids

Disabling/Enabling groups by script

You can enable or disable any existing rules or script group by its name.

trader.groupStart("name") //Start rule group or script by name

trader.groupStop("name") //Stop rule group or script by name

trader.groupIsRunning("name") //Return true if group by name have running rules or script


You can use JavaScript code to create own variables in any place of code.
For example: "var a=0;" and use it later "a=a+6" or combine it with JL Script functions: "a=a+trader.get('LastPrice')"

Custom indicators and events

With JL Script you can create own indicators and events.
To make own indicator you just need to use one command: trader.sendEvent("name",value);
And also you can use the same command with three parameters: trader.sendEvent("symbol","name",value);
You can create indicator with any name you want, but it should not be the same as existing indicators.

For example, let create indicator that is middle value of BidPrice and AskPrice.
Let name this indicator "MidPrice".
We will broadcast event with "MidPrice" using this command: trader.sendEvent("MidPrice",value);
Now we need to calculate value each time when BidPrice or AskPrice changed.

Lets create new script and name group "Mid Price Indicator".
Now add BidPrice and AskPrice events.


Next we make function that calculates our middle price value and name it "calculateMidPrice()".
Code what used to calculate our middle price is: "(trader.get("BidPrice")+trader.get("AskPrice"))/2".
But we need to make sure that we broadcasting event only when indicator changes.
So we create variable named "lastMidPrice" to store last price and compare with new to detect duplicates.

var lastMidPrice=0;
calculateMidPrice(); // Calculate mid price at script startup

function calculateMidPrice()
var midPrice=(trader.get("BidPrice")+trader.get("AskPrice"))/2;
if(midPrice==lastMidPrice)return; // Stop script if value is not changed
lastMidPrice=midPrice; // Save previous value
trader.sendEvent("MidPrice",midPrice); // Broadcast our event




Now we can check how it works. Create new empty script named "MidPrice Test".

Make event to custom indicator is easy as usual indicator events.
Write event body:



Now to see visually how it works we can log every change:

trader.log("MidPrice is changed:", value);

Now just start both script groups and look at the log:


Our custom indicator works and we can use it in any script group. It also c an be used by get method: trader.get("MidPrice");

Need to know

Remember that you need to think about amounts that going to be used to open orders. If your order request amount will be less than 0.001 (for example) exchange will don't accept open order.

Remember that if API Lag is more than 15 seconds, it makes very low chance that order will be placed or canceled. You should take care to open order only if API Lag is small.

You can not get indicators from symbols either than current selected pair yet. But some exchanges does supports sell and buy methods that is not depended on current currency pair.

Video tutorial:

Updated 2014-10-10
Added new events: OpenOrdersCount, OpenBidsCount, OpenAsksCount

Return to Qt Bitcoin Trader