Execute the git clone command:
git clone https://github.com/ztuntrade/untrade-sdk.git && cd untrade-sdk
Install the package using pip3:
pip3 install .
To start using the Untrade API, first initialize the client:
from untrade.client import Client
client = Client()To create a new order, use the following function:
client.create_order(
symbol="BTCUSDT",
side="BUY",
type="MARKET",
market="COIN-M",
quantity=100,
leverage=10,
target=45000,
stop_loss=35000
)symbol(string): The trading pair symbol (e.g., BTCUSDT, ETHUSDT).side(string): 'BUY' or 'SELL'.type(string): 'LIMIT' or 'MARKET'.market(string): 'SPOT', 'COIN-M', or 'USD-M'.quantity(float, optional): Trade quantity.leverage(int, optional): Leverage for the trade (for non-SPOT markets).target(float, optional): Target price.stop_loss(float, optional): Stop loss price.price(float, optional): Entry price (for LIMIT orders).position(float, optional): Position size.
Important Note: Specify either position or quantity. Providing both or neither triggers an error.
Closes an existing trading order.
client.close_order(
symbol="BTCUSDT",
market="COIN-M",
parent_order_id="68b195ec-150e-47e1-8e01-694b719acdd8"
)symbol(string): The trading pair symbol (e.g., BTCUSDT, ETHUSDT).market(string): 'SPOT', 'COIN-M', or 'USD-M'.parent_order_id(string): The ID of the parent order being closed.
client.create_target_order(
symbol="BTCUSDT",
type="TAKE_PROFIT_MARKET",
market="COIN-M",
stop_price=45000,
parent_order_id="68b195ec-150e-47e1-8e01-694b719acdd8"
)symbol(string): The trading pair symbol (e.g., BTCUSDT, ETHUSDT).type(string): 'TAKE_PROFIT_MARKET'.market(string): 'SPOT', 'COIN-M', or 'USD-M'.stop_price(float): Stop price for target.parent_order_id(string): The ID of the parent order being closed.
client.create_stoploss_order(
symbol="BTCUSDT",
type="STOP_MARKET",
market="COIN-M",
stop_price=35000,
parent_order_id="68b195ec-150e-47e1-8e01-694b719acdd8"
)symbol(string): The trading pair symbol (e.g., BTCUSDT, ETHUSDT).type(string): 'STOP_MARKET'.market(string): 'SPOT', 'COIN-M', or 'USD-M'.stop_price(float): Stop Price of stop-loss.parent_order_id(string): The ID of the parent order being closed.
Use the following method to initiate a backtest:
client.backtest(file_path="/your/path")leverage(int): The leverage for the trade (for non-SPOT markets). Default value is 1.chain(bool): Specifies whether to use chain trading(Reverse orders). Default value is False.commission(float): The commission rate for the trade. Default value is 0.15.
Format: CSV (Comma-Separated Values)
Content Structure: The CSV file must include the following headers in the exact order:
- Index (int)
- datetime (datetime) : Format YYYY-MM-DD HH:MM:SS
- open (float)
- high (float)
- low (float)
- close (float)
- volume (float)
- signals (int)
Each row in the file should represent a different time point in the dataset.
- If you are willing to open a long trade and cut it: then your entry is
1and exit is-1. - If you are willing to open a short trade and cut it: then your entry is
-1and exit is1. - When there is no signal - mark the timestamps with
0. - In between entry (
1or-1) and exit (1or-1) of a trade, mark the timestamps with0.
Index,datetime,open,high,low,close,volume,signals
0,2022-02-01 05:30:00,38466.9,38627.35,38276.43,38342.36,1058.42599,0
4001: Position not needed if quantity provided4002: Leverage mandatory for Futures (USD-M, COIN-M)4003: Leverage not for SPOT orders4004: Specify Quantity or Position4005: Price needed for LIMIT orders4006: Target price > Entry price4007: Stop-Loss price > Entry price4008: Only .csv files accepted4009: Parent order not found4010: Parent order already closed4011: Backtest error4012: jupyter_id not found