Skip to main content

SparkLib (0.1.4)

This is rest-api for interacting with https://spark.maticalgos.com . It provides functionalities to manage accounts, strategies, place orders, and much more.

Introduction

This is rest-api for interacting with https://spark.maticalgos.com . It provides functionalities to manage accounts, strategies, place orders, and much more.

User

Authentication with email

Login to SparkLib using your email and password to generate an auth token.

Request Attributes

Attribute Data Type Description
userid* string Email ID of the user.
password* string Password of the user.

Response Attributes

Attribute Data Type Description
access_token string Access token generated by the API
token_type string Type of token generated by the API

Responses

Request samples

from maticalgos.sparkLib import SparkLib

# Example with email and password
userid = "test@gmail.com"
password = "password"

# Initialize the SparkLib object with email and password
spark = SparkLib(userid=userid, password=password)

# Make a request to the API to generate a token
response = spark.generate_token()

# Print the response received from the API
print(response)

Response samples

Content type
application/json
{
  • "access_token": "Your Access Token",
  • "token_type": "bearer"
}

Authentication with API Key

Login to SparkLib using your API Key to generate an auth token.

Request Attributes

Attribute Data Type Description
AuthKey* string API key of the user.

Response Attributes

Attribute Data Type Description
access_token string Access token generated by the API
token_type string Type of token generated by the API

Responses

Request samples

from maticalgos.sparkLib import SparkLib

# Example with API key
AuthKey = "YOUR_API_KEY"

# Initialize the SparkLib object with API key
spark = SparkLib(apikeys=AuthKey)

# Make a request to the API to generate a token
response = spark.generate_token()

# Print the response received from the API
print(response)

Response samples

Content type
application/json
{
  • "access_token": "Your Access Token",
  • "token_type": "bearer"
}

Profile

Get the profile of the user.

Response Attributes

Attribute Data Type Description
status boolean Indicates whether the request was successful
error boolean Indicates whether there was an error
message string A message indicating the result of the request
data array Contains user profile information, including:
ID integer User ID
Name string User's name
Email string User's email address
PhoneNo string User's phone number
LastLogin string Date of the last login , format: 'YYYY-MM-DD'
CreatedOn string Date the account was created , format: 'YYYY-MM-DD'
UCC string User's unique customer code
Disabled string Indicates if the user is disabled
UserType string Type of user (e.g., basic)
AuthKey string Authentication key for the user
acLimit integer Account limit
stLimit integer Strategy limit

Responses

Request samples

from maticalgos.sparkLib import SparkLib

# access_token
access_token = 'eyJ0eXXXXXXXX2c5-Y3RgS8wR14g'

# Initialize the SparkLib object with API key
spark = SparkLib(access_token=access_token)

# Make a request to the API to get the profile
profile = spark.profile()

# Print the response received from the API
print(profile)

Response samples

Content type
application/json
{
  • "status": true,
  • "error": false,
  • "message": "User exists",
  • "data": [
    ]
}

Account

All Accounts

Get All accounts details of the user.

Response Attributes

Attribute Data Type Description
status boolean Indicates whether the request was successful
error boolean Indicates whether there was an error
data array Contains account information, including:
Clientid string Unique identifier for the client
AccountName string Name of the account
LastLogin string Date of the last login , format: 'YYYY-MM-DD'
UCC string User's unique customer code
Trade string Trade information, if any (can be null)
Broker string Broker associated with the account, for more information View Details
message string A message indicating the result of the request

Responses

Request samples

from maticalgos.sparkLib import SparkLib

# access_token
access_token = 'eyJ0eXXXXXXXX2c5-Y3RgS8wR14g'

# Initialize the SparkLib object with API key
spark = SparkLib(access_token=access_token)

# Make a request to the API to get All Accounts associated with the user
all_Accounts = spark.getAllAccounts()

# Print the response received from the API
print(all_Accounts)

Response samples

Content type
application/json
{
  • "status": true,
  • "error": false,
  • "data": [
    ],
  • "message": "Data Received"
}

Single Account

Get details of a specific account.

Query Parameter

Attribute Data Type Description
accountName* string Account name

Response Attributes

Attribute Data Type Description
status boolean Indicates whether the request was successful
error boolean Indicates whether there was an error
data array Contains account information, including:
Clientid string Unique identifier for the client
ApiKey string API key associated with the account
AccountName string Name of the account
LastLogin string Date of the last login
UCC string User's unique customer code
Chatid string Telegram chat ID associated with the account
BotKeys string Telegram bot keys associated with the account
Sessionid string Session ID for the account
Trade string Trade information, if any (can be null)
Broker string Broker associated with the account ,for more information View Details
Redirecturl string Redirect URL for the account
message string A message indicating the result of the request

Responses

Request samples

from maticalgos.sparkLib import SparkLib

# access_token
access_token = 'eyJ0eXXXXXXXX2c5-Y3RgS8wR14g'

# Initialize the SparkLib object with API key
spark = SparkLib(access_token=access_token)

# Make a request to the API to get account details of a single account
single_Account = spark.getOneAccount(accountName='account_name')

# Print the response received from the API
print(single_Account)

Response samples

Content type
application/json
{
  • "status": true,
  • "error": false,
  • "data": [
    ],
  • "message": "Data Received"
}

Generate Authcode For broker account

Generate an auth code for a specific broker account linked with spark.

Query Parameter

Attribute Data Type Description
accountName* string Account name

Response Attributes

Attribute Data Type Description
status boolean Indicates whether the request was successful
error boolean Indicates whether there was an error
data array Contains data response from the API
message string A message indicating the result of the request

Responses

Request samples

from maticalgos.sparkLib import SparkLib

# access_token
access_token = 'eyJ0eXXXXXXXX2c5-Y3RgS8wR14g'

