Skip to content

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

@mostronatorcoder

Description

@mostronatorcoder

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 <buy|sell> <amount> <fiat_amount> <fiat_code> <payment_method> [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:

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:

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:

// 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 <order_id> 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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions