Signal-to-Order Pipeline¶

Open In Colab

Poll a signal source and dry-run dispatch to an OMS.

Part 18 of 20 in the ServLoci algo/options trading notebook series — full index in notebooks/README.md.

Setup¶

# Get your dedicated static IPv6 + SOCKS5 credentials free:
#   https://comm.servloci.in/register        (or /auth/google?free=1 for an instant trial)
# Your api_key / api_secret pair shows up in the portal after signup:
#   https://comm.servloci.in/user
!pip install -q "requests[socks]"
!curl -sL https://comm.servloci.in/sdk/servloci.py -o servloci.py

import os
from servloci import ServLoci

SERVLOCI_API_KEY = os.environ.get("SERVLOCI_API_KEY", "dhan:1000000001")   # broker:client_id
SERVLOCI_API_SECRET = os.environ.get("SERVLOCI_API_SECRET", "")            # from the portal — leave blank to run this notebook in demo mode

sl = None
if SERVLOCI_API_SECRET:
    sl = ServLoci(api_key=SERVLOCI_API_KEY, api_secret=SERVLOCI_API_SECRET)
    print("ServLoci configured:", sl.host, sl.port)
else:
    print("SERVLOCI_API_SECRET not set — running in demo mode (no live proxy calls).")

A poll → signal → dispatch skeleton. Swap check_signal() for your real source (indicator, model, webhook) and oms for a live OrderManager (notebook 16).

import time

def check_signal():
    """Replace with your real signal source."""
    return "BUY"  # | "SELL" | "HOLD"

def dispatch(signal, oms=None, dry_run=True):
    if signal == "HOLD":
        return None
    order = {"symbol": "NIFTY24800CE", "transaction_type": signal, "quantity": 75, "order_type": "MARKET", "product": "INTRADAY"}
    if dry_run or oms is None:
        print("[DRY RUN] would place:", order)
        return order
    return oms.place(order)

DRY_RUN = True  # flip to False only once OMS + credentials are wired and tested end-to-end
for _ in range(3):  # demo: 3 polls instead of an infinite loop
    dispatch(check_signal(), dry_run=DRY_RUN)
    time.sleep(1)

« Previous: Paper Trading Loop
Next: Capstone: End-to-End Algo Bot »

Try the concepts above interactively: Options Strategy Builder · Docs · Get your static IP