# Initialize the SparkLib object with API key
spark = SparkLib(access_token=access_token)

# Make a request to the API to get account details of a single account
authcode = spark.generateAuthcode(accountName='account_name')

# Print the response received from the API
print(authcode)

Response samples

Content type
application/json
{
  • "status": true,
  • "error": false,
  • "data": [
    ],
  • "message": "Login url generated"
}

Validate Authcode

Validate the auth code for a specific account.

Query Attributes

Attribute Data Type Description
broker* string Broker name ,for more information View Details
authcode* string Auth code

Response Attributes

Attribute Data Type Description
status boolean Indicates whether the request was successful
error boolean Indicates whether there was an error
data array Contains data response from the API
message string A message indicating the result of the request

Responses

Request samples

from maticalgos.sparkLib import SparkLib

# access_token
access_token = 'eyJ0eXXXXXXXX2c5-Y3RgS8wR14g'

# Initialize the SparkLib object with API key
spark = SparkLib(access_token=access_token)

# Make a request to the API to get account details of a single account
Val_authcode = spark.validateAuthcode(authcode=access_token,broker='FYERS')

# Print the response received from the API
print(Val_authcode)

Response samples

Content type
application/json
{
  • "status": true,
  • "error": false,
  • "data": [ ],
  • "message": "Logged in successfully"
}

Validate Session

Update the sessionid for a specific account.

Query Attributes

Attribute Data Type Description
accountName* string Account name
sessionid string Session ID (access_token)

Response Attributes

Attribute Data Type Description
status boolean Indicates whether the request was successful
error boolean Indicates whether there was an error
data array Contains data response from the API
message string A message indicating the result of the request

Responses

Request samples

from maticalgos.sparkLib import SparkLib

access_token = 'eyJ0eXXXXXXXX 2c5-Y3RgS8wR14g'

# Initialize the SparkLib object with API key
spark = SparkLib(access_token=access_token)

# Make a request to the API to get update access token
validate_session = spark.validateSessionid(accountname='account_name',sessionid)

# Print the response received from the API
print(validate_session)

Response samples

Content type
application/json
{
  • "status": true,
  • "error": false,
  • "data": [ ],
  • "message": "session id updated"
}

Activate Account

Activate an account.

Query Attributes

Attribute Data Type Description
accountName* string Account name
activate* string Activate('Y')

Response Attributes

Attribute Data Type Description
status boolean Indicates whether the request was successful
error boolean Indicates whether there was an error
data array Contains data response from the API
message string A message indicating the result of the request
Trade string Trading Active or Inactive

Responses

Request samples

from maticalgos.sparkLib import SparkLib

# access_token
access_token = 'eyJ0eXXXXXXXX2c5-Y3RgS8wR14g'

# Initialize the SparkLib object with API key
spark = SparkLib(access_token=access_token)

# Make a request to the API to activate an account
activate = spark.activateAccount(accountName='account_name',activate='Y')

# Print the response received from the API
print(activate)

Response samples

Content type
application/json
{
  • "status": true,
  • "error": false,
  • "data": [
    ],
  • "message": "Trading activated"
}

Deactivate Account

Deactivate an account.

Query Attributes

Attribute Data Type Description
accountName* string Account name
activate* string Deactivate('N')

Response Attributes

Attribute Data Type Description
status boolean Indicates whether the request was successful
error boolean Indicates whether there was an error
data array Contains data response from the API
message string A message indicating the result of the request
Trade string Trading Active or Inactive

Responses

Request samples

from maticalgos.sparkLib import SparkLib

# access_token
access_token = 'eyJ0eXXXXXXXX2c5-Y3RgS8wR14g'

# Initialize the SparkLib object with API key
spark = SparkLib(access_token=access_token)

# Make a request to the API to deactivate an account
deactivate = spark.activateAccount(accountName='account_name',activate='N')

# Print the response received from the API
print(deactivate)

Response samples

Content type
application/json
{
  • "status": true,
  • "error": false,
  • "data": [
    ],
  • "message": "Trading deactivated"
}

Strategy

All Strategies

Get All strategies details of the user.

Response Attributes

Attribute Data Type Description
status boolean Indicates whether the request was successful
error boolean Indicates whether there was an error
data array Contains strategy information, including:
ID integer Strategy ID
StrategyName string Name of the strategy
Description string Description of the strategy
StrategyType string Type of strategy (Intraday, Positional, etc.)
UCC string User's unique customer code
Display string Display information (Private, Public)
ForwardTest string Forward test information (Y or N)
message string A message indicating the result of the request

Responses

Request samples

from maticalgos.sparkLib import SparkLib

# access_token
access_token = 'eyJ0eXXXXXXXX2c5-Y3RgS8wR14g'

# Initialize the SparkLib object with API key
spark = SparkLib(access_token=access_token)

# Make a request to the API to get All Strategies associated with the user
all_Strategies = spark.getStrategy()

# Print the response received from the API
print(all_Strategies)

Response samples

Content type
application/json
{
  • "status": true,
  • "error": false,
  • "data": [
    ],
  • "message": "Strategy data received"
}

Create Strategy

Create a new strategy.

Request Attributes

Attribute Data Type Description
strategyName* string Name of the strategy
strategyType* string Type of strategy (Intraday, Positional, etc.)
description string Description of the strategy
display string Display information (Private, Public)
forwardTest string Forward test information (Y or N)

Response Attributes

Attribute Data Type Description
status boolean Indicates whether the request was successful
error boolean Indicates whether there was an error
data array Contains data response from the API
message string A message indicating the result of the request

Responses

Request samples

from maticalgos.sparkLib import SparkLib

# access_token
access_token = 'eyJ0eXXXXXXXX2c5-Y3RgS8wR14g'

# Initialize the SparkLib object with API key
spark = SparkLib(access_token=access_token)

