Skip to content
Merged
3 changes: 3 additions & 0 deletions MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ classes were also renamed to follow the consistent `*Model` suffix convention.
- `StarkPerpetualAccount` (previously in `x10.perpetual.accounts`) has moved to `x10.core.stark_account`.
- The package now ships a `py.typed` marker (PEP 561), so mypy will now type-check against
the SDK's inline annotations by default.
- `x10.perpetual.configuration` has been **deleted**. All config types and pre-built instances now live in `x10.config`.
- `TESTNET_CONFIG` and `MAINNET_CONFIG` are now instances of the new `Config` dataclass (groups URLs, singing settings, defaults).
- Market names constants have been removed from `x10.config`. Define market name strings inline in your own code.
3 changes: 1 addition & 2 deletions examples/cases/advanced/load_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
from asyncio import run
from typing import Set

from examples.utils import create_trading_client
from x10.config import BTC_USD_MARKET
from examples.utils import BTC_USD_MARKET, create_trading_client
from x10.models.market import MarketModel
from x10.models.order import OrderSide
from x10.perpetual.order_object import create_order_object
Expand Down
3 changes: 1 addition & 2 deletions examples/cases/advanced/market_maker.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
from signal import SIGINT, SIGTERM
from typing import Awaitable, Callable, List

from examples.utils import create_trading_client
from x10.config import BTC_USD_MARKET
from examples.utils import BTC_USD_MARKET, create_trading_client
from x10.models.order import OrderSide
from x10.perpetual.orderbook import OrderBook, OrderBookEntry

Expand Down
8 changes: 4 additions & 4 deletions examples/cases/advanced/onboarding_with_eth_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
from eth_account.signers.local import LocalAccount

from examples.utils import init_env
from x10.config import TESTNET_CONFIG
from x10.core.stark_account import StarkPerpetualAccount
from x10.perpetual.configuration import TESTNET_CONFIG
from x10.perpetual.trading_client.trading_client import PerpetualTradingClient
from x10.perpetual.user_client.user_client import UserClient
from x10.utils.string import is_hex_string

LOGGER = logging.getLogger()
ENDPOINT_CONFIG = TESTNET_CONFIG
CONFIG = TESTNET_CONFIG


async def run_example():
Expand All @@ -23,7 +23,7 @@ async def run_example():
assert is_hex_string(eth_account_private_key), "`eth_account_private_key` must be a hex string"

eth_local_account: LocalAccount = Account.from_key(eth_account_private_key)
user_client = UserClient(endpoint_config=ENDPOINT_CONFIG, l1_private_key=eth_local_account.key.hex)
user_client = UserClient(config=CONFIG, l1_private_key=eth_local_account.key.hex)

LOGGER.info("Onboarding with ETH account %s...", eth_local_account.address)

Expand All @@ -36,7 +36,7 @@ async def run_example():
private_key=main_account.l2_key_pair.private_hex,
vault=main_account.account.l2_vault,
)
trading_client = PerpetualTradingClient(ENDPOINT_CONFIG, starknet_account)
trading_client = PerpetualTradingClient(CONFIG, starknet_account)

LOGGER.info("StarkNet public key: %s", starknet_account.public_key)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
from asyncio import run

from examples.utils import (
BTC_USD_MARKET,
create_trading_client,
find_order_and_cancel,
get_adjust_price_by_pct,
init_env,
)
from x10.config import BTC_USD_MARKET
from x10.models.order import OrderSide, TimeInForce
from x10.perpetual.order_object import create_order_object

Expand Down Expand Up @@ -45,8 +45,8 @@ async def run_example():
time_in_force=TimeInForce.GTT,
reduce_only=False,
post_only=True,
builder_id=builder_id,
builder_fee=builder_fee,
builder_id=builder_id,
)

LOGGER.info("Placing order...")
Expand Down
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 @@ -2,11 +2,11 @@
from asyncio import run

