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
2 changes: 1 addition & 1 deletion examples/cases/createorder/create_conditional_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ async def run_example():
adjust_price_by_pct = get_adjust_price_by_pct(market.trading_config)

order_size = market.trading_config.min_order_size
order_price = adjust_price_by_pct(market.market_stats.bid_price, -15.0)
order_trigger_price = adjust_price_by_pct(market.market_stats.bid_price, -10.0)
order_price = adjust_price_by_pct(order_trigger_price, -5.0)

LOGGER.info("Creating CONDITIONAL order object for market: %s", market.name)

Expand Down
6 changes: 2 additions & 4 deletions examples/cases/createorder/create_market_order.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import logging
from asyncio import run
from decimal import Decimal

from examples.utils import create_trading_client
from x10.config import BTC_USD_MARKET
from x10.config import BTC_USD_MARKET, DEFAULT_MARKET_PRICE_SLIPPAGE
from x10.perpetual.order_object import create_order_object
from x10.perpetual.orders import OrderSide, OrderType, TimeInForce
from x10.utils.order import get_price_with_slippage

LOGGER = logging.getLogger()
MARKET_NAME = BTC_USD_MARKET
SLIPPAGE = Decimal(0.0075)


async def run_example():
Expand All @@ -28,7 +26,7 @@ async def run_example():
side=order_side,
price=best_market_price,
min_price_change=market.trading_config.min_price_change,
slippage=SLIPPAGE,
slippage=DEFAULT_MARKET_PRICE_SLIPPAGE,
)

LOGGER.info("Creating MARKET order object for market: %s", market.name)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import asyncio
import logging
from decimal import Decimal

from examples.utils import create_blocking_client
from x10.config import BTC_USD_MARKET
from x10.config import BTC_USD_MARKET, DEFAULT_MARKET_PRICE_SLIPPAGE
from x10.perpetual.configuration import TESTNET_CONFIG
from x10.perpetual.orderbook import OrderBook
from x10.perpetual.orders import OrderSide, OrderType, TimeInForce
Expand All @@ -12,7 +11,6 @@
LOGGER = logging.getLogger()
ENDPOINT_CONFIG = TESTNET_CONFIG
MARKET_NAME = BTC_USD_MARKET
SLIPPAGE = Decimal(0.0075)


async def get_orderbook_best_ask(market_name: str):
Expand Down Expand Up @@ -58,7 +56,7 @@ async def run_example():
side=order_side,
price=best_ask_entry.price,
min_price_change=market.trading_config.min_price_change,
slippage=SLIPPAGE,
slippage=DEFAULT_MARKET_PRICE_SLIPPAGE,
)

LOGGER.info("Creating MARKET order for market %s: %s@%s", market.name, order_size, order_price)
Expand Down
9 changes: 5 additions & 4 deletions examples/cases/tpsl/create_limit_order_with_partial_tpsl.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import logging
from asyncio import run
from decimal import Decimal

from examples.utils import (
create_trading_client,
find_order_and_cancel,
get_adjust_price_by_pct,
)
from x10.config import BTC_USD_MARKET
from x10.config import BTC_USD_MARKET, DEFAULT_MARKET_PRICE_SLIPPAGE
from x10.perpetual.order_object import OrderTpslTriggerParam, create_order_object
from x10.perpetual.orders import (
OrderPriceType,
Expand All @@ -31,9 +32,9 @@ async def run_example():

order_price = adjust_price_by_pct(market.market_stats.bid_price, -10.0)
tp_trigger_price = adjust_price_by_pct(order_price, 0.5)
tp_price = adjust_price_by_pct(order_price, 1.0)
tp_price = adjust_price_by_pct(tp_trigger_price, 0.5)
sl_trigger_price = adjust_price_by_pct(order_price, -0.5)
sl_price = adjust_price_by_pct(order_price, -1.0)
sl_price = adjust_price_by_pct(sl_trigger_price, -DEFAULT_MARKET_PRICE_SLIPPAGE * Decimal("100"))

LOGGER.info("Creating LIMIT order object with TPSL for market: %s", market.name)

Expand All @@ -58,7 +59,7 @@ async def run_example():
trigger_price=sl_trigger_price,
trigger_price_type=OrderTriggerPriceType.LAST,
price=sl_price,
price_type=OrderPriceType.LIMIT,
price_type=OrderPriceType.MARKET,
),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ async def run_example():