# Make a request to the API to add a new strategy
strategy_res = spark.addStrategy(strategyName='test_strategy', Description='This is test strategy', StrategyType='Intraday', Display='Private', ForwardTest='N')

# Print the response received from the API
print(strategy_res)

Response samples

Content type
application/json
{
  • "status": true,
  • "error": false,
  • "data": [ ],
  • "message": "Strategy Added"
}

Modify Strategy

Update an existing strategy.

Query Attribute

Attribute Data Type Description
strategyName* string Name of the strategy

Request Attributes

Attribute Data Type Description
StrategyType* string Type of strategy (Intraday, Positional, etc.)
Description string Description of the strategy
Display string Display information (Private, Public)
ForwardTest string Forward test information (Y or N)

Response Attributes

Attribute Data Type Description
status boolean Indicates whether the request was successful
error boolean Indicates whether there was an error
data array Contains data response from the API
message string A message indicating the result of the request

Responses

Request samples

from maticalgos.sparkLib import SparkLib

# access_token
access_token = 'eyJ0eXXXXXXXX2c5-Y3RgS8wR14g'

# Initialize the SparkLib object with API key
spark = SparkLib(access_token=access_token)

# Make a request to the API to update the strategy
strategy_res = spark.modifyStrategy(strategyName='test_strategy', Description='This is test strategy', StrategyType='Intraday', Display='Private', ForwardTest='N')

# Print the response received from the API
print(strategy_res)

Response samples

Content type
application/json
{
  • "status": true,
  • "error": false,
  • "data": [ ],
  • "message": "Strategy Modified"
}

Delete Strategy

Delete an existing strategy.

Query Attributes

Attribute Data Type Description
strategyName* string Name of the strategy

Response Attributes

Attribute Data Type Description
status boolean Indicates whether the requestuccessful
error boolean Indicates whether there was an error
data array Contains data response from the API
message string A message indicating the result of the request

Responses

Request samples

from maticalgos.sparkLib import SparkLib

# access_token
access_token = 'eyJ0eXXXXXXXX2c5-Y3RgS8wR14g'

# Initialize the SparkLib object with API key
spark = SparkLib(access_token=access_token)

# Make a request to the API to delete a strategy
strategy_res = spark.deleteStrategy(strategyName='test_strategy')

# Print the response received from the API
print(strategy_res)

Response samples

Content type
application/json
{
  • "status": true,
  • "error": false,
  • "data": [ ],
  • "message": "Strategy Deleted"
}

Activate

Activate Account

Activate an account.

Query Attributes

Attribute Data Type Description
accountName* string Account name
activate* string Activate('Y')

Response Attributes

Attribute Data Type Description
status boolean Indicates whether the request was successful
error boolean Indicates whether there was an error
data array Contains data response from the API
message string A message indicating the result of the request
Trade string Trading Active or Inactive

Responses

Request samples

from maticalgos.sparkLib import SparkLib

# access_token
access_token = 'eyJ0eXXXXXXXX2c5-Y3RgS8wR14g'

# Initialize the SparkLib object with API key
spark = SparkLib(access_token=access_token)

# Make a request to the API to activate an account
activate = spark.activateAccount(accountName='account_name',activate='Y')

# Print the response received from the API
print(activate)

Response samples

Content type
application/json
{
  • "status": true,
  • "error": false,
  • "data": [
    ],
  • "message": "Trading activated"
}

Deactivate Account

Deactivate an account.

Query Attributes

Attribute Data Type Description
accountName* string Account name
activate* string Deactivate('N')

Response Attributes

Attribute Data Type Description
status boolean Indicates whether the request was successful
error boolean Indicates whether there was an error
data array Contains data response from the API
message string A message indicating the result of the request
Trade string Trading Active or Inactive

Responses

Request samples

from maticalgos.sparkLib import SparkLib

# access_token
access_token = 'eyJ0eXXXXXXXX2c5-Y3RgS8wR14g'

# Initialize the SparkLib object with API key
spark = SparkLib(access_token=access_token)

# Make a request to the API to deactivate an account
deactivate = spark.activateAccount(accountName='account_name',activate='N')

# Print the response received from the API
print(deactivate)

Response samples

Content type
application/json
{
  • "status": true,
  • "error": false,
  • "data": [
    ],
  • "message": "Trading deactivated"
}

Reconnect Websocket

Reconnect the websocket connection.

Query Attributes

Attribute Data Type Description
accountName* string Account name

Response Attributes

Attribute Data Type Description
status boolean Indicates whether the request was successful
error boolean Indicates whether there was an error
data array Contains data response from the API
message string A message indicating the result of the request

Responses

Request samples

from maticalgos.sparkLib import SparkLib

# access_token
access_token = 'eyJ0eXXXXXXXX2c5-Y3RgS8wR14g'

# Initialize the SparkLib object with API key
spark = SparkLib(access_token=access_token)

# Make a request to the API to reconnect the order websocket
status = spark.reconnect_orderWS(accountName='account_name')

# Print the response received from the API
print(status)

Response samples

Content type
application/json
{
  • "status": true,
  • "error": false,
  • "data": [ ],
  • "message": "Reconnecting to WS"
}

Order Placement

Place Order

Place an order.

Request Attributes

Attribute Data Type Description
strategyname* string Name of the strategy
orderType* string Type of order (Market, Limit,SL-Limit) ,for more information View Details
productType* string Type of product (Intraday,Delivery) ,for more information View Details
token* string Token of the Instrument (eg. NSE:13528)
qty* integer Quantity
transType* string Transaction type (Buy,Sell) ,for more information View Details
limitPrice float Limit price
splitby integer To split order in batches
triggerPrice float Trigger price
ForwardTest boolean Forward test :False
operations object Operations information
timeLimit integer Time limit
shouldExecute boolean Should execute
priceBuffer integer Price buffer
identifier string To execute order in single account ,eg 'UCC:account_name'

