Giter Site home page Giter Site logo

algobulls / pyalgotrading Goto Github PK

View Code? Open in Web Editor NEW
231.0 7.0 73.0 158.21 MB

Official Python Package for Algorithmic Trading APIs powered by AlgoBulls

Home Page: https://algobulls.github.io/pyalgotrading/

License: MIT License

Shell 0.01% Python 0.14% Jupyter Notebook 99.86%
python algorithmic-trading-strategies backtesting paper-trading real-trading trading-platform algobulls-platform

pyalgotrading's People

Contributors

akhil-jain-algobulls avatar blackfury7 avatar brainzz2285 avatar darshil-chauhan-algobulls avatar eliszbr avatar guanidene avatar hemendra-sakpal-algobulls avatar pratik-urkude-algobulls avatar prithviraj-gotepatil-algobulls avatar pushpakdagade avatar shubham-das-algobulls avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

pyalgotrading's Issues

Alpaca Bug : Attribute Error

Occurred while runnig PT and RT jobs.
Probable cause for this error, data in the queried time is not avaible at alpaca or alpaca is not allowing for trial users

Got this Error 2 times one for PT and one for RT, both on different strategies,
The Instrument given in both the cases was TSLA (this could be a probable cause too if TSLA hist data is not available at Alpaca)

[2023-06-16 22:43:10] Waiting for 49.73 seconds until end of current candle (2023-06-16 13:14:00-04:00)...
[2023-06-16 22:44:08] Received event EXCEPTION. Stopping AlgoBulls Trading Core Engine...
[2023-06-16 22:44:08] Cancelling all open orders (if any)... Starting
[2023-06-16 22:44:08] Ignoring cancel. Order already completed... ac5f856a-678f-48d8-9fb7-429bf6ee8d3a
[2023-06-16 22:44:08] Ignoring cancel. Order already completed... ef17165f-595e-4e65-9908-a2a104b50c97
[2023-06-16 22:44:08] Ignoring cancel. Order already completed... 9a31b38d-066f-4db6-abf0-3e06eece9822
[2023-06-16 22:44:08] Ignoring cancel. Order already completed... f1ffe79e-db4d-4a1c-a9a8-d56aa3dbd04c
[2023-06-16 22:44:08] Ignoring cancel. Order already completed... 55e88853-0e2f-4c13-bafb-59adcdd9b221
[2023-06-16 22:44:08] Cancelling all open orders (if any)... Done
[2023-06-16 22:44:08] Exiting all open positions...
[2023-06-16 22:44:08] Exiting all open positions with order code: ORDER_CODE_INTRADAY (if any)...
[2023-06-16 22:44:23] Querying broker API "get_positions" was unsuccessful even after 10 number of attempts. Please check the above log for exception details
[2023-06-16 22:44:23] [ID:0e33d339377b4d3ca801618f8e4660a7] [SELL] [NASDAQ_EQ:TSLA] Order was exited manually. Not exiting...
[2023-06-16 22:44:23] Exiting all open positions with order code: ORDER_CODE_DELIVERY_T0 (if any)...
[2023-06-16 22:44:23] Exiting all open positions with order code: ORDER_CODE_DELIVERY_T1 (if any)...
[2023-06-16 22:44:23] Exiting all open positions with order code: ORDER_CODE_DELIVERY_T2 (if any)...
[2023-06-16 22:44:23] [User: PA3G7SFZOVVF] Trading session completed
[2023-06-16 22:44:23] Dumping Debug Stack to Python friendly Traceback Format for Python Build Customers: Uncaught exception | Exception Class: <class 'AttributeError'> | Exception Details: 'NoneType' object has no attribute 'items' | Traceback Below:
  File "/usr/local/lib/python3.10/site-packages/alpaca/data/historical/stock.py", line 102, in get_stock_bars
    return BarSet(raw_bars)
  File "/usr/local/lib/python3.10/site-packages/alpaca/data/models/bars.py", line 73, in __init__
    parsed_bars[symbol] = [Bar(symbol, bar) for bar in bars]
  File "/usr/local/lib/python3.10/site-packages/alpaca/data/models/bars.py", line 73, in <listcomp>
    parsed_bars[symbol] = [Bar(symbol, bar) for bar in bars]
  File "/usr/local/lib/python3.10/site-packages/alpaca/data/models/bars.py", line 43, in __init__
    BAR_MAPPING[key]: val for key, val in raw_data.items() if key in BAR_MAPPING

[2023-06-16 22:44:23] An error has occurred due to which the strategy execution cannot proceed anymore. Reason: 'NoneType' object has no attribute 'items'.
If the reason doesn't help, please double check the tweak parameters. If everything seems fine, please checkout https://community.algobulls.com/ or contact [email protected] for support.

Error while uploading strategy to my AlgoBulls account

Algobulls_Error

I was trying to upload the strategy EMA Regular order on my algobulls account so that I can perform some backtesting and generate reports according to the tutorial on pyalgotrading repository but there is some constant error which is stopping me from uploading the strategy to my account in the final step. Kindly help me out with it.

Save parameters from previous backtest run for the papertrade run

  • Once a strategy has been backtested, if a user wants to papertrade on the same strategy for same parameters as backtesting, allow him to just call .papertrade() function with only strategy, start/end times.
  • The other parameters, which are same as BT, should be picked up from BT automatically
  • This issue is taken in this PR: #31

