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
9 changes: 8 additions & 1 deletion examples/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from lnmarkets_sdk.v3.models.futures_isolated import (
GetClosedTradesParams,
GetIsolatedFundingFeesParams,
UpdateTakeprofitParams,
)
from lnmarkets_sdk.v3.models.oracle import GetLastPriceParams

Expand All @@ -32,7 +33,7 @@ async def example_public_endpoints():

# Create client without authentication for public endpoints
# The httpx.AsyncClient is created once and reuses connections
async with LNMClient(APIClientConfig(network="testnet4")) as client:
async with LNMClient(APIClientConfig(network="mainnet")) as client:
# All these requests share the same connection pool
print("\n🔄 Making multiple requests with connection reuse...")

Expand Down Expand Up @@ -221,6 +222,12 @@ async def example_authenticated_endpoints():
except Exception as e:
print(f"Error: {e}")

print("\n --- Update take profit ---")
trade_id = "41ee6f7e-7cee-4c3b-b9f3-962d4b3b97c6"
params = UpdateTakeprofitParams(id=trade_id, value=100_000)
updated = await client.futures.isolated.update_takeprofit(params)
print(f"New take profit: {updated.takeprofit}")


async def main():
"""Run all examples."""
Expand Down
3 changes: 1 addition & 2 deletions src/lnmarkets_sdk/v3/_internal/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
import httpx
from pydantic import BaseModel, ConfigDict, Field, SkipValidation, ValidationError
from pydantic.alias_generators import to_camel
from pydantic.types import UUID4

type APINetwork = Literal["mainnet", "testnet4"]
type APIMethod = Literal["GET", "POST", "PUT"]
type UUID = UUID4
type UUID = str


class BaseConfig:
Expand Down
5 changes: 3 additions & 2 deletions src/lnmarkets_sdk/v3/http/client/futures/isolated.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ async def update_stoploss(self, params: UpdateStoplossParams):
from lnmarkets_sdk.v3.models.futures_isolated import UpdateStoplossParams

async with LNMClient(config) as client:
params = UpdateStoplossParams(id=trade_id, stoploss=90_000)
params = UpdateStoplossParams(id=trade_id, value=90000)
updated = await client.futures.isolated.update_stoploss(params)
print(f"New stop loss: {updated.stoploss}")
```
Expand All @@ -258,11 +258,12 @@ async def update_takeprofit(self, params: UpdateTakeprofitParams):
from lnmarkets_sdk.v3.models.futures_isolated import UpdateTakeprofitParams

async with LNMClient(config) as client:
params = UpdateTakeprofitParams(id=trade_id, takeprofit=110_000)
params = UpdateTakeprofitParams(id=trade_id, value=10000)
updated = await client.futures.isolated.update_takeprofit(params)
print(f"New take profit: {updated.takeprofit}")
```
"""
print(f"params: {params}")
return await self._client.request(
"PUT",
"/futures/isolated/trade/takeprofit",
Expand Down
4 changes: 2 additions & 2 deletions src/lnmarkets_sdk/v3/models/futures_isolated.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,12 @@ class CloseTradeParams(BaseModel, BaseConfig):

class UpdateStoplossParams(BaseModel, BaseConfig):
id: UUID = Field(..., description="Trade ID")
stoploss: float = Field(..., description="New stop loss price level")
value: float = Field(..., description="New stop loss price level")


class UpdateTakeprofitParams(BaseModel, BaseConfig):
id: UUID = Field(..., description="Trade ID")
takeprofit: float = Field(..., description="New take profit price level")
value: float = Field(..., description="New take profit price level")


class GetClosedTradesParams(FromToLimitParams): ...
Expand Down
5 changes: 2 additions & 3 deletions src/lnmarkets_sdk/v3/tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,6 @@ async def test_get_ticker(self):
assert isinstance(ticker.prices, list)
if len(ticker.prices) > 0:
price_bucket = ticker.prices[0]
print(price_bucket)
assert price_bucket.max_size > 0
assert price_bucket.min_size >= 0
if price_bucket.ask_price is not None:
Expand Down Expand Up @@ -621,7 +620,7 @@ async def test_update_stoploss(self):
running_trades = await client.futures.isolated.get_running_trades()
if len(running_trades) > 0:
trade = running_trades[0]
params = UpdateStoplossParams(id=trade.id, stoploss=50_000)
params = UpdateStoplossParams(id=trade.id, value=50_000)
updated = await client.futures.isolated.update_stoploss(params)
assert updated.id == trade.id
assert updated.running is True
Expand All @@ -640,7 +639,7 @@ async def test_update_takeprofit(self):
running_trades = await client.futures.isolated.get_running_trades()
if len(running_trades) > 0:
trade = running_trades[0]
params = UpdateTakeprofitParams(id=trade.id, takeprofit=150_000)
params = UpdateTakeprofitParams(id=trade.id, value=150_000)
updated = await client.futures.isolated.update_takeprofit(params)
assert updated.id == trade.id
assert updated.running is True
Expand Down
Loading