Response Attributes

Attribute Data Type Description
status boolean Indicates whether the request was successful
error boolean Indicates whether there was an error
data array Contains data response from the API
message string A message indicating the result of the request
strefID string Strategy reference ID
placedIn string Accounts in which order is placed

Responses

Request samples

from maticalgos.sparkLib import SparkLib

# access_token = 'eyJ0eXXXXXXXX2c5-Y3RgS8wR14g'

# Initialize the SparkLib object with API key
spark = SparkLib(access_token=access_token)

# Make a request to the API to place an order
status = spark.placeorder(strategyName='test_1',
                            orderType='Market',
                          productType='Intraday',
                          token = 'NSE:13528',
                          qty = 1,
                          transType = 'Buy',
                          limitPrice=80,
                          splitby = 0,
                          triggerPrice = 81,
                          forwardTest = False,
                          operations = {"timeLimit": 0,"shouldExecute": False,"priceBuffer": 0},
                          identifier = F000000:test_1)

# Print the response received from the API
print(status)

Response samples

Content type
application/json
{
  • "status": true,
  • "error": false,
  • "data": [
    ],
  • "message": "Order placed in F000000:account_name"
}

Modify Order

Modify an existing order.

Request Attributes

Attribute Data Type Description
strategyname* string Name of the strategy
strefID* string Strategy reference ID
orderType string Type of order (Market, Limit,SL-Limit) ,for more information View Details
limitPrice float Limit price , required for LIMIT order
triggerPrice float Trigger price
identifier string Identifier

Response Attributes

Attribute Data Type Description
status boolean Indicates whether the request was successful
error boolean Indicates whether there was an error
data array Contains data response from the API
message string A message indicating the result of the request
strefID string Strategy reference ID
placedIn string Account in which order is placed

Responses

Request samples

from maticalgos.sparkLib import SparkLib

# access_token = 'eyJ0eXXXXXXXX2c5-Y3RgS8wR14g'

# Initialize the SparkLib object with API key
spark = SparkLib(access_token=access_token)

# Make a request to the API to modify an order
status = spark.modifyorder(strategyName='test_1',
                            orderType='Market',
                          limitPrice=80,
                          triggerPrice = 81,
                          identifier = None,
                          strefID=344,
                        )

# Print the response received from the API
print(status)

Response samples

Content type
application/json
{
  • "status": true,
  • "error": false,
  • "data": [
    ],
  • "message": "Order modified in F000000:account_name"
}

Cancel Order

Cancel an existing order.

Request Attributes

Attribute Data Type Description
strategyname* string Name of the strategy
strefID* string Strategy reference ID
identifier string Identifier

Response Attributes

Attribute Data Type Description
status boolean Indicates whether the request was successful
error boolean Indicates whether there was an error
data array Contains data response from the API
message string A message indicating the result of the request
strefID string Strategy reference ID
placedIn string Account in which order is placed

Responses

Request samples

from maticalgos.sparkLib import SparkLib

# access_token = 'eyJ0eXXXXXXXX2c5-Y3RgS8wR14g'

# Initialize the SparkLib object with API key
spark = SparkLib(access_token=access_token)

# Make a request to the API to cancel the order
status = spark.cancelorder(strategyName='test_1',
                          identifier = 'F000000:test_1',
                          strefID=344,
                        )

# Print the response received from the API
print(status)

Response samples

Content type
application/json
{
  • "status": true,
  • "error": false,
  • "data": [
    ],
  • "message": "Order cancelled in F000000:account_name"
}

Stop Operation

Stop an operation.

Request Attributes

Attribute Data Type Description
strategyname* string Name of the strategy
strefID* string Strategy reference ID

Response Attributes

Attribute Data Type Description
status boolean Indicates whether the request was successful
error boolean Indicates whether there was an error
data array Contains data response from the API
message string A message indicating the result of the request
strefID string Strategy reference ID

Responses

Request samples

from maticalgos.sparkLib import SparkLib

access_token = 'eyJ0eXXXXXXXX2c5-Y3RgS8wR14g'

# Initialize the SparkLib object with API key
spark = SparkLib(access_token=access_token)

# Make a request to the API to cancel the order
status = spark.stopOperation(strategyName='test_1',
                          strefID=344,
                        )

Response samples

Content type
application/json
{
  • "status": true,
  • "error": false,
  • "data": [
    ],
  • "message": "Operations stopped on 344"
}

Cancel All Orders

Cancel all orders of a particular type.

Query Attributes

Attribute Data Type Description
ctype* string Type of commond ('strategy','account')
strategyname* string Name of the strategy
accountName* string Name of the account

Response Attributes

Attribute Data Type Description
status boolean Indicates whether the request was successful
error boolean Indicates whether there was an error
data array Contains data response from the API
message string A message indicating the result of the request

Responses

Request samples

from maticalgos.sparkLib import SparkLib

access_token = 'eyJ0eXXXXXXXX2c5-Y3RgS8wR14g'

# Initialize the SparkLib object with API key
spark = SparkLib(access_token=access_token)

# Make a request to the API to cancel all orders of a strategy
status = spark.CancalAll(ctype='strategy',strategyName='test_1',accountName='test')

# Print the response received from the API
print(status)

Response samples

Content type
application/json
{
  • "status": true,
  • "error": false,
  • "data": [ ],
  • "message": "Request sent to Cancel All Orders in StrategyName : test_1 with AccountName : test"
}

Square Off All Orders

Square off all orders of a particular type.

Query Attributes

Attribute Data Type Description
ctype* string Type of commond ('strategy','account')
strategyname* string Name of the strategy
accountName* string Name of the account

Response Attributes

