Jump to content

Adjust stopLevel using streaming api data


Recommended Posts

Posted (edited)

Hi, I am trying to update the stops for an existing order using the streaming API.  Working / fledgling code so far:

import time

from ig_streaming_client import IgStreamingSession
from lightstreamer_client import LightstreamerSubscription
api_key = ""; account_id = ''; rest_api_username = ""; rest_api_password = ""

session = IgStreamingSession(api_key, account_id, rest_api_username, rest_api_password)

subscription = LightstreamerSubscription('MERGE',
                                         ['MARKET:CS.D.BITCOIN.TODAY.IP'],
                                         ['UPDATE_TIME', 'BID', 'OFFER'])

print(subscription.addlistener(lambda item: print(item['values']['OFFER']))) #####thisone
session.subscribe(subscription)

time.sleep(10)

session.log_out()

This successfully prints out the latest offer prices for 10 seconds. However, I am struggling to figure out how to take the real time offer values from the streaming data and check against my current order stopLevel and change the stopLevel if the streaming offer price goes below my threshold.

For the #####thisone line above, I am needing something like this (58000 is my threshold):

if subscription.addlistener(lambda item: item['values']['OFFER']) < 58000:
    ig_service.update_open_position(limit_level = None, stop_level = 58100, deal_id = dealId)

Massive gap in my streaming api knowledge I accept but any help would be appreciated.  There does not seem to be much out there that uses streaming data and "does stuff" with the outputs, apart from displaying in an html of course.

Edited by wki
Posted

ok I think I have figured out how to extract the value from lightstreamer and then do something with it.  I pass the streaming item through a function that extracts the appropriate value from the item, adds this value to a list, looks at the last item of that list and does something based on that value. Seems to work ok...

lst = []
def add2list(item):
    val = float(item['values']['OFFER'])
    lst.append(val)
    if lst[-1] < 58000:
        return print('below',lst[-1])
    else:
        return print('above',lst[-1])

session = IgStreamingSession(api_key, account_id, rest_api_username, rest_api_password)

subscription = LightstreamerSubscription('MERGE',
                                         ['MARKET:CS.D.BITCOIN.TODAY.IP'],
                                         ['UPDATE_TIME', 'BID', 'OFFER'])
subscription.addlistener(lambda item: add2list(item))

  • 9 months later...
Posted

Hey,

See you are using the same a me and am wondering about two things:

1) do you know how to unsubscribe from the subscription just made
2) how to update the subscription eg. from bitcoin to ethereum

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • image.png

  • Posts

    • I’ve been exploring RWA (Real-World Asset) projects to focus on this festive season. Currently, I hold ONDO and QNT, but INK Finance (Quill) has caught my attention due to its robust and versatile features. Here’s why:     INK Finance acts as financial infrastructure for protocols, DAOs, and RWA originators, enabling them to:   - Earn yield.   - Manage treasuries.   - Tokenize real-world assets (RWAs) with a focus on compliance and integrity.     The platform provides a scalable solution for web3 DAOs, protocols, and asset managers, empowering them to:   - Customize asset management and governance frameworks through a no-code interface.   - Establish on-chain credit and financial competence.     INK Finance offers a comprehensive, frictionless solution for organized financial activities, combining scalability and customizability.     With its token now available on BingX Spot, I’m planning to take a position around the support zone, that is being respected, looking at the chart below, if the price of QUILL break my bearish trendline on the chart, I will ape in to hold long term, with the current market trend and how are are going into the altcoin season, I'm hoping it'll break the ATH. Trade QUILL Here Sign up on BingX Here  
    • I tried out Ink Finance ($QUILL), and it feels like a game changer for anyone managing DAOs or looking into RWA tokenization and with the no-code framework makes it super accessible, even for traders like me. Also, seeing how it bridges traditional finance and Web3 has been eye-opening and It’s amazing how far DeFi tools have come this one looks tailored for scalability and compliance. Currently listed on BingX, and I’m excited to see where it goes from here. If you’re into DAOs or crypto governance, this is worth checking out.  
    • SP500 (SPX), NASDAQ 100 (NDX), Apple (AAPL), Tesla (TSLA), Amazon (AMZN), Nvidia (NVDA), Microsoft (MSFT), Meta Platforms (META), Netflix (NFLX), Alphabet (GOOGL), Bitcoin (BTC). Stock market Elliott Wave technical analysis and trading strategies: Risk on for stocks and Indices. SP500 supported on 6000 and the Nasdaq supported on 20,000 with many stocks pushing up of their current lows with Impulse structures. Elliott Wave Analysis NASDAQ Tech Stocks:  SP500 (SPX): Wave (iii) of iii) of 5 of (5) of 3) NASDAQ 100 (NDX) Wave (iii) of iii) of 5 of (5) of 3) Apple (AAPL): Wave (iii) of iii) of 3 Amazon (AMZN): Wave  (i) of v) of 3 NVIDIA (NVDA): Wave i) of 5 Meta Platforms (META): Wave iii) of 5 Netflix (NFLX): Wave i) of 5 Alphabet (GOOGL): Working two counts Microsoft MSFT: If a Classic Trading levels pattern is created on Minor Group 1 430 then we can move in long. Tesla (TSLA): Wave (i) of v) Risk On  Bitcoin: (BTC): Wave 4 Financial Events JOLTS Job Openings ADP Non-Farm Employment Change Video Chapters 00:00 SP500 (SPX) 03:16 NASDAQ 100 (NDX) 05:53 Apple (AAPL) 12:08 Amazon (AMZN) 15:43 NVIDIA (NVDA) 20:26 Meta Platforms (META) 22:26 Netflix (NFLX)  24:19 Alphabet (GOOGL) 26:04 Microsoft MSFT 27:11 Tesla (TSLA) 28:35 Bitcoin 31:48 End Analyst Peter Mathers TradingLounge™  Source: tradinglounge.com     
×
×
  • Create New...
us