How to pull data from a socket connection into Execute?
Author: jduke
Creation Date: 6/14/2020 7:22 PM
profile picture

jduke

#1
Hi there,

I have been working on pulling a few different data sources into my Execute logic, and am very grateful for the excellent example for using APIs such as:
https://www.wealth-lab.com/Forum/Posts/Web-Scraping-Free-Cash-Flow-from-Marketwatch-com-38723

My challenge is that I have data that is coming via a socket and I would like to read all the new data from that has come in since the last bar, and use it to make trade decisions for the coming bar. This is a realtime example, so not needed for historical just live streaming strategy.

Basically my first test objective is to have it just PrintDebug out in real-time each line it gets from the socket connection, regardless of whether it is at the beginning, middle, or end of a bar.

My example code is pretty barebones, and may not even be the right approach at all. Any help would be much appreciated.

CODE:
Please log in to see this code.


I am running into a couple of challenges:

1) I'd like it to open the socket just once (I imagine some global variable as in the above FCF example would help, but I can't quite figure it out)

2) It does not seem to PrintDebug until I manually close the socket server application, then it prints out everything it has been gathering.

Once I have these figured out, I will start working on actually using the content of the stream to Buy/Sell at bar+1.

Thanks!

ps. I can make changes to the socket server side code as well if that helps.




profile picture

Eugene

#2
Hi,

PrintDebug() will not print all without FlushDebug() but it's the least problem. I think you're not approaching it correctly. Here's how the process is in Wealth-Lab:

1. A complete bar updates (can be 1-minute, 1-day, etc.)
2. Your strategy executes over all the bars in the chart and determines if it wants to trade on the next bar.
... a. If it doesn't, you don't do anything.
... b. If it does, you place orders for the next bar and they're worked by your broker. (Process complete).


Consequently, a WealthScript Strategy is not meant to stay resident reading from a Stream. It will not work. What you'd really want here is build a streaming data provider for updating ticks or partial bar:

API | Creating Streaming Data Providers for Wealth-Lab 6 (requires approved Wiki username)

That Extension would have to be chosen instead of the Fidelity/Yahoo streaming provider in WL's Preferences.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).