Attribute Data Type Description
status boolean Indicates whether the request was successful
error boolean Indicates whether there was an error
data array Contains data response from the API
message string A message indicating the result of the request

Responses

Request samples

from maticalgos.sparkLib import SparkLib

# access_token
access_token = 'eyJ0eXXXXXXXX2c5-Y3RgS8wR14g'

# Initialize the SparkLib object with API key
spark = SparkLib(access_token=access_token)

# Make a request to the API to SquareOff all orders of a strategy or account
status = spark.SquareOff(ctype='strategy',strategyName='test_1',accountName='test')

# Print the response received from the API
print(status)

Response samples

Content type
application/json
{
  • "status": true,
  • "error": false,
  • "data": [ ],
  • "message": "Request sent to Square Off all positions in StrategyName : test_1 with AccountName : test"
}

Square Off Single Position

Square off a Single Position.

Query Attributes

Attribute Data Type Description
strategyname* string Name of the strategy
accountName* string Name of the account
token* string Token of the Instrument (eg. NSE:13528)
positionType* string Type of position (Intraday,Delivery)
at_limit* float At limit price(true,false)

Response Attributes

Attribute Data Type Description
status boolean Indicates whether the request was successful
error boolean Indicates whether there was an error
data array Contains data response from the API
message string A message indicating the result of the request
strefID string Strategy reference ID

Responses

Request samples

from maticalgos.sparkLib import SparkLib

# access_token
access_token = 'eyJ0eXXXXXXXX2c5-Y3RgS8wR14g'

# Initialize the SparkLib object with API key
spark = SparkLib(access_token=access_token)

# Make a request to the API to cancel all orders of a strategy
status = spark.squareOffSingle(strategyName='test_1',
                              accountName='account_name',
                              token= 'NSE:13528',
                              positionType='Intraday',
                              at_limit='true'
                                )

# Print the response received from the API
print(status)

Response samples

Content type
application/json
{
  • "status": true,
  • "error": false,
  • "data": [
    ],
  • "message": "Order Placed, Position Squared off"
}

Manual Square Off

Manual Square off a Single Position.

Query Attributes

Attribute Data Type Description
strategyname* string Name of the strategy
accountName* string Name of the account
token* string Token of the Instrument (eg. NSE:13528)
positionType* string Type of position (Buy,Sell)
tradedPrice* float Traded price
tradedAt* string Traded at
qty* integer Quantity
ordersPlaced* integer no of orders placed

Response Attributes

Attribute Data Type Description
status boolean Indicates whether the request was successful
error boolean Indicates whether there was an error
data array Contains data response from the API
message string A message indicating the result of the request

Responses

Request samples

from maticalgos.sparkLib import SparkLib

# access_token
access_token = 'eyJ0eXXXXXXXX2c5-Y3RgS8wR14g'

# Initialize the SparkLib object with API key
spark = SparkLib(access_token=access_token)

# Make a request to the API to cancel all orders of a strategy
status = spark.manualSquareOff(strategyName='test_1',
                              accountName='account_name',
                              token= 'NSE:13528',
                              positionType='Buy',
                              tradedPrice=80,
                              tradedAt='2024-05-24T12:56:45.830Z',
                              qty=1,
                              ordersPlaced=1
                                )

# Print the response received from the API
print(status)

Response samples

Content type
application/json
{
  • "status": true,
  • "error": false,
  • "data": [ ],
  • "message": "Position closed manually"
}

Transaction Info

Order Book

Get the order book details.

Query Parameters

Attribute Data Type Description
accountName string Account name
strategyName string Strategy name
strefid integer Strategy reference ID
reftag integer Reference tag
withorders boolean Include orders of splitby
today boolean Include only today's orders

Response Attributes

Attribute Data Type Description
status boolean Indicates whether the request was successful
error boolean Indicates whether there was an error
data array Contains data response from the API
message string A message indicating the result of the request
UCC string Your Client Code
AccountName string Account name
strefID integer Strategy reference ID
reftag integer Reference tag
StrategyName string Strategy name
orderType string Type of order (Market, Limit,SL-Limit) ,for more information View Details
productType string Type of product (Intraday,Delivery) ,for more information View Details
price float Price
limitPrice float Limit price
triggerPrice float Trigger price
token string Token of the Instrument (eg. NSE:13528)
segment string Segment
symbol string Symbol
qty integer Quantity
transType string Transaction type (Buy,Sell) ,for more information View Details
splitby integer To split order in batches
Operations object Operations information
ordersplaced integer No. of Orders placed
ordersdone integer No. of Order, that are not with status of placed/pending
ordersexecuted integer No. of Orders with status of Executed
placed_at string Placed at
recon_at string Reconciled at
trade_at string Trade at
filledQty integer Filled quantity
tradedQty integer Traded quantity
tradeValue float Trade value
tradePrice float Trade price
status string Status
active integer Active
ForwardTest boolean Forward test information

Responses

Request samples

from maticalgos.sparkLib import SparkLib

# access_token
access_token = 'eyJ0eXXXXXXXX2c5-Y3RgS8wR14g'

# Initialize the SparkLib object with API key
spark = SparkLib(access_token=access_token)

# Make a request to the API to get orderbook
status = spark.orderbook(strategyName='test_1',
                        accountName='test',
                        withorders=False,
                        strefid = None,
                        reftag = None,
                        today = True)

# Print the response received from the API
print(status)

Response samples

Content type
application/json
{
  • "status": true,
  • "error": false,
  • "data": [
    ],
  • "message": "Data Received"
}

Net Position

Retrieve the net position.

Query Attributes

Attribute Data Type Description
Acname string Account name
Stname string Strategy name

Response Attributes

Attribute Data Type Description
status boolean Indicates whether the request was successful
error boolean Indicates whether there was an error
data array Contains data response from the API
message string A message indicating the result of the request
accountName string Account name
bookedpnl float Booked profit and loss
openpnl float Open profit and loss
totalpnl float Total profit and loss
totalpositions integer Total number of positions
openpositions integer Number of open positions

