Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 107 additions & 0 deletions derive_client/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Cli module in order to allow interaction.
"""

import json
import math
import os
from pathlib import Path
Expand Down Expand Up @@ -752,5 +753,111 @@ def create_order(ctx, instrument_name, side, price, amount, order_type, instrume
print(result)


@positions.command("transfer")
@click.pass_context
@click.option(
"--instrument-name",
"-i",
type=str,
required=True,
help="Name of the instrument to transfer",
)
@click.option(
"--amount",
"-a",
type=float,
required=True,
help="Amount to transfer (absolute value)",
)
@click.option(
"--limit-price",
"-p",
type=float,
required=True,
help="Limit price for the transfer",
)
@click.option(
"--from-subaccount",
"-f",
type=int,
required=True,
help="Subaccount ID to transfer from",
)
@click.option(
"--to-subaccount",
"-t",
type=int,
required=True,
help="Subaccount ID to transfer to",
)
@click.option(
"--position-amount",
type=float,
default=None,
help="Original position amount (if not provided, will be fetched)",
)
def transfer_position(ctx, instrument_name, amount, limit_price, from_subaccount, to_subaccount, position_amount):
"""Transfer a single position between subaccounts."""
client: BaseClient = ctx.obj["client"]
Comment thread
Aviksaikat marked this conversation as resolved.
result = client.transfer_position(
instrument_name=instrument_name,
amount=amount,
limit_price=limit_price,
from_subaccount_id=from_subaccount,
to_subaccount_id=to_subaccount,
position_amount=position_amount,
)
print(result)


@positions.command("transfer-multiple")
@click.pass_context
@click.option(
"--positions-json",
"-p",
type=str,
required=True,
help='JSON string of positions to transfer, e.g. \'[{"instrument_name": "ETH-PERP", "amount": 0.1, "limit_price": 2000}]\'', # noqa: E501
)
@click.option(
"--from-subaccount",
"-f",
type=int,
required=True,
help="Subaccount ID to transfer from",
)
@click.option(
"--to-subaccount",
"-t",
type=int,
required=True,
help="Subaccount ID to transfer to",
)
@click.option(
"--global-direction",
"-d",
type=click.Choice(["buy", "sell"]),
default="buy",
help="Global direction for the transfer",
)
def transfer_positions(ctx, positions_json, from_subaccount, to_subaccount, global_direction):
"""Transfer multiple positions between subaccounts."""

try:
positions = json.loads(positions_json)
except json.JSONDecodeError as e:
click.echo(f"Error parsing positions JSON: {e}")
return

client: DeriveClient = ctx.obj["client"]
result = client.transfer_positions(
positions=positions,
from_subaccount_id=from_subaccount,
to_subaccount_id=to_subaccount,
global_direction=global_direction,
)
print(result)


if __name__ == "__main__":
cli() # pylint: disable=no-value-for-parameter
Loading
Loading