Git Product home page Git Product logo

Comments (3)

ranaroussi avatar ranaroussi commented on May 18, 2024

There's no strategy initialization in your code, and there's also a ] at the beginning on the instrument=... line. Does it also exist on the code you're running?

Please try running this code and let me know what's the output?

class TestStrategy(Algo):
    def on_start(self):
         pass

    def on_tick(self, instrument):
        print(".", end="")

    def on_bar(self, instrument):
        bar = instrument.get_bar()
        print("\n ==> BAR:", bar)
 
if __name__ == "__main__":
    strategy = TestStrategy(
        instruments = [ "AAPL" ],
        resolution  = "1T" # 1Min bar resolution (Pandas "resample" resolutions)
    )
    strategy.run()

from qtpylib.

 avatar commented on May 18, 2024

Hi Ran. I ran the example you gave.

python print_data.py 
Server Version: 76
TWS Time at connection:20161202 16:42:58 CST
^C......................................................................................................................................................................................................................................................................................................................................

No output. The blotter is working. If I change the 1T to 1K, it works fine.

Another observation that might be related to this issue: I run this code

class TestStrategy(Algo):
    def on_start(self):
         pass

    def on_tick(self, instrument):
        print(".", end="")

    def on_bar(self, instrument):
         print(">", end="")

if __name__ == "__main__":
    strategy = TestStrategy(instruments = [ "AAPL" ], resolution  = "1K")
    strategy.run()

One interesting observation is that nothing was printed until I pressed Ctrl+C. Then all the > and . result appeared. Second observation was that even with sampling K, on_tick is called twice as many as on_bar, which is not as I expected (the frequencies to be same, right?):

python print_data.py 
Server Version: 76
TWS Time at connection:20161202 17:15:58 CST
^C.>..>..>..>..>..>..>..>..>..>..>..>..>..>..>..>..>..>..>..>..>..>..>..>..>..>..>..>..>..>..>..>..>..>..>..>..>..>..>..>..>..>..>.

>>> Interrupted with Ctrl-c...

It is like there is buffering happening and it is dumped when you terminate the process.

from qtpylib.

ranaroussi avatar ranaroussi commented on May 18, 2024

When printing with the end="" parameter, you should add flush=True to have it actually printing... :)

This should work:

from qtpylib.algo import Algo

class TestStrategy(Algo):
    def on_start(self):
         pass

    def on_tick(self, instrument):
        print(".", end="", flush=True)

    def on_bar(self, instrument):
         print(">", end="", flush=True)

if __name__ == "__main__":
    strategy = TestStrategy(instruments = [ "AAPL" ], resolution = "1K")
    strategy.run()

from qtpylib.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.