Responses

Request samples

from maticalgos.sparkLib import SparkLib

# access_token
access_token = 'eyJ0eXXXXXXXX2c5-Y3RgS8wR14g'

# Initialize the SparkLib object with API key
spark = SparkLib(access_token=access_token)

# Make a request to the API to get net position
status = spark.netposition(accountName='account_name', strategyName='test_1')

# Print the response received from the API
print(status)

Response samples

Content type
application/json
{
  • "status": true,
  • "error": false,
  • "data": [
    ],
  • "message": "Data Received"
}

Delete Order

Delete an existing order from the database. This action is used to remove the order from spark database.

Query Attributes

Attribute Data Type Description
strefID* string Strategy reference ID
reftag* string Reference tag

Response Attributes

Attribute Data Type Description
status boolean Indicates whether the request was successful
error boolean Indicates whether there was an error
data array Contains data response from the API
message string A message indicating the result of the request

Responses

Request samples

from maticalgos.sparkLib import SparkLib

# access_token = 'eyJ0eXXXXXXXX2c5-Y3RgS8wR14g'

# Initialize the SparkLib object with API key
spark = SparkLib(access_token=access_token)

# Make a request to the API to delete an order
status = spark.deleteOrder(strefID= 355,
                        reftag =425 )

# Print the response received from the API
print(status)

Response samples

Content type
application/json
{
  • "status": true,
  • "error": false,
  • "data": null,
  • "message": "Order Deleted"
}

Overview

Retrieve the account overview.

Query Attributes

Attribute Data Type Description
acname* string Account name

Response Attributes

Attribute Data Type Description
status boolean Indicates whether the request was successful
error boolean Indicates whether there was an error
data array Contains data response from the API
AccountName string Account name
Broker string Broker name associated with the account ,for more information View Details
ClientID string Client ID
Trade string Indicates if trading is allowed ('Y' or 'N')
LastLogin string Last login date
totalStrategy integer Total number of strategies
runningStrategy integer Number of running strategies
CapitalDeployed float Capital deployed
bookedpnl float Booked profit and loss
openpnl float Open profit and loss
totalpnl float Total profit and loss
totalpositions integer Total number of positions
openpositions integer Number of open positions
message string A message indicating the result of the request

Responses

Request samples

from maticalgos.sparkLib import SparkLib

# access_token
access_token = 'eyJ0eXXXXXXXX2c5-Y3RgS8wR14g'

# Initialize the SparkLib object with API key
spark = SparkLib(access_token=access_token)

# Make a request to the API to get the overview
status = spark.overview(accountName='test')

# Print the response received from the API
print(status)

Response samples

Content type
application/json
{
  • "status": true,
  • "error": false,
  • "data": [
    ],
  • "message": "Data Received"
}

Execution Logs

Retrieve the execution logs.

Response Attributes

Attribute Data Type Description
status boolean Indicates whether the request was successful
error boolean Indicates whether there was an error
data array Contains data response from the API
Datetime string Date and time of the log entry
UCC string Unique Client Code
Name string Name associated with the log entry
Alert Type string Type of alert (e.g., DEBUG, INFO, ERROR)
Message string Log message
message string A message indicating the result of the request

Responses

Request samples

from maticalgos.sparkLib import SparkLib

# access_token
access_token = 'eyJ0eXXXXXXXX2c5-Y3RgS8wR14g'

# Initialize the SparkLib object with API key
spark = SparkLib(access_token=access_token)

# Make a request to the API to get execution logs
status = spark.excutionLogs()

# Print the response received from the API
print(status)

Response samples

Content type
application/json
{
  • "status": true,
  • "error": true,
  • "data": [
    ],
  • "message": "Data Received"
}

Intraday Pnl

Retrieve the intraday profit and loss.

Query Attributes

Attribute Data Type Description
accountName* string Account name
strategyName* string Strategy name

Response Attributes

Attribute Data Type Description
status boolean Indicates whether the request was successful
error boolean Indicates whether there was an error
data array Contains data response from the API
message string A message indicating the result of the request
Datetime string Date and time of the log entry
PNL float Profit or loss

Responses

Request samples

from maticalgos.sparkLib import SparkLib

# access_token
access_token = 'eyJ0eXXXXXXXX2c5-Y3RgS8wR14g'

# Initialize the SparkLib object with API key
spark = SparkLib(access_token=access_token)

# Make a request to the API to get intraday pnl
status = spark.intradaypnl(accountName='test', strategyName='test_1')

# Print the response received from the API
print(status)

Response samples

Content type
application/json
{
  • "status": true,
  • "error": true,
  • "data": [
    ],
  • "message": "Data Received"
}

Push Trades

Convert orders to trades and push them to the database.

Query Attributes

Attribute Data Type Description
allusers* boolean Push trades for all users

Response Attributes

Attribute Data Type Description
status boolean Indicates whether the request was successful
error boolean Indicates whether there was an error
data array Contains data response from the API
message string A message indicating the result of the request

Responses

Request samples

from maticalgos.sparkLib import SparkLib

# access_token
access_token = 'eyJ0eXXXXXXXX2c5-Y3RgS8wR14g'

# Initialize the SparkLib object with API key
spark = SparkLib(access_token=access_token)

# Make a request to the API to push trades
status = spark.pushtrades()

# Print the response received from the API
print(status)

Response samples

Content type
application/json
{
  • "status": true,
  • "error": false,
  • "data": [ ],
  • "message": "Orders converted to Trades and pushed to database"
}

Trades

Get the trades.

Query Attributes

Attribute Data Type Description
startDate* string Start date ,format: 'YYYY-MM-DD'
endDate* string End date ,format: 'YYYY-MM-DD'
strategyName* string Name of the strategy
accountName* string Name of the account

