0

I have found Reactive very difficult to adopt. I believe my problem is that the examples are too simplistic, so I am unsure how to structure a real-world solution. I am hoping that someone will help me to get over the hump by helping me to solve a real-world problem. I would like to do this in RxPY v3.

The use case is this. You have an infinite stream of stock quotes for multiple stocks coming in with symbol, bid, and ask. You also have a position quantity (how many shares you own) which starts out at zero. The quotes and quantity per stock are infinite observables.

You also have three trigger prices: an entry price, a target price, and a stop price. If your position is zero, then the entry price is active. If the stock price rises to the entry price, then you take the action of buying the stock. That will cause your observable position to change to something greater than zero.

Once your position is greater than zero, the target price and stop price become active. If price rises to the target price, you will take the action of selling the stock for a profit. If the price falls to the stop price, you will take the action of selling the stock for a loss. Either way, your position is then zero again, so the entry price would once again become active.

Is this a good use case for RxPY? If so, could someone please at least show me pseudo-code, if not real code, to implement this? I'm not sure how to approach this. Is it best done in one big expression, or is it somehow the interaction of multiple expressions? Does the action always stay within a never-ending observable chain, or do these things live and die and live and die as the state changes?

Any input very much appreciated.

greymatter
  • 840
  • 1
  • 10
  • 25

1 Answers1

1

With the help of some very good folks in the #rxpy channel of http://pythondev.slack.com (special shout-out to Yev, my RxPY sherpa), I was able to get this working. https://github.com/gargleblaster/rxpy_laboratory

greymatter
  • 840
  • 1
  • 10
  • 25