Hello dYdX Team,
I noticed that the v4-chain
repository does not appear to have a feature for specifying the margin type (Cross or Isolated) during order placement via the clob
module.
Adding this capability as a parameter in the place-order
command would greatly improve flexibility for traders managing their margin strategies.
Currently, I am using the following code to place an order. By default, it places orders with Cross Margin, but there is no option to switch to Isolated Margin:
import asyncio
import random
from dydx_v4_client import MAX_CLIENT_ID, NodeClient, OrderFlags, Wallet
from dydx_v4_client.indexer.rest.constants import OrderType
from dydx_v4_client.indexer.rest.indexer_client import IndexerClient
from dydx_v4_client.network import TESTNET
from dydx_v4_client.node.market import Market
from v4_proto.dydxprotocol.clob.order_pb2 import Order
MARKET_ID = "ETH-USD"
TEST_ADDRESS = ''
DYDX_TEST_MNEMONIC = (
)
async def place_market_order(size: float):
try:
node = await NodeClient.connect(TESTNET.node)
indexer = IndexerClient(TESTNET.rest_indexer)
market_data = await indexer.markets.get_perpetual_markets(MARKET_ID)
market = Market(market_data["markets"][MARKET_ID])
wallet = await Wallet.from_mnemonic(node, DYDX_TEST_MNEMONIC, TEST_ADDRESS)
account_info = await node.get_account(TEST_ADDRESS)
wallet.sequence = account_info.sequence
order_id = market.order_id(
TEST_ADDRESS, 0, random.randint(0, MAX_CLIENT_ID), OrderFlags.SHORT_TERM
)
current_block = await node.latest_block_height()
new_order = market.order(
order_id=order_id,
order_type=OrderType.LIMIT,
side=Order.Side.SIDE_SELL,
size=size,
price=0,
time_in_force=Order.TimeInForce.TIME_IN_FORCE_UNSPECIFIED,
reduce_only=False,
good_til_block=current_block + 10,
)
transaction = await node.place_order(
wallet=wallet,
order=new_order,
)
print(f"Transaction successful: {transaction}")
wallet.sequence += 1
except Exception as e:
print(f"An error occurred: {e}")
asyncio.run(place_market_order(1.053))
As you can see, this code places orders with Cross Margin by default, and there is no option to switch to Isolated Margin.
Could you clarify whether this functionality is currently supported or if there are plans to include it in future updates?
Thank you for your time and consideration.
Best regards,