Response Attributes

Attribute Data Type Description
status boolean Indicates whether the request was successful
error boolean Indicates whether there was an error
data array Contains data response from the API
message string A message indicating the result of the request
UCC string Your Client Code
AccountName string Account name
StrategyName string Strategy name
symbol string Symbol
token string Token of the Instrument (eg. NSE:13528)
entryTime string Entry time
exitTime string Exit time
date string Date of trade ,format: 'YYYY-MM-DD'
transType string Transaction type (Buy,Sell) ,for more information View Details
entryPrice float Entry price
exitPrice float Exit price
qty integer Quantity
PNL float Profit and Loss
entryLTP float Entry LTP
exitLTP float Exit LTP
ForwardTest integer Forward test information
Capital float Capital
PNLper float Profit and Loss percentage
TDno integer Trade number
productType string Type of product (Intraday,Delivery) ,for more information View Details

Responses

Request samples

from maticalgos.sparkLib import SparkLib

# access_token
access_token = 'eyJ0eXXXXXXXX2c5-Y3RgS8wR14g'

# Initialize the SparkLib object with API key
spark = SparkLib(access_token=access_token)

# Make a request to the API to get tradebook
status = spark.tradebook(startDate = '2024-05-01',
                        endDate = '2025-01-31',
                        strategyName = 'test_1',
                        accountName= 'account_name')

# Print the response received from the API
print(status)

Response samples

Content type
application/json
{
  • "status": true,
  • "error": false,
  • "data": [
    ],
  • "message": "Tradebook data received"
}

Delete Trade

Delete a trade.

Query Attributes

Attribute Data Type Description
TDno* integer Trade number to be deleted

Response Attributes

Attribute Data Type Description
status boolean Indicates whether the request was successful
error boolean Indicates whether there was an error
data array Contains data response from the API
message string A message indicating the result of the request

Responses

Request samples

from maticalgos.sparkLib import SparkLib

# access_token
access_token = 'eyJ0eXXXXXXXX2c5-Y3RgS8wR14g'

# Initialize the SparkLib object with API key
spark = SparkLib(access_token=access_token)

# Make a request to the API to delete a trade
status = spark.deleteTrade(TDno=292)

# Print the response received from the API
print(status)

Response samples

Content type
application/json
{
  • "status": true,
  • "error": false,
  • "data": [ ],
  • "message": "Trade Deleted"
}

Instrument Info

Get tokens

Get tokens for specific instrument details.

Query Attributes

Attribute Data Type Description
symbol* string Symbol of the instrument
exchange* string Exchange of the instrument ,for more information View Details
expiry string Expiry date of the instrument in format 'YYYY-MM-DD'
instrument string Type of instrument (e.g., FUT, OPT) ,for more information View Details

Response Attributes

Attribute Data Type Description
status boolean Indicates whether the request was successful
error boolean Indicates whether there was an error
data array Contains data response from the API
token string Token of the instrument
symbol string Symbol of the instrument
name string Name of the instrument
expiry string Expiry date of the instrument
strike integer Strike price of the instrument
lotsize integer Lot size of the instrument
instrumenttype string Type of instrument (e.g., OPTIDX, FUTSTK)
exch_seg string Exchange segment of the instrument ,for more information View Details
tick_size float Tick size of the instrument
message string A message indicating the result of the request

Responses

Request samples

from maticalgos.sparkLib import SparkLib

# access_token
access_token = 'eyJ0eXXXXXXXX2c5-Y3RgS8wR14g'

# Initialize the SparkLib object with API key
spark = SparkLib(access_token=access_token)

# Make a request to the API to get tokens
status = spark.getTokens(symbol='NIFTY', exchange='NFO', instrument='OPT', expiry='2024-06-20')

# Print the response received from the API
print(status)

Response samples

Content type
application/json
{
  • "status": true,
  • "error": false,
  • "data": [
    ],
  • "message": "Data Received"
}

Get expiry dates

Get the expiry dates for options contracts.

Query Attributes

Attribute Data Type Description
symbol* string Symbol of the instrument
exchange* string Exchange of the instrument ,for more information View Details
instrument* string Type of instrument (e.g., FUT, OPT) ,for more information View Details

Response Attributes

Attribute Data Type Description
status boolean Indicates whether the request was successful
error boolean Indicates whether there was an error
data array list of expiry dates in format 'YYYY-MM-DD'
message string A message indicating the result of the request

Responses

Request samples

from maticalgos.sparkLib import SparkLib

# access_token
access_token = 'eyJ0eXXXXXXXX2c5-Y3RgS8wR14g'

# Initialize the SparkLib object with API key
spark = SparkLib(access_token=access_token)

# Make a request to the API to get expiry dates
status = spark.getExpiry(symbol='NIFTY', exchange='NFO', instrument='OPT')

# Print the response received from the API
print(status)

Response samples

Content type
application/json
{
  • "status": true,
  • "error": false,
  • "data": [
    ],
  • "message": "Data Received"
}

Get freeze quantity

Get the freeze quantity for a specific symbol.

Query Attributes

Attribute Data Type Description
symbol* string Symbol for which freeze quantity is to be retrieved

Response Attributes

Attribute Data Type Description
status boolean Indicates whether the request was successful
error boolean Indicates whether there was an error
data array Contains data response from the API
freezeQty integer Freeze quantity for the specified symbol
message string A message indicating the result of the request

Responses

Request samples

from maticalgos.sparkLib import SparkLib

# access_token
access_token = 'eyJ0eXXXXXXXX2c5-Y3RgS8wR14g'

# Initialize the SparkLib object with API key
spark = SparkLib(access_token=access_token)

# Make a request to the API to get freeze quantity
status = spark.freezeqty(symbol='NIFTY')

