Coder Social home page Coder Social logo

asthatech / jsvortex Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 1.0 398 KB

NodeJS SDK to trade with AsthaTrade

Home Page: https://asthatrade.com/vortex

JavaScript 2.75% TypeScript 21.97% Makefile 0.02% HTML 73.62% CSS 1.64%
broker broker-api brokerage nse nse-stock-data stock-market stocks stocks-api stocks-prices stocks-trading trading

jsvortex's Introduction

Vortex API NodeJS Client

Official javascript client for communicating with Vortex API

Vortex APIs are meant for clients who want to execute orders based on their own strategy programatically and for partners to build their own applications. These apis provide a fast and secure way to place trades, manage positions and access real time market data.

Documentation

Installation

Install via npm

npm i @asthatrade/jsvortex@latest

Usage

The api methods always return a promise which you can use to call methods like .then(...) and .catch(...). Refer: Promises

Getting Started with APIs

var VortexAPI = require("@asthatrade/jsvortex").VortexAPI
var Constants = require("@asthatrade/jsvortex").Constants

var client = new VortexAPI("api_secret","application_id")


client.login("client_code","password","totp").then(async (res)=> {
    await run()
}).catch((err)=>{
    console.log(err)
})

async function run(){
    var order_book = await client.orders()
    console.log("order book", order_book)

    var positions = await client.positions()
    console.log("positions",positions)

    client.quotes(["NSE_EQ-22"],Constants.QuoteModes.LTP).then((res)=>{
        return client.place_order(Constants.ExchangeTypes.NSE_EQUITY,22,Constants.TransactionTypes.SELL,Constants.ProductTypes.INTRADAY,Constants.VarietyTypes.REGULAR_MARKET_ORDER,1,res.data["NSE_EQ-22"].last_trade_price,0,0,Constants.ValidityTypes.FULL_DAY)
    })
    .then((res)=>{
        console.log(res)
    }).catch((err)=>{
        console.log(err)
    })
}

Getting started with Feed

var JSONbig = require('json-bigint');

var VortexFeed = require("@asthatrade/jsvortex").VortexFeed
var Constants = require("@asthatrade/jsvortex").Constants

const wire =  new VortexFeed("access_token",true,true)

wire.connect()
wire.on("price_update",onPriceUpdate)
wire.on("order_update", onOrderUpdate)
wire.on("error",onError)
wire.on("close",onClose)
wire.on("connect",onConnect)

function onConnect(){
    wire.subscribe(Constants.ExchangeTypes.NSE_EQUITY,26000,Constants.QuoteModes.OHLCV)
    wire.subscribe(Constants.ExchangeTypes.NSE_EQUITY,26009,Constants.QuoteModes.OHLCV)
}

function onPriceUpdate(updates){
    console.log(JSONbig.stringify(updates))
}

function onOrderUpdate(update){
    console.log(update)
}

function onClose(reason){
    console.log(reason)
}

function onError(reason){
    console.log(reason)
}

Run Tests

yarn test

Generate Docs

yarn generate-docs

jsvortex's People

Contributors

brisingr123 avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

rahulmr

jsvortex's Issues

Websocket Data Not Updating

Hi @brisingr123 when I connected WebSocket I was getting incorrect data and the WebSocket was also not sending the updated price
after some time interval, I have attached the screenshot below of the code that I used and the output that I was getting please take a look at the last_traded_time and the Windows time also
image

Thanks
Shubham Yadav

CORS-Error

Hi Astha Team @brisingr123 ๐Ÿ‘‹

I was getting cors error in one of the endpoint which the quote endpoint
i have also attached the screenshot of error and the code that i used for more details

image
image

Pnl Calculation Issue

@brisingr123 To Calculate the Pnl I Used the method that was shown in the documentation but this method gave incorrect results

`
let positionData = {"exchange":"MCX_FO","symbol":"CRUDEOIL","expiry_date":"2023-08-17","option_type":"CE","token":257369,"product":"INTRADAY","quantity":1,"overnight_buy_value":0,"overnight_sell_value":0,"overnight_average_price":0,"lot_size":100,"multiplier":100,"average_price":17,"value":-1700,"buy_value":3430,"sell_value":1730,"buy_quantity":2,"sell_quantity":1,"buy_price":17.15,"sell_price":17.3}

let ptype = "Long"

let ltp = 19

if (ptype == "Long") {
// when buy position is open
// Gain = (last_trade_price * quantity * lot_size * multiplier +overnight_sell_value ) - overnight_buy_value
let cpnl = (ltp * positionData.quantity * positionData.lot_size * positionData.multiplier + positionData.overnight_sell_value) - positionData.overnight_buy_value
console.log("cpnl for long position", cpnl) }

`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.