Coder Social home page Coder Social logo

dwallach1 / prometheus Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 28.36 MB

Automated Crypto Trader

Home Page: https://charts.mongodb.com/charts-prometheus-wblan/public/dashboards/445551b4-ff95-4297-be27-4ce1188f1470

Python 98.83% Dockerfile 0.39% Makefile 0.77%
crypto trading

prometheus's Introduction

PROMETHEUS

In summary, Prometheus was a prominent Titan figure in Greek mythology known for defying the gods to benefit humanity, an act for which he was severely punished, but which cemented his legacy as a champion and benefactor of humankind.

๐Ÿ’ป View the live decisions made by Prometheus here

Historical Analysis

Using Yahoo Finance, we can analyze the historical data of Bitcoin, Ethereum, and Solana to determine the number of 24-hour windows with at least a 5% price drop and the average drop window percentage. We can also determine the number of successful sell events, the average lot time, and the average profit percentage for each asset.

This data is not fully comprehensive as it only has price points once per day while Prometheus checks the price many times per day; however, this gives us a good approximation of the historical performance of this trading strategy.

Looking at ETH in 2019, we can see the following image ETH 2019 Each box represents a buy-sell combination. The colors and size of the boxes are random to be able to distinguish between them. Red lines indicate a BUY event. The width of the box represents the time from BUY to SELL. Buys only occur if the asset dropped at least 5% in the day delta. Sells only occur at the first opportunity to sell for at least a 12% profit.

For this specific asset in 2019, we can see that the average drop window percentage is -8.52%, the average lot time is 21.29 days, and the average profit percentage is 14.67%.

You can find the images for each year in the analysis/imgs folder.

ETH

[ ETH ALL ]
Number of 24-hour windows with at least 5% price drop: 214
The average drop window percentage is: -8.67%
Number of successful sell events: 206
The average lot time is: 172.21 days
The average profit percentage is: 15.38%

[ ETH 2017 ]
Number of 24-hour windows with at least 5% price drop: 5
The average drop window percentage is: -9.67%
Number of successful sell events: 5
The average lot time is: 5.00 days
The average profit percentage is: 16.72%

[ ETH 2018 ]
Number of 24-hour windows with at least 5% price drop: 60
The average drop window percentage is: -8.90%
Number of successful sell events: 30
The average lot time is: 15.13 days
The average profit percentage is: 16.41%

[ ETH 2019 ]
Number of 24-hour windows with at least 5% price drop: 28
The average drop window percentage is: -8.52%
Number of successful sell events: 17
The average lot time is: 21.29 days
The average profit percentage is: 14.67%

[ ETH 2020 ]
Number of 24-hour windows with at least 5% price drop: 26
The average drop window percentage is: -9.50%
Number of successful sell events: 26
The average lot time is: 40.77 days
The average profit percentage is: 15.63%

[ ETH 2021 ]
Number of 24-hour windows with at least 5% price drop: 44
The average drop window percentage is: -8.57%
Number of successful sell events: 38
The average lot time is: 26.53 days
The average profit percentage is: 15.46%

[ ETH 2022 ]
Number of 24-hour windows with at least 5% price drop: 39
The average drop window percentage is: -8.51%
Number of successful sell events: 21
The average lot time is: 20.52 days
The average profit percentage is: 14.34%

[ ETH 2023 ]
Number of 24-hour windows with at least 5% price drop: 6
The average drop window percentage is: -6.29%
Number of successful sell events: 5
The average lot time is: 71.00 days
The average profit percentage is: 14.60%

[ ETH 2024 ] [as of 04.11.2024]
Number of 24-hour windows with at least 5% price drop: 6
The average drop window percentage is: -6.59%
Number of successful sell events: 4
The average lot time is: 10.00 days
The average profit percentage is: 14.58%

You can find the historical results for each asset in the analysis/results folder.

Configuration

Example asset config (config.json)

{
    "assets": [
        {
            "name": "Bitcoin",
            "symbol": "BTC",
            "amount_to_buy_usd": 500,
            "buy_price_percentage_change_threshold": 5.0,
            "sell_price_percentage_change_threshold": 10.0,
            "max_open_buys": 5
        },
        {
            "name": "Ethereum",
            "symbol": "ETH",
            "amount_to_buy_usd": 500,
            "buy_price_percentage_change_threshold": 5.0,
            "sell_price_percentage_change_threshold": 10.0,
            "max_open_buys": 5
        }
    ]
}

Example Market PREVIEW buy ($10 USD worth of BTC)

cb_client.preview_market_order_buy("BTC-USD", "10")

response =>

{
    "order_total": "10.00000000000000004545",
    "commission_total": "0.05469915464942814545",
    "errs": [],
    "warning": [],
    "quote_size": "9.9453008453505719",
    "base_size": "0.0001465019262741",
    "best_bid": "67878.27",
    "best_ask": "67885.12",
    "is_max": false,
    "order_margin_total": "0",
    "leverage": "0",
    "long_leverage": "0",
    "short_leverage": "0",
    "slippage": "0.0000000000002152"
}

Example Market buy response (success) ($500 USD worth of SOL)

{
    "success": true,
    "failure_reason": "UNKNOWN_FAILURE_REASON",
    "order_id": "30300590-9040-4f58-a0c0-a53cf97a3adf",
    "success_response": {
        "order_id": "30300590-9040-4f58-a0c0-a53cf97a3adf",
        "product_id": "SOL-USD",
        "side": "BUY",
        "client_order_id": "b3ff6bc3-8cb7-4347-bd2a-bd6c15985604"
    },
    "order_configuration": {
        "market_market_ioc": {
            "quote_size": "500.0000"
        }
    }
}

