Pinakin System - Some Pythonic Insights

Pinakin is an API-based trading terminal that allows users to perform a variety of operations related to trading and analysis. In addition to supporting various brokers, Pinakin also integrates with popular third-party systems such as Sensibull, Chartink, Tradingview, and Screener.

This allows users to access a wide range of tools and features for trading and analysis, all within a single platform. Pinakin’s API-based architecture also provides flexibility and customization options for advanced users who want to build their own trading strategies or integrate with other systems.

Here is a quick insight on how multivariate global functions are handled as discussed in quant channel.

def positions(broker,first_name,last_name):        
    func = globals()[broker+"_positions"]
    return func(first_name,last_name)


def iifl_positions(first_name,last_name):
    print("hello1"+first_name+last_name)

def paisa_positions(first_name,last_name):
    print("hello2"+first_name+last_name)

positions("iifl"," amit"," ghosh")

This is method 1

def iifl_positions(first_name, last_name):
    print("Hello1 " + first_name + " " + last_name)

def paisa_positions(first_name, last_name):
    print("Hello2 " + first_name + " " + last_name)

broker_functions = {
    "iifl": iifl_positions,
    "paisa": paisa_positions
}

def positions(broker, first_name, last_name):
    if broker in broker_functions:
        return broker_functions[broker](first_name, last_name)
    else:
        print("Broker not supported")

positions("iifl", "Amit", "Ghosh")
positions("paisa", "John", "Doe")

This is method 2

def iifl_positions(first_name, last_name):
    print("Hello1 " + first_name + " " + last_name)

def paisa_positions(first_name, last_name):
    print("Hello2 " + first_name + " " + last_name)

broker_functions = {
    "iifl": iifl_positions,
    "paisa": paisa_positions
}

def positions(broker, first_name, last_name):
    if broker in broker_functions:
        return broker_functions[broker](first_name, last_name)
    else:
        print("Broker not supported")

positions("iifl", "Amit", "Ghosh")
positions("paisa", "John", "Doe")

This is method 3.

But the drawback in these is, it can not handle optional arguments. For say, this following code will land in error.

import inspect

def iifl_positions(first_name, last_name, account_id="123"):
    print("Hello1 " + first_name + " " + last_name + " " + account_id)

def paisa_positions(first_name, last_name, user_id):
    print("Hello2 " + first_name + " " + last_name + " " + user_id)

broker_functions = {
    "iifl": (iifl_positions, ["first_name", "last_name", "account_id"]),
    "paisa": (paisa_positions, ["first_name", "last_name", "user_id"])
}

def positions(broker, **kwargs):
    if broker in broker_functions:
        func, arg_names = broker_functions[broker]
        if set(kwargs.keys()) == set(arg_names):
            kwargs = {arg_name: kwargs[arg_name] for arg_name in arg_names}
            return func(**kwargs)
        else:
            print(f"Expected arguments for {broker}: {arg_names}")
    else:
        print(f"Broker {broker} not supported")

positions("iifl", first_name="Amit", last_name="Ghosh")
positions("paisa", first_name="John", last_name="Doe", user_id="456")

In this case I use inspect.signature to get full list of parameters.

import inspect

def iifl_positions(first_name, last_name, account_id="123"):
    print("Hello1 " + first_name + " " + last_name + " " + account_id)

def paisa_positions(first_name, last_name, user_id=None):
    print("Hello2 " + first_name + " " + last_name + " " + str(user_id))

broker_functions = {
    "iifl": (iifl_positions, ["first_name", "last_name", "account_id"]),
    "paisa": (paisa_positions, ["first_name", "last_name", "user_id"])
}

def positions(broker, **kwargs):
    if broker in broker_functions:
        func, arg_names = broker_functions[broker]
        sig = inspect.signature(func)
        bound_args = sig.bind(**kwargs)
        bound_args.apply_defaults()
        kwargs = dict(bound_args.arguments)
        if set(kwargs.keys()) == set(arg_names):
            kwargs = {arg_name: kwargs[arg_name] for arg_name in arg_names}
            return func(**kwargs)
        else:
            print(f"Expected arguments for {broker}: {arg_names}")
    else:
        print(f"Broker {broker} not supported")

positions("iifl", first_name="Amit", last_name="Ghosh")
positions("paisa", first_name="John", last_name="Doe", user_id="456")
positions("paisa", first_name="Jane", last_name="Doe")

The correct method. Now this becomes easier when you do multiprocess

Can Pinakin do PMS/Portfolio Management?

As in aka smallcase like library system without the headaches of smallcase?

Smallcase is a scam. They curvefit the data to fit the best return outcome when demonstrating a smallcase; that’s why you see different deploy date for all smallcase.

A minor thing like investing before stock market crash and just after the crash makes huge difference in the results.

Pinakin automates index. Many of my clients who have signed up using the links of https://www.unofficed.com/partner avail this service for free. Most does SIP.

90% mutual funds fail to beat the index. So why re-invent the wheel and why not just dump money in the index. Check niftyindices website; there are fantastic indexes like NIFTY Growth which has 22% CAGR since inception and haircut of those stocks are above 75%.

Automating the index using Python = Better than 90% PMS. Plus you can run toothless wheel strategy and stuff.

I have tried my fair share of automating various volatility spread, time based this that and many stuff. But in a small capital, broker’s mistake and nuisance overrides all such strategy. One error from order mis management wipes out 3-4 months’ entire capital.

But in bigger capital things run fine.

1 Like

:heart_eyes: :two_hearts:

trying to re-read the last para… could not understand the above. Could you please elaborate a little more here @dexter ?

OTOH, I think an OSS library for a smallcase like problem/solution is very much needed – how do you tangle around the FIFO, multiple (virtual) portfolio on a single demat account with a broker which has couple of stocks overlapping?

The solutions I developed to get me benefit in this system has got me tangled into multiple FIRs and multiple arrests.

You can hunt in court orders which are public. The less I speak on the details of them as they are still good working method, the more better

Here is a tip → How deep you know about NSE’s different type of leased lines?

Who is in in charge of those leased lines? Private company?

Can you get any benefit if you know any employee of that company?

Is there any port where things are steamed with slight faster?

Every info is online.Harsad found his loophole. You find yours.

:pray:

You are much more than what you say.

You can now do it. After a recent legal issue last month, I had registered PVT LTD and threw the system in public; not the responsibility lies with the one who uses it. not me.