lnp2pBot / lnp2pBot/bot

feat: Add /scheduleorder command for recurring/auto-republishing orders

Open
#769 2 comments 1 reaction 1 assignee View on GitHub

@ToRyVand is already working on this.

Since Jun 10, 2026.

enhancement priority: medium
Dominant language
TypeScript
Stars
292
Forks
136
Avg merge
19m
Merged PRs (30d)
1

Description

## Problem

Active traders need to manually recreate their buy/sell orders every day. This is tedious and time-consuming, especially for users who consistently offer the same trading conditions.

## Proposed Solution

Add a `/scheduleorder` command that creates orders which automatically republish when they expire (not taken).

### Command Syntax

```
/scheduleorder [premium]
```

**Example:**
```
/scheduleorder sell 0 10 eur f2f 1
```

This creates a sell order for 10 EUR via face-to-face with 1% premium, which will auto-republish if not taken.

## Implementation Details

### 1. New Order Field

Add `republish_count` field to the Order model:
```typescript
republish_count: { type: Number, default: 0 }
```

### 2. New Environment Variable

```
REPUBLISH_ORDER_DAYS=10
```

Maximum number of days an order can be republished. Prevents abandoned orders from republishing forever.

### 3. Modify `jobs/delete_published_orders.js`

When processing expired orders:

```typescript
if (order.republish_count > 0) {
// Republish the order
order.republish_count -= 1;
order.status = "PENDING";
order.expires_at = new Date(Date.now() + EXPIRATION_TIME);
await order.save();
// Publish to channel
} else {
// Normal expiration flow
}
```

### 4. Reset Counter on Take

When an order is taken, reset `republish_count` to `REPUBLISH_ORDER_DAYS`:

```typescript
// In takeorder/takebuy/takesell handler
if (order.republish_count !== undefined) {
order.republish_count = parseInt(process.env.REPUBLISH_ORDER_DAYS || "10");
}
```

This ensures that after a successful trade, the order continues auto-republishing.

## User Flow

1. User creates: `/scheduleorder sell 0 100 usd bank 2`
2. Order is published with `republish_count = 10`
3. Order expires (not taken) → job republishes it, `republish_count = 9`
4. ... repeats ...
5. If `republish_count = 0` and expires → order is deleted normally
6. If order is taken at any point → `republish_count` resets to 10

## Edge Cases

- **User wants to stop auto-republish**: Add `/cancelschedule ` command to set `republish_count = 0`
- **Order in dispute**: Should NOT auto-republish (check status before republishing)
- **User changes trading conditions**: They cancel and create a new scheduled order

## Benefits

- Saves time for active traders
- Increases liquidity in channels (more consistent order availability)
- Self-cleaning: abandoned orders stop after N days

---

_Based on discussion #462_

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.