# Introduction

ProjectHax Bot for Crypto

phBot Crypto is a simple Dollar Cost Averaging (DCA) bot. As price moves down the bot will continue placing buy orders below your last fill until the coin goes back up to hit your profit target.

> Dollar-cost averaging (DCA) is an investment strategy in which an investor divides up the total amount to be invested across periodic purchases of a target asset in an effort to reduce the impact of volatility on the overall purchase. The purchases occur regardless of the asset's price and at regular intervals. In effect, this strategy removes much of the detailed work of attempting to time the market in order to make purchases of equities at the best prices. Dollar-cost averaging is also known as the constant dollar plan.

* <https://www.investopedia.com/terms/d/dollarcostaveraging.asp>

<figure><img src="https://52669202-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi8zuIwOp4HKMv0DfxDSf%2Fuploads%2FibOeHlhBA6OsGpUvLzaX%2Fmain.png?alt=media&amp;token=051904d4-ad47-4de8-a78c-4364ca164501" alt=""><figcaption></figcaption></figure>

## Social Media

* [Twitter](https://twitter.com/projecthax)
* [Facebook](https://facebook.com/projecthax)
* [GitHub](https://github.com/projecthax)
* [Discord](https://discord.gg/zpcJrQQDsr)
* [YouTube](https://www.youtube.com/@projecthaxllc)
* [Twitch](https://www.twitch.tv/projecthaxllc)


# Disclaimer

### Crypto Risk Disclosure

Cryptocurrency trading carries a high level of risk and may not be suitable for all investors. Before engaging in any trading activities, individuals should carefully consider their financial situation and risk tolerance. It is important to be aware of the potential for both significant gains and losses.

**Volatility Warning**

Cryptocurrency markets are known for their extreme volatility. Prices can change rapidly, and market conditions can shift unexpectedly. Traders should be prepared for sudden and unpredictable price movements.

**No Guarantee of Profit**

There is no guarantee of profit in cryptocurrency trading. Prices are influenced by various factors, including market sentiment, regulatory developments, technological advancements, and macroeconomic trends. Past performance does not guarantee future results.

**Independent Research**

Traders are encouraged to conduct their own independent research before making any trading decisions. While information and analysis may be provided, individuals should verify and corroborate information from multiple sources and consult with financial professionals if necessary.

**Security Risks**

Participants in cryptocurrency markets should be aware of security risks, including the potential for hacking, fraud, and other malicious activities. It is essential to use secure and reputable platforms and employ best practices for securing digital assets.

**Regulatory Considerations**

Cryptocurrency markets are subject to regulatory developments, which can impact trading activities. Traders should be aware of and comply with applicable regulations in their jurisdiction.

**Lack of Regulation**

Cryptocurrencies are not regulated by any government or central authority. The lack of regulatory oversight means that investors may have limited recourse in the event of fraud or other unlawful activities.

**Tax Implications**

Cryptocurrency transactions may have tax implications, and individuals are responsible for complying with tax laws in their jurisdiction. It is advisable to seek professional advice to understand the tax implications of cryptocurrency trading.

**Use of Leverage**

Trading with leverage amplifies both potential gains and losses. It is important to understand the risks associated with leverage and only use it if you fully comprehend its implications.

**Not a Solicitation**

The information presented in this disclaimer is not a solicitation to buy or sell any cryptocurrency or engage in any trading activities. Individuals should make their own decisions based on their financial goals and risk tolerance.

By engaging in cryptocurrency trading, individuals acknowledge and accept the inherent risks involved and release all parties involved from any liability. This disclaimer is subject to change without notice.

***

### Futures Trading Risk Disclaimer

**Introduction**

Futures trading involves substantial risk and is not suitable for every investor. An investor could potentially lose all or more than the initial investment. Only risk capital should be used for trading, and only those with sufficient risk capital should consider trading.

**Risk of Loss**

Trading in futures contracts carries a high level of risk and may not be suitable for all investors. The high degree of leverage can work against you as well as for you. Before deciding to trade, you should carefully consider your investment objectives, level of experience, and risk appetite. The possibility exists that you could sustain a loss in excess of your initial investment, and therefore, you should not invest money that you cannot afford to lose.

**Education and Understanding**

Trading in futures requires a good understanding of market principles, trading strategies, and risk management. It is essential that you educate yourself and seek professional advice before engaging in any futures trading activity.

**Market Volatility**

Futures markets can be highly volatile. Price movements can be unpredictable and may result from a variety of factors, including market events, economic releases, geopolitical developments, and more. Extreme market conditions can lead to significant price gaps and limit up or down moves, which may impact your positions.

**No Guarantees**

There are no guarantees or certainties in futures trading. Past performance is not indicative of future results. Any historical data or performance should not be taken as an indication or guarantee of future performance.

**Risk of Leverage**

Futures trading often involves the use of leverage, which can amplify both potential profits and potential losses. It is important to understand and carefully manage the risks associated with leverage.

**Consultation with Professionals**

It is strongly advised that you seek advice from a qualified financial advisor, legal professional, or other knowledgeable professionals before engaging in futures trading.

**Regulatory Considerations**

Futures trading is subject to regulatory oversight, and compliance with relevant laws and regulations is essential. It is your responsibility to be aware of and comply with all applicable regulations.


# Purchasing

phBot Crypto is a standalone application from the original phBot created by ProjectHax LLC. It can be purchased at [phBot.org](https://phbot.org/crypto) for $10 per month or $99 per year. If you have an existing phBot subscription it will be unaffected as these are separate subscriptions.

{% embed url="<https://phbot.org/crypto>" %}


# Download

This links below will always have the latest version. By downloading this application you agree to the [terms and conditions](https://phbot.org/legal/). It is on you to understand how the bot works and accept the risks associated with it.

## Windows

* [phBot Crypto](https://cdn.projecthax.com/crypto/phBot-crypto.exe)
* [vc\_redist.x86.exe](https://aka.ms/vs/17/release/vc_redist.x86.exe)

## Linux

* [phBot\_Crypto-x86\_64.AppImage](https://cdn.projecthax.com/crypto/phBot_Crypto-x86_64.AppImage)

Please see the [usage instructions](/supported-operating-systems) for Linux.


# Updating

The bot checks for updates each time it is opened. If a new version is available it will show you the download link, changelog, and ask if you would like to download it.

Information about new releases is posted on the [forum](https://forum.projecthax.com/t/phbot-crypto-release/15533) and [discord](https://discord.gg/zpcJrQQDsr) server.

<figure><img src="https://52669202-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi8zuIwOp4HKMv0DfxDSf%2Fuploads%2Fiw8dJwMEjzbbdA8ewDn2%2Fimage.png?alt=media&amp;token=b2ec0532-710a-4408-afe4-36f5e571935c" alt=""><figcaption></figcaption></figure>


# Supported Operating Systems

## Windows

Windows 7 and onward is supported with Windows 10 and up being recommended.

## Linux

Any distro that is based on Ubuntu 20.04 x86-64 or later. It has been tested on:

* Debian 12
* Ubuntu 20.04, 22.04, 24.04
* RHEL 9, RockyLinux 9, RHEL 10 Beta

#### AppImage (recommended)

1. Install fuse for AppImage and CA certificates.
   1. `sudo apt install fuse ca-certificates -y`
   2. `sudo dnf install fuse ca-certificates -y`
2. Download the AppImage from <https://phbot.org/crypto/download/>
3. `chmod +x phBot_Crypto-*.AppImage`
4. Run `./phBot_Crypto-*.AppImage`
5. To update the bot, follow the steps outlined here.

All configuration files for Linux are located at `~/.phBot-crypto`.

#### Wine

Ubuntu 22.04 x86-64 is recommended. If you want to run it completely headless you should learn about [screen](https://www.howtogeek.com/662422/how-to-use-linuxs-screen-command/).

```
sudo dpkg --add-architecture i386
sudo mkdir -pm755 /etc/apt/keyrings
sudo wget -O /etc/apt/keyrings/winehq-archive.key https://dl.winehq.org/wine-builds/winehq.key
sudo wget -NP /etc/apt/sources.list.d/ https://dl.winehq.org/wine-builds/ubuntu/dists/jammy/winehq-jammy.sources
sudo apt update && sudo apt install --install-recommends winehq-stable
```

**Running**

```
wine cmd
phBot-crypto.exe
```

## VPS

If you would like to run phBot Crypto on a VPS there are several options to choose from.

**Paid**

* [DigitalOcean](https://m.do.co/c/7116139f5003)
* [Linode](https://www.linode.com/?r=18f42bca02213da70dd79826fd2ff1af171e152a)
* [Vultr](https://www.vultr.com/?ref=6804024)

**Free**

* [AWS](https://aws.amazon.com/free/)
* [Oracle (recommended)](https://www.oracle.com/cloud/free/)
* [IBM](https://www.ibm.com/cloud/free)

The bot does need to write some data to disk so AWS free tier is not recommended as it is too slow.


# Wallets

You only need a wallet if you wish to take profit as crypto then transfer it off exchange.

* [Exodus](https://www.exodus.com/)
* [Coinbase Wallet](https://wallet.coinbase.com/)
* [Crypto.com](https://crypto.com/defi-wallet)
* [Ledger](https://www.ledger.com/)


# Tax

[Koinly.io](https://koinly.io/?via=6BCBDC5B)


# Frequently Asked Questions

* Q: Can I run multiple exchanges at the same time?

* A: Yes.

* Q: Can I run multiple accounts from the same exchange at the same time?

* A: Yes, copy the application to another folder and use different API keys in the config file.

* Q: How much money do I need to use this?

* A: That is up to you, but with some quick math you will need apporximately $250 for 10 fills with a size of 20 and scale factor 1.05 – per pair.

* Q: What is the minimum size I can trade with?

* A: On Binance the minimum is $10 however you really should use $12 due to fees and to avoid rounding problems.

* Q: Can I trade coin pairs such as BTCETH?

* A: It should work but has never been tested so it is not recommended that you try it. BTCUSDT or BTCUSDC is supported.

* Q: Can it trade on margin or futures?

* A: Margin is supported only on Binance otherwise spot only. If you choose to enable margin, you will not be able to trade spot as well at Binance with the same configuration.

* Q: The bot crashes almost immediately after it opens.

* A: Make sure you have installed the latest vcredist x86 from Microsoft. <https://aka.ms/vs/17/release/vc_redist.x86.exe>

* Q: Will this make me rich?

* A: No.

<figure><img src="https://52669202-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi8zuIwOp4HKMv0DfxDSf%2Fuploads%2FHAbduUkYaE4a6tTIDin0%2Fso-youre-telling-me-theres-a-chance-1.gif?alt=media&amp;token=5ba62025-0173-44b9-8f00-d1b2fde131ac" alt=""><figcaption></figcaption></figure>


# Introduction

Since `v1.2.1` there is a configuration menu that walks you through the exchange and pair configuration.

<figure><img src="https://52669202-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi8zuIwOp4HKMv0DfxDSf%2Fuploads%2FZGhf3iahpAM1VBF2l408%2Fconfig_1.png?alt=media&amp;token=6015cc99-39b7-4aea-b818-8547c6fc7285" alt=""><figcaption></figcaption></figure>

First, you will need to add an exchange for the bot to trade on. In this example, Coinbase is chosen.

<figure><img src="https://52669202-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi8zuIwOp4HKMv0DfxDSf%2Fuploads%2FhBy2xsI3y5G3VgUKHS0a%2Fconfig_2.png?alt=media&amp;token=68d77f09-292a-4ebb-9389-0ab0f92ab9da" alt=""><figcaption></figcaption></figure>

Next, enter your API key information and enable the exchange. If you press `enter` it will use the default value inside the bracket. If no bracket exists then you *must* type a value.

<figure><img src="https://52669202-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi8zuIwOp4HKMv0DfxDSf%2Fuploads%2FSXxWFMKcAi3dWfmjBLS1%2Fconfig_3.png?alt=media&amp;token=67b487f3-b4e3-4359-9c82-441ba1ef97d2" alt=""><figcaption></figcaption></figure>

Finally, create a trading pair to add to the exchange. The symbol on Coinbase is `BTC-USD`, but on another exchange it may differ.

<figure><img src="https://52669202-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi8zuIwOp4HKMv0DfxDSf%2Fuploads%2FLvrAK7igEc2691ushjat%2Fconfig_4.png?alt=media&amp;token=a1070f25-2d79-443f-b91d-fdc0ed56de42" alt=""><figcaption></figcaption></figure>

Finished! Press `q` to save and quit then restart phBot. You can edit your configuration before the bot starts by pressing `e`.

Remember, you can always edit `phBot.ini` to change an option that is not shown in the menu system.


# Main

## Main Configuration

* `Agree`
  * Determines if you have accepted the agreement when first starting phBot.
* `Username`
  * Bot username.
* `Password`
  * Bot password.
* `Delay`
  * Startup delay in seconds. If this is set to 0, the bot will not check for updates and will immediately start.
  * Default: `5`
* `Interval`
  * Delay in seconds between each order/fill refresh in the bot. If you are frequently hitting rate limits this value may need to be increased. For longer term trades or slower algorithms it can be increased to `15` seconds or more.
  * Minimum: `1`
  * Default: `5`
  * Maximum: `300`


# Pairs

## Pairs

Some pair names may overlap on different exchanges. If this is the case, you will need a separate folder if you wish to use different settings.

### Configuration

Once you have created a pair you must then add it to the `Pairs` list for the exchange. Each pair must be separated by a comma.

* `Enabled`
  * Enables or disables the pair. `true` or `false`
* `Size`
  * Initial dollar amount.
* `Initial`
  * Percentage away from the current price to place the initial buy order. If this is set to `0` it will use a market order and immediately enter - this also means it will always be in a trade assuming volume/price conditions are met.
* `Target`
  * Profit target percentage (based on the average).
* `Target Base`
  * Target a specific dollar amount (eg. set to 10 to always target a $10 profit). This defaults to `0` which will use the `Target` percent as shown above.
* `Scale`
  * Percentage away from the last fill to place another buy order.
* `Scale Factor`
  * Percentage to increase the dollar amount by for each scale in. The value it uses is the last fill dollar amount. This means each new scale in order will be more than the previous dollar amount.
* `Scale Multiplier`
  * Percentage to increase the `Scale` by for each subsequent fill. This defaults to `0`.
* `Fills`
  * Maximum number of scale ins.
* `Profit`
  * Currency to take profit in. `crypto` or `base` with `base` being the default.
* `Target Type`
  * Sets which price to use for the profit target. `avg` targets the average of all the fills and `base` will use the first entry.
* `Flush`
  * Enable to continuously move the initial buy order based on the last trade. This can be used to catch huge down moves when there are liquidity issues.
* `Switched`
  * Enable if you switched from crypto profit back to base. This defaults to `true` to force the bot to only track the average based on the orders that it creates.
* `Volume`
  * Minimum amount of 24 hour volume to begin the initial buy. If a position already exists it will continue scaling. `0` will always trade.
* `Percent Change`
  * Minimum % change (up or down) to start a sequence of trades. This value must be a positive number as we do not care if it is up or down - only moving. Can be set to `0` to always trade.
* `Max Price`
  * Max price to start buying at. If this is set to `0` it will be ignored.
* `Exit Only`
  * Once the sell order is filled do not place new buy orders. This will not cancel an initial unfilled buy order and will continue trading until the take profit order is filled.
* `Max Dominance`
  * Maximum BTC dominance allowed for new buy orders to be placed. New orders will only be placed if BTC dominance is *below* this value. Requires a [CoinMarketCap](https://coinmarketcap.com/api/pricing/) API key.
* `Min Dominance`
  * Minimum BTC dominance allowed for new buy orders to be placed. New orders will only be placed if BTC dominiance is *above* this value. Requires a [CoinMarketCap](https://coinmarketcap.com/api/pricing/) API key.
* `Stop`
  * Stop loss (in base currency). This option defaults to `0` for no stop loss. It should *always* be a positive number.
* `Target1 Target2 TargetN` (replace N with fill number)
  * Allows you to have a profit target based on the number of fills. If you have `1`fill you can specify a higher profit target for that fill number. Supports up to `100` fills. Supported only when taking profit in base $.
  * Example:
    * `Target1=10`
      * 10% target if only one fill.
    * `Target2=7`
      * 7% target if only two fills.
    * `Target=5`
      * Default target if a fill target is not specified.

#### Crypto Profit

The bot allows you to take profit as either dollars (base) or crypto. If you decide to take profit as crypto then go back to base you must first get out of the current trades and enable `Switched`. If you do not, it will either sell the entire position instantly, or if you withdrew profits, not be able to sell because the coin is no longer in your portfolio.

It is not recommended to take profit as crypto with a small dollar balance.

***WARNING!*** Do **not** delete the `db3` database file when taking profit as crypto or if `Switched` is on unless you know what you are doing. If you do, you must wait for your target to hit then cancel any open orders. You essentially must completely reset then let the bot start over.

#### Switched

Enabling the `Switched` option forces the bot to only track trades that it makes. Changing orders on the exchange with `Switched` enabled is not recommended. You can still edit the target and scale and restart the bot to make it update the orders.

If you manually exited a position, you will need to delete the database file so that it knows to start placing buy orders. This essentially wipes the memory of any trades the bot made. It will also wipe all information about other pairs so it is important to only delete it if you want to start over on all pairs.

If you only ever take profit as the base currency you should never need to use this option unless you are manually buying/selling as well. In that case you should have a separate portfolio just for the bot.

#### Margin

Margin trading is supported on Binance and Alpaca. Margin is only recommended for sophisticated investors with a high risk tolerance.

The bot will continue buying based on your fill count. It is on you to determine how much risk you are willing to take with margin.


# Proxy

## Proxy

Proxies are supported in `v1.1.1` and onward.

#### Example

**SOCKS 5**

```
socks5://127.0.0.1:1080
```

**SOCKS 5 w/authentication**

```
socks5://user:pass@127.0.0.1:1080
```

**SOCKS 4a**

```
socks4a://127.0.0.1:1080
```

**HTTP**

```
http://127.0.0.1:80
```

**HTTPS**

```
https://127.0.0.1:443
```


# Examples

Any coins/stocks listed below are purely used as example and are not a recommendation to buy or sell.

```
[phBot]
Agree=false
Username=
Password=
Interval=5
Delay=5

[Coinbase]
Enabled=true
Key=
Secret=
Passphrase=
Pairs=BTC-USD
Proxy=
URL=https://api.pro.coinbase.com

[Binance]
Enabled=false
Key=
Secret=
Pairs=BTCUSDT
Proxy=
URL=https://api.binance.us
Margin=false

[Gemini]
Enabled=false
Key=
Secret=
Pairs=BTCUSD
Proxy=
URL=https://api.gemini.com

[Alpaca]
Enabled=false
Key=
Secret=
Pairs=SPY
Proxy=
URL=https://api.alpaca.markets

[Alpaca Crypto]
Enabled=false
Key=
Secret=
Pairs=SPY
Proxy=
URL=https://api.alpaca.markets

[Kraken]
Enabled=false
Key=
Secret=
URL=https://api.kraken.com
Proxy=
Pairs=

[BTC-USD]
Enabled=true
Size=20
Initial=1
Target=1.5
Target Base=0
Scale=2
Scale Factor=1.05
Scale Multiplier=0
Fills=20
Profit=base
Volume=0
Target Type=avg
Percent Change=0
Max Price=0
Flush=false
Switched=false
Exit Only=false

[BTCUSDT]
Enabled=true
Size=20
Initial=1
Target=1.5
Target Base=0
Scale=2
Scale Factor=1.05
Scale Multiplier=0
Fills=20
Profit=base
Volume=0
Target Type=avg
Percent Change=0
Max Price=0
Flush=false
Switched=false
Exit Only=false

[BTCUSD]
Enabled=true
Size=20
Initial=1
Target=1.5
Target Base=0
Scale=2
Scale Factor=1.05
Scale Multiplier=0
Fills=20
Profit=base
Volume=0
Target Type=avg
Percent Change=0
Max Price=0
Flush=false
Switched=false
Exit Only=false

[SPY]
Enabled=true
Size=500
Initial=1
Target=1.5
Target Base=0
Scale=1
Scale Factor=1.05
Scale Multiplier=0
Fills=20
Profit=base
Volume=0
Target Type=avg
Percent Change=0
Max Price=0
Flush=false
Switched=false
Exit Only=false
```

#### Example use cases

There are several ways to use the bot.

1. Buying continuously after each sell.
   * This works best if you want to take profit as crypto.
2. Buying slightly lower with a small initial percent (1% or so)
   * A little less risk as it has already dropped a small amount.
3. Buying crashes (15% or more) and high scale percentages (10% or more).
   * Does not happen as frequently but will generate the most amount of profit if several orders are filled. This works best after the coin has gone parabolic.

**Continuous**

```
[BTC-USD]
Enabled=true
Size=20
Initial=0
Target=1.5
Target Base=0
Scale=2
Scale Factor=1.05
Scale Multiplier=0
Fills=20
Profit=base
Volume=0
Target Type=avg
Percent Change=0
Max Price=0
Flush=false
Switched=false
Exit Only=false
```

**Small initial**

```
[BTC-USD]
Enabled=true
Size=20
Initial=1
Target=1.5
Target Base=0
Scale=2
Scale Factor=1.05
Scale Multiplier=0
Fills=20
Profit=base
Volume=0
Target Type=avg
Percent Change=0
Max Price=0
Flush=false
Switched=false
Exit Only=false
```

**Crashes**

The `Flush` option allows the bot to replace the buy order every 5 minutes to lower it with the price of the coin.

```
[BTC-USD]
Enabled=true
Size=20
Initial=15
Target=1.5
Target Base=0
Scale=10
Scale Factor=1.05
Scale Multiplier=0
Fills=20
Profit=base
Volume=0
Target Type=avg
Percent Change=0
Max Price=0
Flush=true
Switched=false
Exit Only=false
```


# Introduction

## Supported Exchanges

More exchanges may be added in the future depending on demand.

* Binance.com / Binance.us
* Coinbase
* Gemini
* Alpaca (stocks/crypto)
* Kraken

## Date / Time

**Your computer timezone and time must be correct otherwise you will have issues authenticating.**

## Configuration

All settings are stored inside the `phBot.ini` file where the executable lives. You only need one exchange for phBot to function. Binance currently has the lowest fees and is available almost everywhere. Coinbase Pro has much higher fees until you start doing lots of volume.

The `db3` files are where order and fill information is stored (per exchange). They can be deleted if needed only when `Switched` is disabled and you are not taking profit as crypto. See [Switched](broken://pages/KMDIF79Sv455qrqEuoDX) for more info.

## API Key Creation

First you will need to create an API key so that the bot is able to make trades. *Do not ever* share the API keys you create with someone else.


# Binance

Binance.com / Binance.us

The bot supports Binance.com and Binance.us by changing the `URL` field in the config file.

&#x20;&#x20;

<figure><img src="https://52669202-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi8zuIwOp4HKMv0DfxDSf%2Fuploads%2F2S3w3sTAQji60nK0ug0j%2Fbinance_1.png?alt=media&amp;token=fc845d17-11bf-4e75-a8ca-1054d62033d7" alt="" width="205"><figcaption></figcaption></figure>

<figure><img src="https://52669202-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi8zuIwOp4HKMv0DfxDSf%2Fuploads%2Fq9CSFUy3xVVe9OgoJown%2Fbinance_2.png?alt=media&amp;token=158fe3c5-6302-4d59-8c6e-39dc9946f188" alt="" width="370"><figcaption></figcaption></figure>

<figure><img src="https://52669202-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi8zuIwOp4HKMv0DfxDSf%2Fuploads%2FQEB9zVBFDzQDU8NUa437%2Fbinance_3.png?alt=media&amp;token=2b9b8e7f-b26b-4c59-aac5-1b30313023bd" alt=""><figcaption></figcaption></figure>

Your API keys will be twice as long as what you see here.

1. Copy the *API Key* and *Secret Key* fields and place them in the `phBot.ini` file under the `Key` and `Secret` fields for `Binance`.
2. Set `Enabled` to `true`

<figure><img src="https://52669202-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi8zuIwOp4HKMv0DfxDSf%2Fuploads%2FJk3Y0X4WAKJPdcnWzyTS%2Fbinance_4.png?alt=media&amp;token=c71cc092-96ba-4608-80e8-7076a40620b0" alt=""><figcaption></figcaption></figure>

### **URL**

This only needs to be changed if you are using it with Binance.*com* instead of Binance.*us*.

For Binance.*com* change this field to: `https://api.binance.com`

### **Symbol Example**

```
BTCUSDT
```


# Coinbase

Coinbase.com

Coinbase has discontinued Coinbase Pro and replaced it with Advanced Trade. The new platform is supported in `v1.2.5` and onwards.

***

&#x20; &#x20;

<figure><img src="https://52669202-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi8zuIwOp4HKMv0DfxDSf%2Fuploads%2FfJzs445uNqlXZHmMSOHZ%2Fcoinbase_1.png?alt=media&amp;token=89cf6f40-5ace-4a6c-a343-9190db1f59db" alt="" width="256"><figcaption></figcaption></figure>

<figure><img src="https://52669202-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi8zuIwOp4HKMv0DfxDSf%2Fuploads%2F6R8XsUZRSALvpngf8V5i%2Fcoinbase_2.png?alt=media&amp;token=f49df265-63ad-4a71-9a73-b99abaf1854c" alt="" width="375"><figcaption></figcaption></figure>

<figure><img src="https://52669202-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi8zuIwOp4HKMv0DfxDSf%2Fuploads%2Fsvl9bubxz2pZ1xovR4Dc%2Fcoinbase_3.png?alt=media&amp;token=95187cca-cb88-4e13-a132-4851d5ba0618" alt="" width="357"><figcaption></figcaption></figure>

<figure><img src="https://52669202-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi8zuIwOp4HKMv0DfxDSf%2Fuploads%2FRrYrjnqPWuOFlKxwRVQg%2Fcoinbase_4.png?alt=media&amp;token=36ca6d70-3794-4512-962d-b2649af2cbd8" alt=""><figcaption></figcaption></figure>

1. Copy *name to the* `Key` field and *privateKey* to the `Secret Key` field into the `phBot.ini` file under `Coinbase`.
2. Set `Enabled` to `true`

**Symbol Example**

```
BTC-USD
```

**Sandbox**

Advanced Trade currently does not have a sandbox feature.


# Gemini

Gemini.com

Your API keys will be twice as long as what you see here.

<figure><img src="https://52669202-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi8zuIwOp4HKMv0DfxDSf%2Fuploads%2FlyetrGokRhUkkKRvbMSA%2Fgemini_1.png?alt=media&amp;token=2b85e016-e682-4fb7-b309-eccf5ca49a29" alt=""><figcaption></figcaption></figure>

<figure><img src="https://52669202-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi8zuIwOp4HKMv0DfxDSf%2Fuploads%2FyYHScMvW9EDXpfPWgYJx%2Fgemini_2.png?alt=media&amp;token=e1c77936-a51f-4ae1-a7bd-69d7d9b98569" alt="" width="347"><figcaption></figcaption></figure>

<figure><img src="https://52669202-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi8zuIwOp4HKMv0DfxDSf%2Fuploads%2FvqRm2dLOwJlsUEfPEfFi%2Fgemini_3.png?alt=media&amp;token=0918e824-9f52-4a1b-8b3b-07b75f1a4827" alt="" width="346"><figcaption></figcaption></figure>

1. Copy the *API Key* and *Secret Key* fields and place them in the `phBot.ini` file under the `Key` and `Secret` fields for `Gemini`.
2. Set `Enabled` to `true`

**Sandbox**

* `https://api.sandbox.gemini.com`


# Alpaca (stocks/crypto)

alpaca.markets

### **!!! Alpaca does not return any data on crypto fees.**

**Fees are calculated based on Tier 1 of** [**this page**](https://docs.alpaca.markets/docs/crypto-fees)**.** **If your trading volume is above tier 1, you will end up with left over dust that the bot will not recognize and will not sell.**

***

## Stocks

Stock trading is supported through the [alpaca.markets](https://alpaca.markets) brokerage.

* Taking profit as crypto (or stock shares in this case) is not supported.
* Fractional shares are not supported so your size must be more than the cost of 1 share.
* Live data is required from Alpaca for accurate size and price calculations which currently costs $9/mo or $99/yr. If you use the bot without data, the initial price calculation could be incorrect resulting in an instant fill.
* It is recommended to only trade index funds and not individual stocks. Risk is significantly higher on single stocks.

<figure><img src="https://52669202-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi8zuIwOp4HKMv0DfxDSf%2Fuploads%2FmF1CtVCvdLgpciz3uwi4%2Falpaca_1.png?alt=media&amp;token=6e331200-66fa-4c4e-aea0-4349549459c9" alt=""><figcaption></figcaption></figure>

<figure><img src="https://52669202-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi8zuIwOp4HKMv0DfxDSf%2Fuploads%2FNTcc5I67enyM1BgAlYgk%2Falpaca_2.png?alt=media&amp;token=b9ea7c78-d30b-4740-a2d1-267f8b675ea4" alt=""><figcaption></figcaption></figure>

1. Copy the *API Key ID* and *Secret Key* into the `phBot.ini` file under `Alpaca`.
2. Set `Enabled` to `true`

If you do not have more than $25,000 in your account, you should block trade entries and exits to prevent becoming a pattern day trader.

**Symbol Example**

```
SPY
```

**Sandbox**

See below.

## Crypto

1. Copy the *API Key ID* and *Secret Key* into the `phBot.ini` file under `Alpaca Crypto`.
2. Set `Enabled` to `true`

**Symbol Example**

```
BTC/USD
```

**Sandbox**

* `https://paper-api.alpaca.markets`
* <https://docs.alpaca.markets/docs/paper-trading>


# Kraken

Kraken.com

Kraken is supported in `v1.2.0` and onward.

&#x20;  ![](https://52669202-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi8zuIwOp4HKMv0DfxDSf%2Fuploads%2FROFV81roQDUADM4t5JKF%2Fimage.png?alt=media\&token=95cc31d1-c6e4-4cd1-8962-89fa426e56ac)

<figure><img src="https://52669202-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi8zuIwOp4HKMv0DfxDSf%2Fuploads%2F7volkmRVZVghVPj4rm7x%2Fimage.png?alt=media&amp;token=1e451944-5c68-49d9-afe2-5bdb7edc9ec5" alt=""><figcaption></figcaption></figure>

<figure><img src="https://52669202-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi8zuIwOp4HKMv0DfxDSf%2Fuploads%2FnewelBSmzbKEL1jdRPit%2Fimage.png?alt=media&amp;token=47edf24c-e294-4f4e-abf8-3ed68f4683a2" alt=""><figcaption></figcaption></figure>

<figure><img src="https://52669202-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi8zuIwOp4HKMv0DfxDSf%2Fuploads%2FhnCZPzPIoDpIGwlp22Ok%2Fimage.png?alt=media&amp;token=d08e4173-9ee6-4a07-bc5f-58a384b04f28" alt="" width="299"><figcaption></figcaption></figure>

Your API keys will be twice as long as what you see here.

1. Copy the *API Key* and *Private key* fields and place them in the `phBot.ini` file under the `Key` and `Secret` fields for `Kraken`.
2. Set `Enabled` to `true`

**Symbol Example**

```
XXBTZUSD
```

* <https://api.kraken.com/0/public/AssetPairs>


# Introduction

Starting with `v1.1.0`, it is possible to trigger trades based on signals created in Python. The bot is designed to dollar cost average but can be configured to have a single buy depending on your strategy.

[See the Example page for an example Python plugin.](/python/example)


# API

Python functions for phBot Crypto

## `get_bars(exchange, pair, granularity)`

This function retrieves historical bars for a given pair from an exchange. Granularity is in seconds.

### **Usage**

`get_bars(EX_COINBASE, 'BTC-USD', 60)`

### **Returns**

`None` or a `list` containing the historical bars in JSON.

```json
[{
   't': 1663858740,
   'o': 18865.76,
   'h': 18891.17,
   'l': 18855.5,
   'c': 18879.53,
   'v': 41.84053623
}, {
   't': 1663858680,
   'o': 18893.84,
   'h': 18900.26,
   'l': 18862.77,
   'c': 18866.74,
   'v': 41.47941474
}, {
   't': 1663858620,
   'o': 18896.58,
   'h': 18904.81,
   'l': 18882.33,
   'c': 18892.81,
   'v': 50.05292682
}, {
   't': 1663858560,
   'o': 18908.72,
   'h': 18917.8,
   'l': 18878.35,
   'c': 18898.82,
   'v': 29.25498139
}, {
   't': 1663858500,
   'o': 18911.94,
   'h': 18912.82,
   'l': 18883.5,
   'c': 18909.35,
   'v': 38.71486704
}

...etc

]
```

## `get_dominance()`

This function returns the Bitcoin and Ethereum dominance values from [CoinMarketCap](https://coinmarketcap.com/api/pricing/). A CMC API key must be configured in the `phBot.ini`file.

### Usage

`get_dominance()`

### Returns

`None`or a `dict` containing dominance data from CMC. Data is cached for 2 minutes before being refreshed.

```
{
   "btc_dominance":54.95772073293,
   "eth_dominance":13.109460109462,
   "btc_dominance_24h_percentage_change":0.13599359293,
   "eth_dominance_24h_percentage_change":0.148275599462,
   "btc_dominance_yesterday":54.82172714,
   "eth_dominance_yesterday":12.96118451,
   "last_updated":"2024-12-13T05:14:59.999Z"
}
```

## `get_fear_greed()`

This function returns the crypto fear and greed index from CoinMarketCap.

### Usage

`get_fear_greed()`

### Returns

`None`or a `dict`containing the latest fear/greed index from CMC. Data is cached for 2 minutes before being refreshed.

```
{
   "timestamp":1733961600,
   "value":80,
   "classification":"Extreme greed"
}
```


# Functions

## `signal(ex, pair)`

This function must return `None`, `False`, or `True`.

* `ex`
  * Exchange
* `pair`
  * Name of the pair being traded

### Return

1. Return `None` if the symbol is not handled by the script. If all scripts return `None` for the symbol then it will trade based on your settings.
2. Return `False` if the signal is not present.
3. Return `True` if the signal is present. This will allow the bot to place trades based on your settings.

## `update(ex, pair, last, avg, size, target)`

Since `v1.2.2`, this function can be used to force the bot to exit its current position and start over.

* `ex`
  * Exchange
* `pair`
  * Name of the pair being traded
* `last`
  * Last price of the pair
* `avg`
  * Average price of all entries
* `size`
  * Current position size
* `target`
  * Current target price

### Return

1. Return `True` to stay in the position.
2. Return `False` (or anything else) to exit the position.

This function should return `True` by default if you just want status updates sent to Python.

## `finished()`

This function is called when the bot is exiting. Depending on how the bot is closed, it may not be called.


# Example

Example Python plugin for phBot Crypto

```python
from phBot import *
import talib
import numpy

EX_COINBASE = 0
EX_BINANCE = 1
EX_ALPACA = 2
EX_GEMINI = 3
EX_ALPACA_C = 4
EX_KRAKEN = 5

def signal(ex, pair):
   bars = get_bars(ex, pair, 86400)
   if bars:
      close = numpy.array([x['c'] for x in bars])
      rsi = talib.RSI(close)
      print('Python: %s -> %s %f %f %f %f %f' % (pair, bars[-1]['t'], bars[-1]['o'], bars[-1]['h'], bars[-1]['l'], bars[-1]['c'], bars[-1]['v']))
   return None

def update(ex, pair, last, avg, size, target):
   print('Python: %s -> last: %f avg: %f size: %f target: %f' % (pair, last, avg, size, target))
   return True

def finished():
   pass
```


# Libs

## Included Libraries

* ta-lib
* tulipy
* numpy

## Windows

You will need to install Python 3.13.3 x86 if you want to install Python packages through pip.

* [Python 3.13.3 x86](https://www.python.org/downloads/release/python-3133/)

```
pip3 install --target=<path\to\bot>\plugins\python313\Lib ta-lib
```

## Linux

phBot is bundled with [Python 3.13.3 x64.](https://www.python.org/ftp/python/3.13.3/Python-3.13.3.tar.xz) You will have to compile Python yourself in order to install the correct version of packages with pip.

```bat
LD_LIBRARY_PATH=/opt/python3.13.3/lib /opt/python3.13.3/bin/pip3 install -U --target=/home/$USER/.phBot-crypto/plugins/python313/Lib ta-lib
```

**Building Python**

```
./configure --prefix=/opt/python3.13.3 \
--enable-shared \
--enable-optimizations \
--with-ensurepip=install
```

```
make && sudo make install
```


