Skip to content

api ¤

CCXTAPI ¤

CCXTAPI(
    exchange: int,
    key: str,
    secret: str,
    currency: str = "USDT",
    ccxt: CCXTAPIExchange | None = None,
    **kwargs
)

Bases: LiveAPI

CCXT API

Parameters:

  • exchange (int) –

    description

  • key (str) –

    description

  • secret (str) –

    description

  • ccxt (CCXTAPIExchange | None, default: None ) –

    description. Defaults to None.

Source code in lettrade/exchange/ccxt/api.py
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
def __init__(
    self,
    exchange: int,
    key: str,
    secret: str,
    currency: str = "USDT",
    ccxt: CCXTAPIExchange | None = None,
    **kwargs,
):
    """_summary_

    Args:
        exchange (int): _description_
        key (str): _description_
        secret (str): _description_
        ccxt (CCXTAPIExchange | None, optional): _description_. Defaults to None.
    """
    if ccxt is None:
        ccxt = CCXTAPIExchange(exchange=exchange, key=key, secret=secret, **kwargs)
    self._ccxt = ccxt
    self._currency = ccxt

account ¤

account() -> dict
Source code in lettrade/exchange/ccxt/api.py
264
265
266
267
268
269
270
271
272
273
274
def account(self) -> dict:
    """"""
    raw = self._ccxt.fetch_my_balance()
    currency = raw[self._currency]
    return Box(
        balance=currency["free"],
        equity=currency["total"],
        margin=1,
        leverage=1,
        raw=raw,
    )

execution_get ¤

execution_get(id: str, **kwargs) -> dict
Source code in lettrade/exchange/ccxt/api.py
323
324
def execution_get(self, id: str, **kwargs) -> dict:
    """"""

executions_get ¤

executions_get(
    position_id: str | None = None,
    search: str | None = None,
    **kwargs
) -> list[dict]
Source code in lettrade/exchange/ccxt/api.py
315
316
317
318
319
320
321
def executions_get(
    self,
    position_id: str | None = None,
    search: str | None = None,
    **kwargs,
) -> list[dict]:
    """"""

executions_total ¤

executions_total(
    since: datetime | None = None,
    to: datetime | None = None,
    **kwargs
) -> int
Source code in lettrade/exchange/ccxt/api.py
307
308
309
310
311
312
313
def executions_total(
    self,
    since: datetime | None = None,
    to: datetime | None = None,
    **kwargs,
) -> int:
    """"""

init ¤

init(**kwargs)
Source code in lettrade/exchange/live/api.py
21
22
def init(self, **kwargs):
    """"""

order_close ¤

order_close(order: CCXTOrder)
Source code in lettrade/exchange/ccxt/api.py
297
298
def order_close(self, order: "CCXTOrder"):
    """"""

order_open ¤

order_open(order: CCXTOrder, **kwargs)
Source code in lettrade/exchange/ccxt/api.py
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
def order_open(self, order: "CCXTOrder", **kwargs):
    """"""
    try:
        result = self._ccxt.create_my_order(
            symbol=order.data.symbol,
            type=order.type.lower(),
            side=order.side.lower(),
            amount=abs(order.size),
            price=order.place_price,
            **kwargs,
        )

        print("order_open", order, result)
        return result
    except ccxt.InvalidOrder as e:
        raise LetLiveOrderInvalidException(e.args[0]) from e

orders_get ¤

orders_get(**kwargs)
Source code in lettrade/exchange/ccxt/api.py
303
304
def orders_get(self, **kwargs):
    """"""

orders_history_get ¤

orders_history_get(
    id: str | None = None,
    since: datetime | None = None,
    to: datetime | None = None,
    **kwargs
) -> list[dict]
Source code in lettrade/exchange/live/api.py
100
101
102
103
104
105
106
107
def orders_history_get(
    self,
    id: str | None = None,
    since: datetime | None = None,
    to: datetime | None = None,
    **kwargs,
) -> list[dict]:
    """"""

orders_total ¤

orders_total()
Source code in lettrade/exchange/ccxt/api.py
300
301
def orders_total(self):
    """"""

position_close ¤

position_close(position: CCXTPosition, **kwargs) -> dict
Source code in lettrade/exchange/ccxt/api.py
347
348
def position_close(self, position: "CCXTPosition", **kwargs) -> dict:
    """"""

position_update ¤

position_update(
    position: CCXTPosition,
    sl: float | None = None,
    tp: float | None = None,
    **kwargs
) -> dict
Source code in lettrade/exchange/ccxt/api.py
338
339
340
341
342
343
344
345
def position_update(
    self,
    position: "CCXTPosition",
    sl: float | None = None,
    tp: float | None = None,
    **kwargs,
) -> dict:
    """"""

positions_get ¤

positions_get(
    id: str = None, symbol: str = None, **kwargs
) -> list[dict]
Source code in lettrade/exchange/ccxt/api.py
335
336
def positions_get(self, id: str = None, symbol: str = None, **kwargs) -> list[dict]:
    """"""

positions_total ¤

positions_total(
    since: datetime | None = None,
    to: datetime | None = None,
    **kwargs
) -> int
Source code in lettrade/exchange/ccxt/api.py
327
328
329
330
331
332
333
def positions_total(
    self,
    since: datetime | None = None,
    to: datetime | None = None,
    **kwargs,
) -> int:
    """"""

stop ¤

stop()
Source code in lettrade/exchange/ccxt/api.py
232
233
def stop(self):
    """"""

CCXTAPIExchange ¤

CCXTAPIExchange(
    exchange: str,
    key: str,
    secret: str,
    options: dict | None = None,
    type: Literal["spot", "margin", "future"] = "spot",
    sandbox: bool = True,
    verbose: bool = False,
    **kwargs
)

Single instance across multiprocessing. Help pickle-able result and send across multiprocessing

Source code in lettrade/exchange/ccxt/api.py
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
def __init__(
    self,
    exchange: str,
    key: str,
    secret: str,
    options: dict | None = None,
    type: Literal["spot", "margin", "future"] = "spot",
    sandbox: bool = True,
    verbose: bool = False,
    **kwargs,
) -> None:
    config = dict(
        apiKey=key,
        secret=secret,
        enableRateLimit=True,
        defaultType=type,
        options={
            "sandboxMode": sandbox,
            "warnOnFetchOpenOrdersWithoutSymbol": False,
            "tradesLimit": 1,
            "ordersLimit": 1,
            "OHLCVLimit": 1,
        },
    )
    config.update(kwargs)

    if options is not None:
        config["options"].update(options)

    self._exchange = getattr(ccxt, exchange)(config)

    # Must call sanbox function instead of option sandboxMode
    self._exchange.set_sandbox_mode(sandbox)
    self._exchange.verbose = verbose
    logger.info("Starting exchange class: %s", self._exchange)

stop ¤

stop()
Source code in lettrade/exchange/ccxt/api.py
88
89
def stop(self):
    """"""