Skip to content

theborakompanioni/cln-spend-and-replace-plugin

Repository files navigation

Build GitHub Release License

Logo Logo

cln-spend-and-replace-plugin

Core Lightning ⚡ plugin to immediately re-stack all outgoing sats from your node.

Note: Most code is still experimental - use with caution do not use till v0.1.0 is reached. This project is under active development. Pull requests and issues are welcome. Look at the changelog to track notable changes.

  • Place market orders on exchange for all outgoing payments
  • In dry-run mode (or on any other network than mainnet), place massively undervalued limit orders
  • Blocked: Withdraw via Lightning automatically (according to @pierrerochard, Kraken is working on enabling programmatic withdrawals via lightning; however, it is not live yet)

RPC commands

snr-listconfigs

Command to list all configuration options.

user@host:~$ lightning-cli snr-listconfigs
{
  "result": {
    "dry-run": false,
    "fiat-currency": {
      "default": "USD"
    },
    "exchange": {
      "name": "Kraken",
      "host": "api.kraken.com"
    }
  }
}

snr-version

Command to print the plugin version.

user@host:~$ lightning-cli snr-version
{
  "result": {
    "version": "0.1.0-dev.4.uncommitted+7f363fa"
  }
}

snr-exchangeinfo

Command to list exchange specific information.

user@host:~$ lightning-cli snr-exchangeinfo
{
  "result" : {
    "name": "Kraken",
    "description": "Kraken is a Bitcoin exchange operated by Payward, Inc.",
    "host": "api.kraken.com",
    "metadata": {
      "instruments": {
        "BTC/USD": {
          "min-amount" : "0.00001"
        }
      }
    }
  }
}

snr-ticker

Get the ticker representing the current exchange rate for the provided currency.

user@host:~$ lightning-cli snr-ticker
{
  "result": {
    "BTC/USD": {
      "ask": "27308.20000",
      "bid": "27308.20000",
      "high": "28000.00000",
      "low": "27155.00000",
      "open": "27588.10000",
      "last": "27308.20000"
    }
  }
}
user@host:~$ lightning-cli snr-ticker GBP
{
  "result": {
    "BTC/GBP": {
      "ask": "21896.70000",
      "bid": "21896.70000",
      "high": "22496.10000",
      "low": "21803.60000",
      "open": "22201.40000",
      "last": "21901.50000"
    }
  }
}

snr-balance

Get the balance of your account.

user@host:~$ lightning-cli snr-balance
{
  "result": {
    "_": {
      "id": null,
      "name": null,
      "balances": {
        "BTC": {
          "available": "0.0002100000",
          "available-for-withdrawal": "0.0002100000",
          "borrowed": "0",
          "depositing": "0",
          "frozen": "0",
          "loaned": "0",
          "total": "0.0002100000",
          "withdrawing": "0"
        },
        "USD": {
          "available": "42.1337",
          "available-for-withdrawal": "42.1337",
          "borrowed": "0",
          "depositing": "0",
          "frozen": "0",
          "loaned": "0",
          "total": "42.1337",
          "withdrawing": "0"
        }
      }
    },
    "margin": {
      "id": "margin",
      "name": "margin",
      "balances": {
        "BTC": {
          "available": "0.0002100000",
          "available-for-withdrawal": "0.0002100000",
          "borrowed": "0",
          "depositing": "0",
          "frozen": "0",
          "loaned": "0",
          "total": "0.0002100000",
          "withdrawing": "0"
        },
        "USD": {
          "available": "42.1337",
          "available-for-withdrawal": "42.1337",
          "borrowed": "0",
          "depositing": "0",
          "frozen": "0",
          "loaned": "0",
          "total": "42.1337",
          "withdrawing": "0"
        }
      }
    }
  }
}

snr-history

Get the trade history of your account.

user@host:~$ lightning-cli snr-history
{
  "result": {
    "open": {
      "abcdef-00000-000001": {
        "id": "abcdef-00000-000001",
        "type": "BID",
        "status": "NEW",
        "is-open": true,
        "is-final": false,
        "original-amount": "0.42",
        "remaining-amount": "0.42",
        "limit-price": "21.0",
        "asset-pair": "BTC/USD",
        "ref": "0",
        "date": "2021-05-26T03:33:20Z",
        "timestamp": 1622000000
      }
    },
    "closed": {
      "abcdef-00000-000000": {
        "id": "abcdef-00000-000000",
        "type": "BID",
        "order-id": "abcdef",
        "price": "21000.0",
        "original-amount": "0.21",
        "asset-pair": "BTC/USD",
        "ref": "",
        "fee-amount": "0.090103",
        "fee-currency": "USD",
        "date": "2021-05-14T13:46:40Z",
        "timestamp": 1621000000
      }
    }
  }
}

snr-placetestorder

Place a minimal, greatly undervalued limit order to test if exchange settings are working properly.

user@host:~$ lightning-cli snr-placetestorder
{
  "result": {
    "order": {
      "id": "abcdef-00000-000002",
      "type": "BID",
      "asset-pair": "BTC/GBP",
      "amount": "0.00001000",
      "price": "2189.67"
    }
  }
}

Development

Requirements

  • java >=17
  • docker

Build

./gradlew build -x test

Run

TBD

Test

./gradlew test integrationTest --rerun-tasks

Dependency Verification

Gradle is used for checksum and signature verification of dependencies.

# write metadata for dependency verification
./gradlew --write-verification-metadata pgp,sha256 --export-keys

See Gradle Userguide: Verifying dependencies for more information.

Checkstyle

Checkstyle with adapted google_checks is used for checking Java source code for adherence to a Code Standard.

# check for code standard violations with checkstyle
./gradlew checkstyleMain --rerun-tasks

SpotBugs

SpotBugs is used for static code analysis.

# invoke static code analysis with spotbugs
./gradlew spotbugsMain --rerun-tasks

Contributing

All contributions and ideas are always welcome. For any question, bug or feature request, please create an issue. Before you start, please read the contributing guidelines.

Resources


License

The project is licensed under the Apache License. See LICENSE for details.

About

Core Lightning ⚡ plugin to immediately re-stack all outgoing sats from your node.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Languages