API DOCUMENTATION
Publisher JS

Publisher JS Plugin

The Superr Publisher JavaScript plugin allows you to incorporate one-click trade buttons into your webpage. It functions similarly to a basket with a payment gateway, where an inline popup appears on your webpage, guiding users through the trading process and returning them to your page. As mentioned in the section on offsite order execution, it is also possible to retrieve the request_token from this flow to initiate an Superr Connect session.

Using the JavaScript plugin, you can dynamically add one or more stocks to the basket (up to a maximum of 10), or you can embed simple static buttons using plain HTML.

Getting Started

<script src="https://developers.stoxkart.com/publisher.js" />

To include the Superr Publisher plugin on your webpage, simply paste the following script tag at the end of your webpage, just before the closing </body> tag. This code needs to be included only once to render any number of buttons on a page.

HTML Buttons

<superr-button
  data-superr="your-api-key"
  data-exchange="NSE"
  data-tradingsymbol="TATAMOTORS"
  data-action="BUY"
  data-quantity="1"
  data-order_type="LIMIT"
>
  Buy TATAMOTORS
</superr-button>

You can use the custom <superr-button> HTML5 tag to render branded Superr buttons that initiate a trade with a single click. These branded buttons function similarly to social media buttons, and you can include as many as you desire on a page.

Dynamic buttons with JavaScript

// initialize a new SuperrConnect instance with your api key
const superr = new SuperrConnect("your-api-key");
 
// add as many stocks as you want
superr.add({
  exchange: "NSE",
  token: "3456",
  order_type: "LIMIT",
  product_type: "DELIVERY",
  quantity: 1,
  disclose_quantity: 0,
  price: 3475,
  trigger_price: 0,
  stop_loss_price: 0,
  validity: "DAY",
  action: "SELL",
  tradingsymbol: "TATAMOTORS",
});
 
const button = document.querySelector("#custom-button-demo");
 
// one way to make the button dynamic
superr.link(button);
 
// other way to do this
button.addEventListener("click", () => {
  superr.connect();
});

You can create a basket of stocks and utilize the plugin to generate an Superr button that executes the trade, or you can associate the basket with your own button (or any HTML element).

The plugin loads its assets asynchronously, so it is crucial to initialize your custom SuperrConnect calls only after the plugin has been fully loaded. To accomplish this, you should utilize the SuperrConnect.ready() function.

Note

Include your custom code after the publisher.js inclusion. Also, make sure to wrap your code in SuperrConnect.ready()

Paremeters

ParameterDescription
tradingsymbol (*)Tradingsymbol of the instrument
exchange (*)Name of the exchange (eg. NSE, BSE)
action (*)BUY or SELL
quantity (*)Quantity to transact
order_typeOrder type (MARKET, LIMIT, etc.)
varietyOrder variety (regular, amo, co. Defaults to regular)
product_typeMargin product to use for the order (margins are blocked based on this)
priceFor LIMIT orders
trigger_priceFor SL, SL-M, etc.
stoplossFor SL, SL-M, etc.
trailing_stoplossThe trailing stoploss price
target_priceThe target price
disclosed_quantityQuantity to disclose publicly (for equity trades)
validityOrder validity
readonlyDefault is false. If set to true, the UI does not allow the user to edit values such as quantity, price, etc., and they can only review and execute.
tagAn optional tag to apply to an order to identify it (alphanumeric, max 8 chars)

Methods

MethodParametersDescription
SuperrConnect.ready()functionA safe wrapper which takes a callback that runs after synchronously loading all the assets.
add()entryAdds item(s) given in the paramters representing a trading entry to the basket.
link()element_selectorLinks the basket to the given HTML element, and binds an HTML onclick event listener, which when clicked, initiates the order.
connect()-Initiates the order with all the trading entries in the current basket at the time of calling this function.