fenix icon indicating copy to clipboard operation
fenix copied to clipboard

Placing order

Open rajkiranjeet opened this issue 4 months ago • 1 comments

i try to finvasia

Session Created Successfully Error creating session or placing order: Non-base32 digit found below is my code import pyotp from fenix.finvasia import finvasia

TOTP Secret and Credentials

totp_secret = "24242424"

Padding the secret if necessary

def pad_base32_secret(secret): missing_padding = len(secret) % 8 if missing_padding: secret += '=' * (8 - missing_padding) return secret

Pad the TOTP secret

padded_totp_secret = pad_base32_secret(totp_secret)

Generate TOTP Token

try: totp = pyotp.TOTP(padded_totp_secret) totp_token = totp.now() print(f"Generated TOTP Token: {totp_token}")

# Credentials for Finvasia
credentials = {
    "user_id": "FA9",
    "password": "",
    "api_key": "",
    "totp_token": totp_token,
    "imei": "abc1234",
    "vendor_code": "FA9_U"
}

# Step 1: Use Finvasia's create session method (if available)
# The session management will be internal to Finvasia
session = finvasia._session  # Use finvasia's session management
print("Session Created Successfully")

# Step 2: Create headers for the order
headers = finvasia.create_headers({
    "user_id": credentials["user_id"],
    "password": credentials["password"],
    "totpstr": credentials["totp_token"],  # Pass generated TOTP token
    "vendor_code": credentials["vendor_code"],
    "api_key": credentials["api_key"]
})

# Step 3: Place an order using the created session
order_response = finvasia.create_order_eq(
    exchange="NSE",
    symbol="RELIANCE",
    quantity=10,
    side="SELL",
    product="MIS",
    validity="DAY",
    variety="REGULAR",
    unique_id="NSEOrder",
    headers=headers,
    price=2840.0,
    trigger=2845.0
)

print("Order Response:")
print(order_response)

except Exception as e: print(f"Error creating session or placing order: {e}")

can u fnrm whats wrong also can we use this seession for websocket or geting LTP  ?

rajkiranjeet avatar Oct 13 '24 12:10 rajkiranjeet