Strategy Parameters could also be none or an empty dictionary

  • If strategy_parameters are set to None then it raises an error in API class.
  • It should be allowed to pass empty or None Parameters when executing the strategy
  • For strategies like "VWAP Crossover" there is no need for strategy_parameters. Hence I want to pass a None or an empty dictionary value

Logs progress bar tracking for BT/PT/RT

  • Implement a feature in fetching the logs feature where we can show a progress bar, so user knows how much BT is done.
  • Use this library to show progress bar: https://github.com/tqdm/tqdm
  • Idea is based on the timestamp we get in logs, and based on start and end timestamp given while BT, we should compute the progress percentage and show in jupyter.
  • Your function should fetch the logs peridocially every 5 seconds. Conect with shubham to know the new logs api which helps fetch only incremental logs (ciurrent api fetches everything in 1 go).
  • Give an option to disable this mode, so in that case the get logs function behaves as it does now.
  • #35

Add brokerage feature

  • Need support for commissions; take reference form backtrader for type of commissions model that we want.
  • There is need to simulate real life situation when fetching the pnl table and generating the statistics.
  • Brokerage feature should be added as this is one of the things that that will help us simulate almost real-life profits and losses.
  • This will also improve the estimation of overall profits for every trade.
  • PR: #32

Following the Pyalgotrading tutorial gives an error

I was following the pyalgotrading tutorial. I copy pasted all the code into strategy_sma_regular_order.py file. When I run the command 'algobulls_connection.create_strategy(StrategySMARegularOrder)' , I get the following error: -

TypeError: Can't instantiate abstract class StrategySMARegularOrder with abstract methods name

Need to add a dummy class file for strategy base v2

  • To code the strategy, you need to import the Base Class for your strategy class.
  • This base class needs to be defined in the pyalgotrading package itself.
  • I cannot run or upload my options strategy that was coded locally on my device. It cannot be uploaded by pyalgotrading as there was an Python Error of Class Not Found. Since the Base Class was not defined, and there is no dummy class in the package as well for Options Strategies.
  • Need a base class in package so that I could import it in my strategy and then it will help me upload it to AB server.

Pass the parameter initial funds to the statistics functions from saved_paramters dictionary

  • Initial funds have to be passed manually for statistics function, this is very tiring and unnecessary step for most of the users.
  • It would be easier if we were saving the initial funds somewhere when executing the strategy.
  • And retrieving the saved initial funds when calling the statistics function.
  • For exceptional cases we can give initial funds to be 1e9.
  • Also keep the provision for manually providing the virtual funds to the statistic functions as well

Internal key objects should be linked to Strategy Code

Currently, the following objects of the AlgoBullsAPI class are not linked to the Strategy Code:

  1. _key__backtesting
  2. _key__papertrading
  3. _key__realtrading

The first time any method of AlgoBulls API is called, these keys are fetched and cached for the corresponding strategy code. However, if the methods are called again for a different strategy code, instead of using a key corresponding to them, the cached keys are used which results in incorrect execution.

The solution to this problem is simple: Link the cached keys to Strategy Code. Fetch cached keys only if the strategy code matches, else, fetch the key from the server.

Feature to perform analytics on P&L data coming from external CSV/Excel Sheet file

  • Need the ability to load a custom pnl table from a CSV and generate Analytics using Quantstats.
  • And keep internal sanity when somebody imports a CSV, so we have the necessary columns with necessary data types, etc.
  • If user gives a CSV which has the necessary columns, and asks to generate analytics on it, (without doing any BT, PT or RT, because user already did that to get the table), then we should be able to simply import it and generate the entire Quantstats in few lines of code

Add a function to fetch allowed/available brokers

  • when the user started an RT from pyalogtrading, he gave the name as NUVAMA in the broking details, and the strategy broke.
  • Mainly because the user does not know the valid list of names that we have given in AlgoBullsSupportedBrokers
  • How do we solve this?
    • One way would be to put the whole list somewhere on the pyalgotrading help site
    • One better way is to give a method like algobulls_connection.get_all_brokers() , this is similar to algobulls_connection.get_all_strategies(), which gives a list of all strategies in the user's account

Add progressive logs for BT, PT and RT

  • Intially when logs were fetched they used to come in one instance, and they would be incomplete if the strategy is still running.
  • There was a need to add progressive logs, that would print the logs as they are updated in real time.
  • There is also a need to add a progress bar to track the progress of the strategy's execution.
  • Since, there was an update in the API for logs in backend, this feature has to be re-updated.
  • Backend does not support complete logs API, hence that logic needs to be removed as well.

Need to add examples for plot_candlestick_chart function in pyalgotrading/utils/func.py

I am trying to use this function to plot candlesticks for my dataframe.
But the format of arguments is not mentioned properly.
First I was stuck at plot_type argument. To understand it I had to find the code in the repo where it was defined.
Now ,I am finding it difficult to understand the format of indicators required for this function.

So, there is need of examples and additional information on arguments.

Generative AI integration

  • add a feature to take inputs from user for generating strategy using chat-gpt
  • add feature to save the generated strategy
  • add feature to show recent chats

Add a feature for slippage

  • A feature for giving slippage percentage needs to be provided when calling functions for pnl_table
  • This slippage will help simulate real-life environment, and hence will provide an estimated net-pnl which will be closer to real life environment
  • It would be even more better if the Slippage is determined by order_variety, i.e Limit Order should have only positive slippage whereas Market Order will have negative slippage as well as positive slippage.
  • The feature is binded with this PR: #34

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.