Example Market PREVIEW sell (0.0001 BTC for USD)

cb_client.preview_market_order_sell("BTC-USD", "0.0001")

response =>

{
    "order_total": "6.7447079505",
    "commission_total": "0.0373010495",
    "errs": [],
    "warning": [],
    "quote_size": "6.782009",
    "base_size": "0.0001",
    "best_bid": "67820.09",
    "best_ask": "67825.33",
    "is_max": false,
    "order_margin_total": "0",
    "leverage": "0",
    "long_leverage": "0",
    "short_leverage": "0",
    "slippage": "0"
}

Example Market sell response (success) (0.0005 BTC for USD)

{
    "success": true,
    "failure_reason": "UNKNOWN_FAILURE_REASON",
    "order_id": "595979f7-50b4-4b51-af4e-f644286bb63f",
    "success_response": {
        "order_id": "595979f7-50b4-4b51-af4e-f644286bb63f",
        "product_id": "BTC-USD",
        "side": "SELL",
        "client_order_id": "27309299-76b8-4401-9161-2692fbe22ada"
    },
    "order_configuration": {
        "market_market_ioc": {
            "base_size": "0.0005"
        }
    }
}

prometheus's People

Contributors

dwallach1 avatar

Stargazers

 avatar

Watchers

 avatar

prometheus's Issues

add unit tests

You can write a unit test using a testing framework like pytest to validate the buy functionality of the DecisionMaker class.

import unittest
from unittest.mock import MagicMock
from main import DecisionMaker, DecisionContext, Asset, Enviorment, RESTClient, MongoClient
from decisions import DecisionType

class TestDecisionMaker(unittest.TestCase):

    def test_buy_asset(self):
        # Mocking necessary dependencies
        cb_client = MagicMock(spec=RESTClient)
        mongo_client = MagicMock(spec=MongoClient)

        # Creating test data
        asset_config = Asset(name="TestAsset", symbol="TEST", account_id="123", amount_to_buy=100.0, buy_price_percentage_change_threshold=0.5, sell_price_percentage_change_threshold=1.0, max_open_buys=2)
        context = DecisionContext(enviorment=Enviorment.TEST, price=100.0, symbol="TEST", asset_balance=10.0, total_asset_value=1000.0, usdc_balance=1000.0, volume_24h=1000.0, volume_percentage_change_24h=0.5, price_percentage_change_24h=1.0, total_asset_holdings_value=1000.0, price_change_check=True, buy_buffer_check=True, open_buy_check=True, open_buy_count=0, open_buy_decisions=[])

        # Creating an instance of DecisionMaker
        decision_maker = DecisionMaker(Enviorment.TEST, cb_client, mongo_client, "test_db", "test_collection", asset_config, "usd_account_id")

        # Mocking the necessary methods for buying
        decision_maker.get_decision_context = MagicMock(return_value=context)
        decision_maker.get_buying_power = MagicMock(return_value=1000.0)
        decision_maker.place_buy_order = MagicMock(return_value={"mock": "buy_order_result"})

        # Running the buy decision
        decision_maker.compute_decisions()

        # Asserting that the buy order was placed
        decision_maker.place_buy_order.assert_called()

if __name__ == '__main__':
    unittest.main()

detect relative local minimum

right now we buy if dips below buy_price_percentage_change_threshold but can we treat this as a flag to enable the buy but add logic to try and guess once its bottomed out. This will try to protect against a fast drop of 10% when the threshold is set to 5%. we can fire off a "watcher" and once it detects rate of change decreasing or improving it inserts the buy

expand to more assets

add LINK, ADA and AVAX to the assets config. These follow similar patterns as other assets, increasing our buy opportunities

Analysis get most "profitable" pairings

We have average return per pairing and number of allotments. Assume a constant order size of $100 which pairing generates the best results.

Things to consider:

  • in a bull market right now. Should we stop before the bull market to see how it would perform? Etc.

Strategies in asset config

For assets im bullish on and dont mind holding onto for a long time, i set my buy strategy to only need one candle of recovery. My sell strategy will check when we're above the sell threshold and then try to maximize profits by riding a pump if there is one.

{
    "name": "Bitcoin",
    "symbol": "BTC",
    "amount_to_buy_usd": 500,
    "buy_price_percentage_change_threshold": -5.0,
    "sell_price_percentage_change_threshold": 12.0,
    "max_open_buys": 5,
    "buy_strategy": {
        "candle_size": "ONE_HOUR",
        "green_candles_in_a_row": 1
    },
    "sell_strategy": {
        "type": "MAXIMIZE_PROFIT",
        "MAXIMIZE_PROFIT": {
            "candle_size": "ONE_HOUR",
            "red_candles_in_a_row": 1
        }
    }
}

with riskier assets, i increase the number of candles and sell immediately once i can.

{
    "name": "Cardano",
    "symbol": "ADA",
    "amount_to_buy_usd": 100,
    "buy_price_percentage_change_threshold": -5.0,
    "sell_price_percentage_change_threshold": 12.0,
    "max_open_buys": 1,
    "buy_strategy": {
        "candle_size": "ONE_HOUR",
        "green_candles_in_a_row": 2
    },
    "sell_strategy": {
        "type": "IMMEDIATE_SELL",
        "IMMEDIATE_SELL": {}
    }
}

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.