pyxtb
DEFAULT_XAPI_ADDRESS
DEFAULT_XAPI_ADDRESS = 'xapi.xtb.com'
Api
Api(login: int, password: str, app_name='pyxtb', address=DEFAULT_XAPI_ADDRESS, demo: bool = True)
Main XTB API connector
Examples:
>>> async with Api(1000000, "password") as api:
>>> trades = await api.get_trades(openedOnly=True)
>>> symbols = [await api.get_symbol(trade.symbol) for trade in trades]
>>> symbol_map = {symbol.symbol: symbol for symbol in symbols}
>>> print("Opened trades profit")
>>> for trade in trades:
>>> print(f"{symbol_map[trade.symbol].description}: {trade.profit}")
Source code in pyxtb/api.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
|
__aenter__
__aenter__()
Source code in pyxtb/api.py
107 108 109 |
|
__aexit__
__aexit__(exc_type, exc, tb)
Source code in pyxtb/api.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
|
get_all_symbols
get_all_symbols(**kwargs) -> list[SymbolRecord]
Description: Returns array of all symbols available for the user.
http://developers.xstore.pro/documentation/#getAllSymbols
Source code in pyxtb/api.py
253 254 255 256 257 258 259 260 261 |
|
get_calendar
get_calendar(**kwargs) -> list[CalendarRecord]
Description: Returns calendar with market events.
http://developers.xstore.pro/documentation/#getCalendar
Source code in pyxtb/api.py
263 264 265 266 267 268 269 270 271 |
|
get_chart_last_request
get_chart_last_request(info: ChartLastInfoRecord, **kwargs) -> ChartResponseRecord
Description: Please note that this function can be usually replaced by its streaming equivalent getCandles which is the preferred way of retrieving current candle data. Returns chart info, from start date to the current time. If the chosen period of CHART_LAST_INFO_RECORD is greater than 1 minute, the last candle returned by the API can change until the end of the period (the candle is being automatically updated every minute).
Limitations: there are limitations in charts data availability. Detailed ranges for charts data, what can be accessed with specific period, are as follows:
PERIOD_M1 --- <0-1) month, i.e. one month time PERIOD_M30 --- <1-7) month, six months time PERIOD_H4 --- <7-13) month, six months time PERIOD_D1 --- 13 month, and earlier on
Note, that specific PERIOD_ is the lowest (i.e. the most detailed) period, accessible in listed range. For instance, in months range <1-7) you can access periods: PERIOD_M30, PERIOD_H1, PERIOD_H4, PERIOD_D1, PERIOD_W1, PERIOD_MN1. Specific data ranges availability is guaranteed, however those ranges may be wider, e.g.: PERIOD_M1 may be accessible for 1.5 months back from now, where 1.0 months is guaranteed.
Example scenario:
- request charts of 5 minutes period, for 3 months time span, back from now;
- response: you are guaranteed to get 1 month of 5 minutes charts; because, 5 minutes period charts are not accessible 2 months and 3 months back from now.
http://developers.xstore.pro/documentation/#getChartLastRequest
Source code in pyxtb/api.py
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 |
|
get_chart_range_request
get_chart_range_request(info: ChartRangeInfoRecord, **kwargs) -> ChartResponseRecord
Description: Please note that this function can be usually replaced by its streaming equivalent getCandles which is the preferred way of retrieving current candle data. Returns chart info with data between given start and end dates.
Limitations: there are limitations in charts data availability. Detailed ranges for charts data, what can be accessed with specific period, are as follows:
PERIOD_M1 --- <0-1) month, i.e. one month time
PERIOD_M30 --- <1-7) month, six months time
PERIOD_H4 --- <7-13) month, six months time
PERIOD_D1 --- 13 month, and earlier on
Note, that specific PERIOD_ is the lowest (i.e. the most detailed) period, accessible in listed range. For instance, in months range <1-7) you can access periods: PERIOD_M30, PERIOD_H1, PERIOD_H4, PERIOD_D1, PERIOD_W1, PERIOD_MN1. Specific data ranges availability is guaranteed, however those ranges may be wider, e.g.: PERIOD_M1 may be accessible for 1.5 months back from now, where 1.0 months is guaranteed.
http://developers.xstore.pro/documentation/#getChartRangeRequest
Source code in pyxtb/api.py
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 |
|
get_commission_def
get_commission_def(symbol: str, volume: float, **kwargs) -> CommissionDefResponseRecord
Description: Returns calculation of commission and rate of exchange. The value is calculated as expected value, and therefore might not be perfectly accurate.
http://developers.xstore.pro/documentation/#getCommissionDef
Source code in pyxtb/api.py
326 327 328 329 330 331 332 333 334 335 336 337 338 339 |
|
get_current_user_data
get_current_user_data(**kwargs) -> CurrentUserDataRecord
Description: Returns calculation of commission and rate of exchange. The value is calculated as expected value, and therefore might not be perfectly accurate.
http://developers.xstore.pro/documentation/#getCurrentUserData
Source code in pyxtb/api.py
341 342 343 344 345 346 347 348 349 |
|
get_ibs_history
get_ibs_history(end: Time, start: Time, **kwargs) -> list[IBRecord]
Description: Returns IBs data from the given time range.
http://developers.xstore.pro/documentation/#getIbsHistory
Source code in pyxtb/api.py
351 352 353 354 355 356 357 358 359 |
|
get_margin_level
get_margin_level(**kwargs) -> MarginLevelRecord
Description: Please note that this function can be usually replaced by its streaming equivalent getBalance which is the preferred way of retrieving account indicators. Returns various account indicators.
http://developers.xstore.pro/documentation/#getMarginLevel
Source code in pyxtb/api.py
361 362 363 364 365 366 367 368 369 |
|
get_margin_trade
get_margin_trade(symbol: str, volume: float, **kwargs) -> MarginTradeRecord
Description: Returns expected margin for given instrument and volume. The value is calculated as expected margin value, and therefore might not be perfectly accurate.
http://developers.xstore.pro/documentation/#getMarginTrade
Source code in pyxtb/api.py
371 372 373 374 375 376 377 378 379 380 381 382 383 384 |
|
get_news
get_news(start: Time, end: Time = 0, **kwargs) -> list[NewsTopicRecord]
Description: Please note that this function can be usually replaced by its streaming equivalent getNews which is the preferred way of retrieving news data. Returns news from trading server which were sent within specified period of time.
http://developers.xstore.pro/documentation/#getNews
Source code in pyxtb/api.py
386 387 388 389 390 391 392 393 394 395 396 |
|
get_profit_calculation
get_profit_calculation(closePrice: float, cmd: Command, openPrice: float, symbol: str, volume: float, **kwargs) -> ProfitCalculationRecord
Description: Calculates estimated profit for given deal data Should be used for calculator-like apps only. Profit for opened transactions should be taken from server, due to higher precision of server calculation.
http://developers.xstore.pro/documentation/#getProfitCalculation
Source code in pyxtb/api.py
398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 |
|
get_server_time
get_server_time(**kwargs) -> ServerTimeRecord
Description: Returns current time on trading server.
http://developers.xstore.pro/documentation/#getServerTime
Source code in pyxtb/api.py
425 426 427 428 429 430 431 432 433 |
|
get_step_rules
get_step_rules(**kwargs) -> list[StepRuleRecord]
Description: Returns a list of step rules for DMAs.
http://developers.xstore.pro/documentation/#getStepRules
Source code in pyxtb/api.py
435 436 437 438 439 440 441 442 443 |
|
get_symbol
get_symbol(symbol: str, **kwargs) -> SymbolRecord
Description: Returns information about symbol available for the user.
http://developers.xstore.pro/documentation/#getSymbol
Source code in pyxtb/api.py
445 446 447 448 449 450 451 452 453 |
|
get_tick_prices
get_tick_prices(level: int, symbols: list[str], timestamp: Time, **kwargs) -> TickPricesResponseRecord
Description: Please note that this function can be usually replaced by its streaming equivalent getTickPrices which is the preferred way of retrieving ticks data. Returns array of current quotations for given symbols, only quotations that changed from given timestamp are returned. New timestamp obtained from output will be used as an argument of the next call of this command.
http://developers.xstore.pro/documentation/#getTickPrices
Source code in pyxtb/api.py
455 456 457 458 459 460 461 462 463 464 465 466 467 468 |
|
get_trade_records
get_trade_records(orders: list[int], **kwargs) -> list[TradeRecord]
Description: Returns array of trades listed in orders argument.
http://developers.xstore.pro/documentation/#getTradeRecords
Source code in pyxtb/api.py
470 471 472 473 474 475 476 477 478 479 480 481 |
|
get_trades
get_trades(openedOnly: bool, **kwargs) -> list[TradeRecord]
Description: Please note that this function can be usually replaced by its streaming equivalent getTrades which is the preferred way of retrieving trades data. Returns array of user's trades.
http://developers.xstore.pro/documentation/#getTrades
Source code in pyxtb/api.py
483 484 485 486 487 488 489 490 491 492 493 494 |
|
get_trades_history
get_trades_history(start: int, end: int = 0, **kwargs) -> list[TradeRecord]
Description: Please note that this function can be usually replaced by its streaming equivalent getTrades which is the preferred way of retrieving trades data. Returns array of user's trades which were closed within specified period of time.
http://developers.xstore.pro/documentation/#getTradesHistory
Source code in pyxtb/api.py
496 497 498 499 500 501 502 503 504 505 506 507 508 509 |
|
get_trading_hours
get_trading_hours(symbols: list[str], **kwargs) -> list[TradingHoursRecord]
Description: Returns quotes and trading times.
http://developers.xstore.pro/documentation/#getTradingHours
Source code in pyxtb/api.py
511 512 513 514 515 516 517 518 519 520 521 522 523 524 |
|
get_version
get_version(**kwargs) -> VersionRecord
Description: Returns the current API version.
http://developers.xstore.pro/documentation/#getVersion
Source code in pyxtb/api.py
526 527 528 529 530 531 532 533 534 535 536 |
|
login
login()
http://developers.xstore.pro/documentation/#login
Source code in pyxtb/api.py
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
|
logout
logout() -> RESPONSE[StreamingTradeStatusRecord]
http://developers.xstore.pro/documentation/#logout
Source code in pyxtb/api.py
234 235 236 237 |
|
ping
ping(**kwargs) -> None
Description: Regularly calling this function is enough to refresh the internal state of all the components in the system. It is recommended that any application that does not execute other commands, should call this command at least once every 10 minutes. Please note that the streaming counterpart of this function is combination of ping and getKeepAlive .
http://developers.xstore.pro/documentation/#ping
Source code in pyxtb/api.py
538 539 540 541 542 543 544 545 546 547 548 |
|
streaming_ping
streaming_ping()
Description: Description: Regularly calling this function is enough to refresh the internal state of all the components in the system. Streaming connection, when any command is not sent by client in the session, generates only one way network traffic. It is recommended that any application that does not execute other commands, should call this command at least once every 10 minutes. Note: There is no response in return to this command.
http://developers.xstore.pro/documentation/#streamping
Source code in pyxtb/api.py
722 723 724 725 726 727 728 729 730 731 |
|
subscribe_get_balance
subscribe_get_balance(eventListener: Callable[[StreamingBalanceRecord], None], **kwargs)
Description: Allows to get actual account indicators values in real-time, as soon as they are available in the system.
http://developers.xstore.pro/documentation/#streamgetBalance
Source code in pyxtb/api.py
614 615 616 617 618 619 620 621 622 623 624 |
|
subscribe_get_candles
subscribe_get_candles(eventListener: Callable[[StreamingCandleRecord], None], symbol: str, **kwargs)
Description: Subscribes for and unsubscribes from API chart candles. The interval of every candle is 1 minute. A new candle arrives every minute.
http://developers.xstore.pro/documentation/#streamgetCandles
Source code in pyxtb/api.py
626 627 628 629 630 631 632 633 634 635 636 637 638 639 |
|
subscribe_get_keep_alive
subscribe_get_keep_alive(eventListener: Callable[[StreamingKeepAliveRecord], None], **kwargs)
Description: Subscribes for and unsubscribes from 'keep alive' messages. A new 'keep alive' message is sent by the API every 3 seconds.
http://developers.xstore.pro/documentation/#streamgetKeepAlive
Source code in pyxtb/api.py
641 642 643 644 645 646 647 648 649 650 651 652 653 |
|
subscribe_get_news
subscribe_get_news(eventListener: Callable[[StreamingNewsRecord], None], **kwargs)
Description: Subscribes for and unsubscribes from news.
http://developers.xstore.pro/documentation/#streamgetNews
Source code in pyxtb/api.py
655 656 657 658 659 660 661 662 663 |
|
subscribe_get_profits
subscribe_get_profits(eventListener: Callable[[StreamingProfitRecord], None], **kwargs)
Description: Subscribes for and unsubscribes from profits.
http://developers.xstore.pro/documentation/#streamgetProfits
Source code in pyxtb/api.py
665 666 667 668 669 670 671 672 673 674 675 |
|
subscribe_tick_prices
subscribe_tick_prices(eventListener: Callable[[StreamingTickRecord], None], symbol: str, minArrivalTime: int = 0, maxLevel: int | None = None, **kwargs)
Description: Establishes subscription for quotations and allows to obtain the relevant information in real-time, as soon as it is available in the system. The getTickPrices command can be invoked many times for the same symbol, but only one subscription for a given symbol will be created. Please beware that when multiple records are available, the order in which they are received is not guaranteed.
http://developers.xstore.pro/documentation/#streamgetTickPrices
Source code in pyxtb/api.py
677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 |
|
subscribe_trade_status
subscribe_trade_status(eventListener: Callable[[StreamingTradeStatusRecord], None], **kwargs)
Description: Allows to get status for sent trade requests in real-time, as soon as it is available in the system. Please beware that when multiple records are available, the order in which they are received is not guaranteed.
http://developers.xstore.pro/documentation/#streamgetTradeStatus
Source code in pyxtb/api.py
710 711 712 713 714 715 716 717 718 719 720 |
|
subscribe_trades
subscribe_trades(eventListener: Callable[[StreamingTradeRecord], None], **kwargs)
Description: Establishes subscription for user trade status data and allows to obtain the relevant information in real-time, as soon as it is available in the system. Please beware that when multiple records are available, the order in which they are received is not guaranteed.
http://developers.xstore.pro/documentation/#streamgetTrades
Source code in pyxtb/api.py
700 701 702 703 704 705 706 707 708 |
|
trade_transaction
trade_transaction(tradeTransInfo: TradeTransInfoRecord, **kwargs) -> TradeTransResponseRecord
Description: Starts trade transaction. tradeTransaction sends main transaction information to the server.
http://developers.xstore.pro/documentation/#tradeTransaction
Source code in pyxtb/api.py
550 551 552 553 554 555 556 557 558 559 560 561 562 563 |
|
trade_transaction_status
trade_transaction_status(order: int, **kwargs) -> TradeTransactionStatusResponseRecord
Description: Please note that this function can be usually replaced by its streaming equivalent getTradeStatus which is the preferred way of retrieving transaction status data. Returns current transaction status. At any time of transaction processing client might check the status of transaction on server side. In order to do that client must provide unique order taken from tradeTransaction invocation.
http://developers.xstore.pro/documentation/#tradeTransactionStatus
Source code in pyxtb/api.py
565 566 567 568 569 570 571 572 573 574 575 576 577 578 |
|