Example

Example Python plugin for phBot Crypto

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

signal

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

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.

Last updated