# Print the response received from the API
print(status)

Response samples

Content type
application/json
{
  • "status": true,
  • "error": false,
  • "data": [
    ],
  • "message": "Data Received"
}

Contract Master

Retrieve the contract master data. The contract master data contains information about the contracts available for trading. It is in csv format with the following columns:

Column Name Data Type Description
token integer Token of the Instrument
symbol string Symbol of the Instrument
name string Name of the Instrument
expiry string Expiry date of the contract ,format: 'YYYY-MM-DD'
strike float Strike price of the contract
lotsize integer Lot size of the contract
instrumenttype string Type of instrument (e.g., OPTIDX, FUTSTK)
exch_seg string Exchange segment of the contract ,for more information View Details
tick_size float Tick size of the contract

Responses

Request samples

from maticalgos.sparkLib import SparkLib

# access_token = 'eyJ0eXXXXXXXX2c5-Y3RgS8wR14g'

# Initialize the SparkLib object with API key
spark = SparkLib(access_token=access_token)

# Make a request to the API to get contract master data
status = spark.contractMaster()

# Print the response received from the API
print(status)

Response samples

Content type
application/json
{
  • "status": true,
  • "error": false,
  • "data": [
    ],
  • "message": "Data Received"
}

Isholiday

Check if today is a holiday for the specified exchange.

Query Attributes

Attribute Data Type Description
exch* string Exchange (NSE,NFO) ,for more information [View Details](#tag/Appendix/Exchanges

Response Attributes

Attribute Data Type Description
status boolean Indicates whether the request was successful
error boolean Indicates whether there was an error
message string A message indicating the result of the request
data array Contains data response from the API
holiday boolean Indicates if today is a holiday

Responses

Request samples

from maticalgos.sparkLib import SparkLib

# access_token
access_token = 'eyJ0eXXXXXXXX2c5-Y3RgS8wR14g'

# Initialize the SparkLib object with API key
spark = SparkLib(access_token=access_token)

# Make a request to the API to check if today is a holiday
status = spark.isHoliday(exch='NSE')

# Print the response received from the API
print(status)

Response samples

Content type
application/json
{
  • "status": true,
  • "error": false,
  • "message": "Today is a holiday.",
  • "data": [
    ]
}

WebSocket

Order Websocket

Establish a websocket connection to receive order data.

To connect to order websocket, the below input params are mandate

WebSocket endpoint: wss://apiv.maticalgos.com/orderWS?token=YOUR_ACCESS_TOKEN

Here, we are making a connection with order websocket with parameters and callback functions on_order, on_error, on_close, on_open, which are required in the Python socket connection library used. Sample callback function is shared below.

Callback Functions

Function Description
on_order Callback function to handle order data
on_error Callback function to handle error data
on_close Callback function to handle close data
on_open Callback function to handle open data

Request Attributes

Attribute Data Type Description
token* string Access token

Response Attributes

Attribute Data Type Description
type string Type of data ( General,OrderUpdate )
data array Contains data response from the API
message string A message indicating the result of the request
strefID integer Strategy reference ID
UCC string Unique client code
AccountName string Account name
StrategyName string Strategy name
qty integer Quantity
productType string Type of product (Intraday,Delivery) ,for more information View Details
token string Token of the Instrument (eg. NSE:13528)
price float Price
limitPrice float Limit price
reftag integer Reference tag
placed_at string Date and time of order placement
orderType string Type of order (Market,Limit) ,for more information View Details
triggerPrice float Trigger price
transType string Transaction type (Buy,Sell) ,for more information View Details
filledQty integer Filled quantity
status string Order status , for more information View Details
tradePrice float Trade price
orders array Order details
orderid string Order ID
placed boolean Indicates if order is placed
changed boolean Indicates if order is changed
segment string Segment
splitby integer To split order in batches
active boolean Indicates if order is active
ordersexecuted integer Number of orders executed
ordersdone integer Number of orders done
ordersplaced integer Number of orders placed
operations array Operations details
timeLimit integer Time limit
shouldExecute boolean Indicates if order should be executed
priceBuffer float Price buffer
symbol string Symbol of the Instrument

Responses

Request samples

from maticalgos.sparkLib import OrderSocket
import time

def on_order(message):
    print('test message', message)

def on_error(error):
    print('test_error', error)

def on_close():
    print("### closed ###")

def on_open():
    print(" test on_open called")

access_token  = 'eyJ0eXXXXXXXX2c5-Y3RgS8wR14g'


order = OrderSocket(access_token=access_token,
                    on_order=on_order,
                    on_error=on_error,
                    on_close=on_close,
                    on_connect=on_open,
                    reconnect=True,
                    max_reconnect_attempts=20,
                    run_background=True
                    )
order.connect()
time.sleep(20)
order.close_connection()

Response samples

Content type
application/json
{
  • "status": true,
  • "error": false,
  • "data": [
    ],
  • "message": "Data Received"
}

Appendix

Brokers

Broker Description
FYERS FYERS Broker
IIFL IIFL Broker
testBroker Test Broker for paper trading

Exchanges

Exchange Description
NSE National Stock Exchange
BSE Bombay Stock Exchange
NFO NSE Futures and Options
BFO BSE Futures and Options
MCX Multi Commodity Exchange (coming soon)

Product Types

Product Types Description
Delivery Delivery of instruments
Intraday Intraday trading

Order Types

Order Types Description
Limit Limit order
Market Market order
SL-Limit Stoplimit order (SL-L)

Order Status

Order Status Description
Cancelled Order is cancelled
Executed Order is executed
Rejected Order is rejected
Pending Order is pending
Placed Order is placed

Transaction Type

Trans Type Description
Buy Buy order
Sell Sell order

Instrument Type

Instrument Type Description
FUT Futures
OPT Options