order_price = adjust_price_by_pct(market.market_stats.bid_price, -10.0)
tp_trigger_price = adjust_price_by_pct(order_price, 0.5)
tp_price = adjust_price_by_pct(order_price, 1.0)
tp_price = adjust_price_by_pct(tp_trigger_price, 0.5)
sl_trigger_price = adjust_price_by_pct(order_price, -0.5)
sl_price = adjust_price_by_pct(order_price, -1.0)
sl_price = adjust_price_by_pct(sl_trigger_price, -0.5)

LOGGER.info("Creating LIMIT order object with TPSL for market: %s", market.name)

Expand Down
4 changes: 2 additions & 2 deletions examples/cases/tpsl/create_partial_tpsl_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ async def run_example():

last_price = market.market_stats.last_price
tp_trigger_price = adjust_price_by_pct(last_price, -5)
tp_price = adjust_price_by_pct(last_price, -10)
tp_price = adjust_price_by_pct(tp_trigger_price, -5)
sl_trigger_price = adjust_price_by_pct(last_price, 5)
sl_price = adjust_price_by_pct(last_price, 10)
sl_price = adjust_price_by_pct(sl_trigger_price, 5)

LOGGER.info("Creating partial TPSL order object for market: %s", market.name)

Expand Down
4 changes: 2 additions & 2 deletions examples/cases/tpsl/create_position_tpsl_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ async def run_example():

last_price = market.market_stats.last_price
tp_trigger_price = adjust_price_by_pct(last_price, -5)
tp_price = adjust_price_by_pct(last_price, -10)
tp_price = adjust_price_by_pct(tp_trigger_price, -5)
sl_trigger_price = adjust_price_by_pct(last_price, 5)
sl_price = adjust_price_by_pct(last_price, 10)
sl_price = adjust_price_by_pct(sl_trigger_price, 5)

LOGGER.info("Creating entire position TPSL order object for market: %s", market.name)

Expand Down
2 changes: 1 addition & 1 deletion examples/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def create_stream_client(endpoint_config: EndpointConfig = TESTNET_CONFIG):


def get_adjust_price_by_pct(config: TradingConfigModel):
def adjust_price_by_pct(price: Decimal, pct: int):
def adjust_price_by_pct(price: Decimal, pct: Decimal | int):
return config.round_price(price + price * Decimal(pct) / 100)

return adjust_price_by_pct
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "x10-python-trading-starknet"
version = "1.3.0"
version = "1.3.1"
description = "Python client for X10 API"
authors = ["X10 <tech@ex10.org>"]
repository = "https://github.com/x10xchange/python_sdk"
Expand Down
2 changes: 2 additions & 0 deletions x10/config.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import importlib.metadata
from decimal import Decimal

BTC_USD_MARKET = "BTC-USD"
SOL_USD_MARKET = "SOL-USD"
ADA_USD_MARKET = "ADA-USD"
ETH_USD_MARKET = "ETH-USD"

DEFAULT_MARKET_PRICE_SLIPPAGE = Decimal("0.0075")
DEFAULT_REQUEST_TIMEOUT_SECONDS = 500
SDK_VERSION = importlib.metadata.version("x10-python-trading-starknet")
USER_AGENT = f"X10PythonTradingClient/{SDK_VERSION}"
5 changes: 1 addition & 4 deletions x10/perpetual/order_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,7 @@ def create_tpsl_trigger_model(trigger_param: OrderTpslTriggerParam | None):
return None

if tp_sl_type is None:
raise ValueError("`tp_sl_type` must be provided if `take_profit` or `stop_loss` is specified")

if trigger_param.price_type == OrderPriceType.MARKET:
raise NotImplementedError("TPSL `MARKET` price type is not supported yet")
raise ValueError("`tp_sl_type` must be provided if `take_profit` and/or `stop_loss` is specified")

return __create_order_tpsl_trigger_model(
trigger_param=trigger_param,
Expand Down
Loading