Add Bitvavo broker support and paper trading#20
Conversation
- Add broker abstraction layer (brokers/ module) - Implement RobinhoodBroker and BitvavoBroker classes - Add broker selection dropdown in GUI settings - Add Bitvavo API setup wizard in settings dialog - Update pt_trader.py to use broker interface - Add python-bitvavo-api to requirements.txt Supports EUR trading pairs for Bitvavo (BTC-EUR, ETH-EUR, etc.) while maintaining full Robinhood compatibility (USD pairs).
- Add PaperBroker class for simulated trading without real money - Uses real market prices but executes virtual trades - Persists state to paper_trading_state.json (survives restarts) - Add paper trading toggle and balance setting in GUI - Track virtual balance, holdings, and trade history - Calculate performance metrics (P&L, win rate) Perfect for testing strategies before using real funds.
|
I had a quick look at your abstraction implementation. A few short comments....
I see what you did with the init file. I think executing these methods during import obscures this functionality.
I would not say that abstraction has been properly achieved here. It is still rather brute force, what you have done is implement a selector switch that runs during import. Adding more exchanges would be increasing this list of methods. You have _create_robinhood_broker() and _create_bitvavo_broker() Otherwise I can see that broker implementations do suitably inherit from the BrokerAPI.
A good start to creating a base class. The base class should have all the methods that are common to each instance. Child classes then implement the specifics and subtle differences. Declaring abstract methods in the base class then forces the implementation in the child class. For example the base class can declare a method get_price(token) and then implementing a new interface would require the child class to define the implementation. Lets say I want to add the Kraken exchange. I would define a new class KrakenInterface and it would inherit from and extend the Broker base class, and it would implement the get_price() method for Kraken. I can see this structure in your code. I recommend creating some folders to separate things hierarchically.
As you can see in the main branch, there are a couple of files that are many thousands of lines of code, implementing mixture of many functions and methods that are unrelated and in random order. It is in desperate need of breaking up into to pieces and smaller supporting classes. Implementing an abstract interface likely will grow in complexity, so thought should be given to defining it as a composition of various components, and then implementing those component in subclasses. As an example you have 'factory functions' in the init file. A good base class should implement all of the high level methods required for interacting with an object and its data. Self initialisation and configuration is common. However if that itself became complex enough, separating the creation could make sense so the init() method does not grow to be too large and complex. This would be an appropriate time to implement a factory class that can be used by the top level application. The factory class would handle everything required to be done to create and configure a Broker() object. main() --> calls factory create broker It may further be best to break this down some more. For example create a Interface base class. In this example the Broker would be performing the information arbitrage between the Application and the Interface. In some works the session and interface could all be in one class, but this kind of stuff is sensitive enough that it will grow in size considerably, so implementing the separation of concern from the start is best. Like, you could try and implement both a polling and streaming interface from the application and you would see quickly that a component would be required to handle the runtime operations as its main focus.
Overall the abstraction is there at the lower level, but I would think about further abstracting the relationship between the application on the broker side. Also would be best to take the code out of the init file and build a separate factory. I would accept the PR given the assumption development of the interface would continue. |
sjackson0109
left a comment
There was a problem hiding this comment.
I've got a sister project underway here https://github.com/sjackson0109/PowerTraderAI
If you are interested, i'd like to PR your branch, and support you in joining a couple of us working on this together.
As much as we love @garagesteve1155 for the project he has on offer; he's made his position clear, that he is happy to let other members manage their own forks. So that is what i'm doing. You're welcome to come along...
Summary
Features
Bitvavo Integration
Paper Trading
Files Changed
brokers/base.py- Abstract broker interfacebrokers/robinhood.py- Robinhood implementation (extracted from pt_trader.py)brokers/bitvavo.py- Bitvavo implementation using official SDKbrokers/paper.py- Paper trading simulatorbrokers/__init__.py- Factory function with paper trading supportpt_trader.py- Updated to use broker abstractionpt_hub.py- Added broker selection, Bitvavo setup, and paper trading togglerequirements.txt- Added python-bitvavo-apiTest plan