from examples.utils import (
BTC_USD_MARKET,
create_trading_client,
find_order_and_cancel,
get_adjust_price_by_pct,
)
from x10.config import BTC_USD_MARKET
from x10.models.order import (
OrderPriceType,
OrderSide,
Expand Down
2 changes: 1 addition & 1 deletion examples/cases/createorder/create_limit_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
from asyncio import run

from examples.utils import (
BTC_USD_MARKET,
create_trading_client,
find_order_and_cancel,
get_adjust_price_by_pct,
)
from x10.config import BTC_USD_MARKET
from x10.models.order import OrderSide, TimeInForce
from x10.perpetual.order_object import create_order_object

Expand Down
5 changes: 2 additions & 3 deletions examples/cases/createorder/create_market_order.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import logging
from asyncio import run

from examples.utils import create_trading_client
from x10.config import BTC_USD_MARKET, DEFAULT_MARKET_PRICE_SLIPPAGE
from examples.utils import BTC_USD_MARKET, create_trading_client
from x10.models.order import OrderSide, OrderType, TimeInForce
from x10.perpetual.order_object import create_order_object
from x10.utils.order import get_price_with_slippage
Expand All @@ -26,7 +25,7 @@ async def run_example():
side=order_side,
price=best_market_price,
min_price_change=market.trading_config.min_price_change,
slippage=DEFAULT_MARKET_PRICE_SLIPPAGE,
slippage=trading_client.config.defaults.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,15 +1,14 @@
import asyncio
import logging

from examples.utils import create_blocking_client
from x10.config import BTC_USD_MARKET, DEFAULT_MARKET_PRICE_SLIPPAGE
from examples.utils import BTC_USD_MARKET, create_blocking_client
from x10.config import TESTNET_CONFIG
from x10.models.order import OrderSide, OrderType, TimeInForce
from x10.perpetual.configuration import TESTNET_CONFIG
from x10.perpetual.orderbook import OrderBook
from x10.utils.order import get_price_with_slippage

LOGGER = logging.getLogger()
ENDPOINT_CONFIG = TESTNET_CONFIG
CONFIG = TESTNET_CONFIG
MARKET_NAME = BTC_USD_MARKET


Expand All @@ -21,7 +20,7 @@ async def best_ask_initialised(_best_ask):
best_ask_condition.notify_all()

orderbook = await OrderBook.create(
ENDPOINT_CONFIG,
CONFIG,
market_name=market_name,
start=True,
best_ask_change_callback=best_ask_initialised,
Expand All @@ -39,7 +38,7 @@ async def best_ask_initialised(_best_ask):


async def run_example():
blocking_client = create_blocking_client(ENDPOINT_CONFIG)
blocking_client = create_blocking_client(CONFIG)
markets = await blocking_client.get_markets()
market = markets[MARKET_NAME]

Expand All @@ -56,7 +55,7 @@ async def run_example():
side=order_side,
price=best_ask_entry.price,
min_price_change=market.trading_config.min_price_change,
slippage=DEFAULT_MARKET_PRICE_SLIPPAGE,
slippage=blocking_client.config.defaults.market_price_slippage,
)

LOGGER.info("Creating MARKET order for market %s: %s@%s", market.name, order_size, order_price)
Expand Down
3 changes: 1 addition & 2 deletions examples/cases/stream/subscribe_to_multiple_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
from asyncio import run
from signal import SIGINT, SIGTERM

from examples.utils import create_stream_client, init_env
from x10.config import BTC_USD_MARKET
from examples.utils import BTC_USD_MARKET, create_stream_client, init_env

LOGGER = logging.getLogger()
MARKET_NAME = BTC_USD_MARKET
Expand Down
6 changes: 4 additions & 2 deletions examples/cases/tpsl/create_limit_order_with_partial_tpsl.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
from decimal import Decimal

from examples.utils import (
BTC_USD_MARKET,
create_trading_client,
find_order_and_cancel,
get_adjust_price_by_pct,
)
from x10.config import BTC_USD_MARKET, DEFAULT_MARKET_PRICE_SLIPPAGE
from x10.models.order import (
OrderPriceType,
OrderSide,
Expand All @@ -34,7 +34,9 @@ async def run_example():
tp_trigger_price = adjust_price_by_pct(order_price, 0.5)
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(sl_trigger_price, -DEFAULT_MARKET_PRICE_SLIPPAGE * Decimal("100"))
sl_price = adjust_price_by_pct(
sl_trigger_price, -trading_client.config.defaults.market_price_slippage * Decimal("100")
)

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
from asyncio import run

from examples.utils import (
BTC_USD_MARKET,
create_trading_client,
find_order_and_cancel,
get_adjust_price_by_pct,
)
from x10.config import BTC_USD_MARKET
from x10.models.order import (
OrderPriceType,
OrderSide,
Expand Down
2 changes: 1 addition & 1 deletion examples/cases/tpsl/create_partial_tpsl_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
from decimal import Decimal

from examples.utils import (
BTC_USD_MARKET,
create_trading_client,
find_order_and_cancel,
get_adjust_price_by_pct,
)
from x10.config import BTC_USD_MARKET
from x10.models.order import (
OrderPriceType,
OrderSide,
Expand Down
2 changes: 1 addition & 1 deletion examples/cases/tpsl/create_position_tpsl_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
from decimal import Decimal

from examples.utils import (
BTC_USD_MARKET,
create_trading_client,
find_order_and_cancel,
get_adjust_price_by_pct,
)
from x10.config import BTC_USD_MARKET
from x10.models.order import (
OrderPriceType,
OrderSide,
Expand Down
2 changes: 1 addition & 1 deletion examples/cases/withdraw/withdrawal_bridged.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from decimal import Decimal

from examples.utils import create_trading_client
from x10.perpetual.configuration import MAINNET_CONFIG
from x10.config import MAINNET_CONFIG

LOGGER = logging.getLogger()
FEE_THRESHOLD_USDC = 2
Expand Down
2 changes: 1 addition & 1 deletion examples/cases/withdraw/withdrawal_starknet.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from decimal import Decimal

from examples.utils import create_trading_client
from x10.perpetual.configuration import MAINNET_CONFIG
from x10.config import MAINNET_CONFIG
from x10.utils.nonce import generate_nonce
from x10.utils.string import is_hex_string

Expand Down
16 changes: 9 additions & 7 deletions examples/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@
import yaml
from dotenv import load_dotenv

from x10.config import TESTNET_CONFIG, Config
from x10.core.stark_account import StarkPerpetualAccount
from x10.models.market import TradingConfigModel
from x10.perpetual.configuration import TESTNET_CONFIG, EndpointConfig
from x10.perpetual.simple_client.simple_trading_client import BlockingTradingClient
from x10.perpetual.stream_client import PerpetualStreamClient
from x10.perpetual.trading_client import PerpetualTradingClient
from x10.utils.string import is_hex_string

BTC_USD_MARKET = "BTC-USD"


@dataclass
class EnvConfig:
Expand Down Expand Up @@ -59,7 +61,7 @@ def init_env(require_private_api: bool = True):
)


def create_trading_client(endpoint_config: EndpointConfig = TESTNET_CONFIG):
def create_trading_client(config: Config = TESTNET_CONFIG):
env_config = init_env()

stark_account = StarkPerpetualAccount(
Expand All @@ -69,10 +71,10 @@ def create_trading_client(endpoint_config: EndpointConfig = TESTNET_CONFIG):
vault=env_config.vault_id,
)

return PerpetualTradingClient(endpoint_config, stark_account)
return PerpetualTradingClient(config, stark_account)


def create_blocking_client(endpoint_config: EndpointConfig = TESTNET_CONFIG):
def create_blocking_client(config: Config = TESTNET_CONFIG):
env_config = init_env()

stark_account = StarkPerpetualAccount(
Expand All @@ -82,11 +84,11 @@ def create_blocking_client(endpoint_config: EndpointConfig = TESTNET_CONFIG):
vault=env_config.vault_id,
)

return BlockingTradingClient(endpoint_config, stark_account)
return BlockingTradingClient(config, stark_account)


def create_stream_client(endpoint_config: EndpointConfig = TESTNET_CONFIG):
return PerpetualStreamClient(api_url=endpoint_config.stream_url)
def create_stream_client(config: Config = TESTNET_CONFIG):
return PerpetualStreamClient(api_url=config.endpoints.stream_url)


def get_adjust_price_by_pct(config: TradingConfigModel):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ async def test_create_buy_limit_order_settlement_data(
):
mocker.patch("x10.utils.nonce.generate_nonce", return_value=FROZEN_NONCE)

from x10.perpetual.configuration import MAINNET_CONFIG
from x10.config import MAINNET_CONFIG
from x10.perpetual.limit_order_object_settlement import create_order_settlement_data

trading_account = create_trading_account()
Expand All @@ -29,7 +29,7 @@ async def test_create_buy_limit_order_settlement_data(
quote_asset_model=collateral_asset,
base_asset_model=vault_asset,
starknet_account=trading_account,
starknet_domain=MAINNET_CONFIG.starknet_domain,
starknet_domain=MAINNET_CONFIG.signing.starknet_domain,
is_buy=True,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
from hamcrest import assert_that, equal_to
from pytest_mock import MockerFixture

from x10.config import TESTNET_CONFIG
from x10.models.order import (
OrderPriceType,
OrderSide,
OrderTriggerDirection,
OrderTriggerPriceType,
OrderType,
)
from x10.perpetual.configuration import TESTNET_CONFIG

FROZEN_NONCE = 1473459052

Expand All @@ -36,7 +36,7 @@ async def test_create_buy_order(mocker: MockerFixture, create_trading_account, c
amount_of_synthetic=Decimal("0.00100000"),
price=Decimal("43445.11680000"),
side=OrderSide.BUY,
starknet_domain=TESTNET_CONFIG.starknet_domain,
starknet_domain=TESTNET_CONFIG.signing.starknet_domain,
trigger=OrderConditionalTriggerParam(
trigger_price=Decimal("43400"),
trigger_price_type=OrderTriggerPriceType.INDEX,
Expand Down
Loading
Loading