Skip to content

feat: add userTransfer method for internal account transfers#119

Open
alexonconceicao wants to merge 1 commit intoln-markets:masterfrom
alexonconceicao:userTransferMethod
Open

feat: add userTransfer method for internal account transfers#119
alexonconceicao wants to merge 1 commit intoln-markets:masterfrom
alexonconceicao:userTransferMethod

Conversation

@alexonconceicao
Copy link

@alexonconceicao alexonconceicao commented Apr 7, 2025


Title

feat(rest): add userTransfer to enable internal transfers between LN Markets accounts

Summary

This PR adds the userTransfer method to the REST client, enabling internal transfers between LN Markets accounts via POST /user/transfer with required authentication. The method is now exported in createRestClient.

Context and Motivation

This PR exposes the official internal transfer route, enabling:

  • Automated rebalancing between accounts
  • Splitting deposits across subaccounts
  • Internal settlement without on-chain withdrawals

Main Changes

  • Implemented userTransfer(data) in src/rest.ts
  • Forwards the provided payload to POST /user/transfer
  • Added export in createRestClient

Code snippet:

const userTransfer = (data: any) => {
  return request({
    method: 'POST',
    path: '/user/transfer',
    requireAuth: true,
    data,
  });
};

Export:

userTransfer,

API

Endpoint: POST /user/transfer
Auth: required

Example request body:

{
  "to": "user_or_account_identifier",
  "amount": 100000
}

Example response:

{
  "transferId": "abc123",
  "status": "accepted",
  "amount": 100000
}

Usage

Node.js:

import { createRestClient } from '@ln-markets/api';

const client = createRestClient({ key: process.env.LNM_KEY, secret: process.env.LNM_SECRET });

const res = await client.userTransfer({
  to: 'targetUser',
  amount: 100000
});

console.log(res);

cURL:

curl -X POST https://api.lnmarkets.com/user/transfer \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -d '{"to":"targetUser","amount":100000}'

Design Considerations

  • Consistent with existing client pattern: thin wrapper, no local validation
  • Backward compatible: only adds a new method
  • Idempotency and rate limiting are handled server-side
  • Errors bubble up through request()

Documentation

  • Add to REST methods section of the library with minimal usage example
  • Clarify authentication requirements and supported payload fields

Checklist

  • Implemented with requireAuth
  • Exported in createRestClient
  • Generic typing for compatibility

Impact

Low risk. This change only exposes an existing API endpoint, without modifying current methods or behavior.


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant