Cancoin Blog

The Cancoin price script engine

Ty Cancoin
August 27, 2017

The price of your buy or sell listing in the Cancoin Marketplace is powered by your listing's price script. Define your price by applying a simple margin to your favorite exchange, or write a multi-line lua script to take full control of your buy or sell price.

Price scripts

Cancoin price scripts are used to determine your listing's buy or sell price. The price engine will execute your script any time a market or currency variable in your script has changed, updating your listing's public buy or sell price at the same time. Cancoin provides an in-browser script editor that allows you to craft your scripts using live bitcoin market variables that are queried and updated from a number of sources, including Bitcoin Average and Open Exchange Rates. Cancoin price scripts are written in the Lua programming language, which when combined with the near infinite combination of market variables available, allow a high level of flexibility when determining your listing's price.

Lua is a simple programming language that contains few default keywords and has a basic grammar that is descriptive and easy to read & write as a beginner. Our goal is to allow anyone to create customized scripts, so an easy to grasp syntax was a priority. One of the greatest strengths of Lua is also it’s large range of implementations. The original implementation is written in C and is a favourite among video game developers, especially for advanced customizations and plugins. There are versions in Java and .Net to allow for embedding in those ecosystems.

Cancoin uses an implementation named Luerl which is written in Erlang and runs on the amazing BEAM virtual machine. This implementation allows us a number of benefits over other Lua implementations. These benefits include: Immutable lua environments, per-processor run queues, per-process reduction counting, and a preemptive scheduler with execution priority.

Script examples

Simple

Create your price from a bitcoin currency variable and add a margin.

local margin = 1.04
my_price = USD * margin
return my_price
View live script

Exchange based

Create your price from a bitcoin exchange variable and add a margin.

local margin = 1.04
my_price = btceUSD * margin
return my_price
View live script

Return min

Return the min value from a set of integers (variables) and add a margin.

local margin = 1.04
price = min(USD, USD_7d_avg)
myprice = price + margin
return price
View live script

Return max

Return the max value from a set of integers (variables) and add a margin.

local margin = 1.04
price = max(USD, USD_7d_avg)
myprice = price + margin
return price
View live script

Flat service fee

Create your price from a market variable with a flat service fee and margin included.

local margin = 1.04
local my_service_fee = 20
price = USD + my_service_fee + margin
return price
View live script

Change price

Return a higher value if the 24 hour change price exceeds a threshold.

local margin = 1.04
local maxprice = 1700
if USD_24h_change_price > 25
 then price = maxprice
else
 price = USD + margin
end
return price
View live script

More information

Try it now:
cancoin.co/price_engine

Learn more about price engine operators and variables:
cancoin.co/price_engine/variables

Learn more about Lua:
Lua.org

Learn more about Luerl:
Luerl on Github

Services
Bitcoin wallet
Every account comes with a free, easy to use multi-sig bitcoin wallet to send, receive and secure your Bitcoins.
LEARN MORE
Bitcoin marketplace
Buy & Sell bitcoins directly from other users with your prefered currency, location, price and payment type.
LEARN MORE
Custom Alerts
Create custom market and listing alerts to get instant price updates sent via SMS, email and more.
LEARN MORE
Cancoin is a peer-to-peer (P2P) bitcoin marketplace and multi-sig (P2SH) wallet service offering quick and secure bitcoin exchanges.
Made in Canada
All content copyright © 2017 Macroverse Inc.
Terms of Service   /   Privacy Policy