betfair command line interface with simple trade processing

npm install bf-cli
2 downloads in the last week
2 downloads in the last month

Betfair Command Line Interface

The main goal of the bf-cli is to automatically close Open Positions on Betfair Markets. After manually placing Bets via the Betfair website the bf-cli can be run to poll a user's open Orders and, based on user defined strategies, secure profits or accept losses.


The bf-cli is intended to be installed globally and can be installed via npm:

npm install bf-cli -g


In a folder on your machine, create a config.json with your settings:

  "credentials": {
    "username": "",
    "password": "",
    "exchange": "UK"
  "settings": {
    "log": "/path/to/bf-cli.log",
    "throttling": 45
  "strategies": [
      "eventTypes": [ "American Football", "Ice Hockey", "Basketball" ],
      "start": 30.0,
      "stop": -60.0,
      "stopDelay": 30,
      "decay": {
        "type": "margin",
        "value": 300.0,
        "min": 10.0,
        "max": 30.0,
  • credentials
    • username / password: Betfair login details.
    • exchange: UK or AU (target specific BF Markets based on Exchange).
  • settings
    • log: location of log file.
    • throttling: the time in seconds to wait before running loop within commands (e.g. bf run).
  • strategies: an array of objects to be used to handle different event types.
    • eventTypes: a string based array of Betfair Event Names that this Strategy should apply to; alternatively, a wildcard "eventTypes": "*".
    • start: percentage of Order Size aiming to Profit (also could be known as the point to set initial stop loss)
    • stop: max loss (percentage of Order Size to Risk).
    • stopDelay: number of minutes after market start time to wait before closing an order based on stop.
    • decay
      • type: margin only type supported at this point.
      • value: the percentage of profit to secure before reducing to minimum stop loss (e.g. 300%).
      • max: percentage of Order Size to Risk after profit secured (i.e. how much profit to Risk).
      • min: percentage of Order Size to Risk after decay value has been reached.

Run (from your directory):

bf run


  • no support for Markets on the Australian Exchange.
  • see issues for other known limitations (and add an Issue if you have identified new ones)


The API common library (./src/common/api) was heavily influenced by Anton Zemlyanov's betfair node library. Originally a dependency upon this library, the betfair node package had changes made that required refactoring of the bf-cli so a decision was made at this point to fork his library and use an old version with minor patching. It was then anticipated that this common library will evolve over time and be rewritten entirely so it made sense to fold the fork in to the bf-cli. Anton, thanks for the library and if you have any issues let me know.

npm loves you