Skip to content

ztuntrade/untrade-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Untrade SDK

Python Version

Installation

Execute the git clone command:

git clone https://github.com/ztuntrade/untrade-sdk.git && cd untrade-sdk

Install the package using pip3:

pip3 install .

Initialisation

To start using the Untrade API, first initialize the client:

from untrade.client import Client
client = Client()

Module Functions

Create New Order

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
)

Parameters

  • 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.

Close Order

Closes an existing trading order.

client.close_order(
    symbol="BTCUSDT",
    market="COIN-M",
    parent_order_id="68b195ec-150e-47e1-8e01-694b719acdd8"
)

Parameters

  • 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.

Target Order

client.create_target_order(
    symbol="BTCUSDT",
    type="TAKE_PROFIT_MARKET",
    market="COIN-M",
    stop_price=45000,
    parent_order_id="68b195ec-150e-47e1-8e01-694b719acdd8"
)

Parameters

  • 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.

Stop-Loss Order

client.create_stoploss_order(
    symbol="BTCUSDT",
    type="STOP_MARKET",
    market="COIN-M",
    stop_price=35000,
    parent_order_id="68b195ec-150e-47e1-8e01-694b719acdd8"
)

Parameters

  • 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.

Backtest

Use the following method to initiate a backtest:

client.backtest(file_path="/your/path")

Parameters

  • 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.

File Requirements

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.

Important Note

  • If you are willing to open a long trade and cut it: then your entry is 1 and exit is -1.
  • If you are willing to open a short trade and cut it: then your entry is -1 and exit is 1.
  • When there is no signal - mark the timestamps with 0.
  • In between entry (1 or -1) and exit (1 or -1) of a trade, mark the timestamps with 0.

Example CSV

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

Error Codes

  • 4001: Position not needed if quantity provided
  • 4002: Leverage mandatory for Futures (USD-M, COIN-M)
  • 4003: Leverage not for SPOT orders
  • 4004: Specify Quantity or Position
  • 4005: Price needed for LIMIT orders
  • 4006: Target price > Entry price
  • 4007: Stop-Loss price > Entry price
  • 4008: Only .csv files accepted
  • 4009: Parent order not found
  • 4010: Parent order already closed
  • 4011: Backtest error
  • 4012: jupyter_id not found

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages