├── .gitignore ├── README.md ├── docs ├── broker.rst ├── conf.py ├── index.rst ├── mix.rst ├── overview.rst ├── spot.rst └── websockets.rst ├── examples ├── cancel_orders.py ├── create_orders.py ├── example_rest_api.py └── example_websocket_api.py ├── pybitget ├── __init__.py ├── client.py ├── enums.py ├── exceptions.py ├── stream.py └── utils.py └── release_notes.md /.gitignore: -------------------------------------------------------------------------------- 1 | setup.py 2 | setup.cfg 3 | Pipfile 4 | Makefile 5 | # Created by https://www.toptal.com/developers/gitignore/api/python,virtualenv,visualstudio,visualstudiocode,linux 6 | # Edit at https://www.toptal.com/developers/gitignore?templates=python,virtualenv,visualstudio,visualstudiocode,linux 7 | 8 | ### Linux ### 9 | *~ 10 | 11 | # temporary files which can be created if a process still has a handle open of a deleted file 12 | .fuse_hidden* 13 | 14 | # KDE directory preferences 15 | .directory 16 | 17 | # Linux trash folder which might appear on any partition or disk 18 | .Trash-* 19 | 20 | # .nfs files are created when an open file is removed but is still being accessed 21 | .nfs* 22 | 23 | ### Python ### 24 | # Byte-compiled / optimized / DLL files 25 | __pycache__/ 26 | *.py[cod] 27 | *$py.class 28 | 29 | # C extensions 30 | *.so 31 | 32 | # Distribution / packaging 33 | .Python 34 | build/ 35 | develop-eggs/ 36 | dist/ 37 | downloads/ 38 | eggs/ 39 | .eggs/ 40 | lib/ 41 | lib64/ 42 | parts/ 43 | sdist/ 44 | var/ 45 | wheels/ 46 | share/python-wheels/ 47 | *.egg-info/ 48 | .installed.cfg 49 | *.egg 50 | MANIFEST 51 | zzz* 52 | # PyInstaller 53 | # Usually these files are written by a python script from a template 54 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 55 | *.manifest 56 | *.spec 57 | 58 | # Installer logs 59 | pip-log.txt 60 | pip-delete-this-directory.txt 61 | 62 | # Unit test / coverage reports 63 | htmlcov/ 64 | .tox/ 65 | .nox/ 66 | .coverage 67 | .coverage.* 68 | .cache 69 | nosetests.xml 70 | coverage.xml 71 | *.cover 72 | *.py,cover 73 | .hypothesis/ 74 | .pytest_cache/ 75 | cover/ 76 | 77 | # Translations 78 | *.mo 79 | *.pot 80 | 81 | # Django stuff: 82 | *.log 83 | local_settings.py 84 | db.sqlite3 85 | db.sqlite3-journal 86 | 87 | # Flask stuff: 88 | instance/ 89 | .webassets-cache 90 | 91 | # Scrapy stuff: 92 | .scrapy 93 | 94 | # Sphinx documentation 95 | docs/_build/ 96 | 97 | # PyBuilder 98 | .pybuilder/ 99 | target/ 100 | 101 | # Jupyter Notebook 102 | .ipynb_checkpoints 103 | 104 | # IPython 105 | profile_default/ 106 | ipython_config.py 107 | 108 | # pyenv 109 | # For a library or package, you might want to ignore these files since the code is 110 | # intended to run in multiple environments; otherwise, check them in: 111 | # .python-version 112 | 113 | # pipenv 114 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 115 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 116 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 117 | # install all needed dependencies. 118 | #Pipfile.lock 119 | 120 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 121 | __pypackages__/ 122 | 123 | # Celery stuff 124 | celerybeat-schedule 125 | celerybeat.pid 126 | 127 | # SageMath parsed files 128 | *.sage.py 129 | 130 | # Environments 131 | .env 132 | .venv 133 | env/ 134 | venv/ 135 | ENV/ 136 | env.bak/ 137 | venv.bak/ 138 | 139 | # Spyder project settings 140 | .spyderproject 141 | .spyproject 142 | 143 | # Rope project settings 144 | .ropeproject 145 | 146 | # mkdocs documentation 147 | /site 148 | 149 | # mypy 150 | .mypy_cache/ 151 | .dmypy.json 152 | dmypy.json 153 | 154 | # Pyre type checker 155 | .pyre/ 156 | 157 | # pytype static type analyzer 158 | .pytype/ 159 | 160 | # Cython debug symbols 161 | cython_debug/ 162 | 163 | ### VirtualEnv ### 164 | # Virtualenv 165 | # http://iamzed.com/2009/05/07/a-primer-on-virtualenv/ 166 | [Bb]in 167 | [Ii]nclude 168 | [Ll]ib 169 | [Ll]ib64 170 | [Ll]ocal 171 | [Ss]cripts 172 | pyvenv.cfg 173 | pip-selfcheck.json 174 | 175 | ### VisualStudioCode ### 176 | .vscode/* 177 | !.vscode/settings.json 178 | !.vscode/tasks.json 179 | !.vscode/launch.json 180 | !.vscode/extensions.json 181 | *.code-workspace 182 | 183 | # Local History for Visual Studio Code 184 | .history/ 185 | 186 | ### VisualStudioCode Patch ### 187 | # Ignore all local history of files 188 | .history 189 | .ionide 190 | 191 | ### VisualStudio ### 192 | ## Ignore Visual Studio temporary files, build results, and 193 | ## files generated by popular Visual Studio add-ons. 194 | ## 195 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 196 | 197 | # User-specific files 198 | *.rsuser 199 | *.suo 200 | *.user 201 | *.userosscache 202 | *.sln.docstates 203 | 204 | # User-specific files (MonoDevelop/Xamarin Studio) 205 | *.userprefs 206 | 207 | # Mono auto generated files 208 | mono_crash.* 209 | 210 | # Build results 211 | [Dd]ebug/ 212 | [Dd]ebugPublic/ 213 | [Rr]elease/ 214 | [Rr]eleases/ 215 | x64/ 216 | x86/ 217 | [Ww][Ii][Nn]32/ 218 | [Aa][Rr][Mm]/ 219 | [Aa][Rr][Mm]64/ 220 | bld/ 221 | [Bb]in/ 222 | [Oo]bj/ 223 | [Ll]og/ 224 | [Ll]ogs/ 225 | 226 | # Visual Studio 2015/2017 cache/options directory 227 | .vs/ 228 | # Uncomment if you have tasks that create the project's static files in wwwroot 229 | #wwwroot/ 230 | 231 | # Visual Studio 2017 auto generated files 232 | Generated\ Files/ 233 | 234 | # MSTest test Results 235 | [Tt]est[Rr]esult*/ 236 | [Bb]uild[Ll]og.* 237 | 238 | # NUnit 239 | *.VisualState.xml 240 | TestResult.xml 241 | nunit-*.xml 242 | 243 | # Build Results of an ATL Project 244 | [Dd]ebugPS/ 245 | [Rr]eleasePS/ 246 | dlldata.c 247 | 248 | # Benchmark Results 249 | BenchmarkDotNet.Artifacts/ 250 | 251 | # .NET Core 252 | project.lock.json 253 | project.fragment.lock.json 254 | artifacts/ 255 | 256 | # ASP.NET Scaffolding 257 | ScaffoldingReadMe.txt 258 | 259 | # StyleCop 260 | StyleCopReport.xml 261 | 262 | # Files built by Visual Studio 263 | *_i.c 264 | *_p.c 265 | *_h.h 266 | *.ilk 267 | *.meta 268 | *.obj 269 | *.iobj 270 | *.pch 271 | *.pdb 272 | *.ipdb 273 | *.pgc 274 | *.pgd 275 | *.rsp 276 | *.sbr 277 | *.tlb 278 | *.tli 279 | *.tlh 280 | *.tmp 281 | *.tmp_proj 282 | *_wpftmp.csproj 283 | *.tlog 284 | *.vspscc 285 | *.vssscc 286 | .builds 287 | *.pidb 288 | *.svclog 289 | *.scc 290 | 291 | # Chutzpah Test files 292 | _Chutzpah* 293 | 294 | # Visual C++ cache files 295 | ipch/ 296 | *.aps 297 | *.ncb 298 | *.opendb 299 | *.opensdf 300 | *.sdf 301 | *.cachefile 302 | *.VC.db 303 | *.VC.VC.opendb 304 | 305 | # Visual Studio profiler 306 | *.psess 307 | *.vsp 308 | *.vspx 309 | *.sap 310 | 311 | # Visual Studio Trace Files 312 | *.e2e 313 | 314 | # TFS 2012 Local Workspace 315 | $tf/ 316 | 317 | # Guidance Automation Toolkit 318 | *.gpState 319 | 320 | # ReSharper is a .NET coding add-in 321 | _ReSharper*/ 322 | *.[Rr]e[Ss]harper 323 | *.DotSettings.user 324 | 325 | # TeamCity is a build add-in 326 | _TeamCity* 327 | 328 | # DotCover is a Code Coverage Tool 329 | *.dotCover 330 | 331 | # AxoCover is a Code Coverage Tool 332 | .axoCover/* 333 | !.axoCover/settings.json 334 | 335 | # Coverlet is a free, cross platform Code Coverage Tool 336 | coverage*.json 337 | coverage*.xml 338 | coverage*.info 339 | 340 | # Visual Studio code coverage results 341 | *.coverage 342 | *.coveragexml 343 | 344 | # NCrunch 345 | _NCrunch_* 346 | .*crunch*.local.xml 347 | nCrunchTemp_* 348 | 349 | # MightyMoose 350 | *.mm.* 351 | AutoTest.Net/ 352 | 353 | # Web workbench (sass) 354 | .sass-cache/ 355 | 356 | # Installshield output folder 357 | [Ee]xpress/ 358 | 359 | # DocProject is a documentation generator add-in 360 | DocProject/buildhelp/ 361 | DocProject/Help/*.HxT 362 | DocProject/Help/*.HxC 363 | DocProject/Help/*.hhc 364 | DocProject/Help/*.hhk 365 | DocProject/Help/*.hhp 366 | DocProject/Help/Html2 367 | DocProject/Help/html 368 | 369 | # Click-Once directory 370 | publish/ 371 | 372 | # Publish Web Output 373 | *.[Pp]ublish.xml 374 | *.azurePubxml 375 | # Note: Comment the next line if you want to checkin your web deploy settings, 376 | # but database connection strings (with potential passwords) will be unencrypted 377 | *.pubxml 378 | *.publishproj 379 | 380 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 381 | # checkin your Azure Web App publish settings, but sensitive information contained 382 | # in these scripts will be unencrypted 383 | PublishScripts/ 384 | 385 | # NuGet Packages 386 | *.nupkg 387 | # NuGet Symbol Packages 388 | *.snupkg 389 | # The packages folder can be ignored because of Package Restore 390 | **/[Pp]ackages/* 391 | # except build/, which is used as an MSBuild target. 392 | !**/[Pp]ackages/build/ 393 | # Uncomment if necessary however generally it will be regenerated when needed 394 | #!**/[Pp]ackages/repositories.config 395 | # NuGet v3's project.json files produces more ignorable files 396 | *.nuget.props 397 | *.nuget.targets 398 | 399 | # Nuget personal access tokens and Credentials 400 | nuget.config 401 | 402 | # Microsoft Azure Build Output 403 | csx/ 404 | *.build.csdef 405 | 406 | # Microsoft Azure Emulator 407 | ecf/ 408 | rcf/ 409 | 410 | # Windows Store app package directories and files 411 | AppPackages/ 412 | BundleArtifacts/ 413 | Package.StoreAssociation.xml 414 | _pkginfo.txt 415 | *.appx 416 | *.appxbundle 417 | *.appxupload 418 | 419 | # Visual Studio cache files 420 | # files ending in .cache can be ignored 421 | *.[Cc]ache 422 | # but keep track of directories ending in .cache 423 | !?*.[Cc]ache/ 424 | 425 | # Others 426 | ClientBin/ 427 | ~$* 428 | *.dbmdl 429 | *.dbproj.schemaview 430 | *.jfm 431 | *.pfx 432 | *.publishsettings 433 | orleans.codegen.cs 434 | 435 | # Including strong name files can present a security risk 436 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 437 | #*.snk 438 | 439 | # Since there are multiple workflows, uncomment next line to ignore bower_components 440 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 441 | #bower_components/ 442 | 443 | # RIA/Silverlight projects 444 | Generated_Code/ 445 | 446 | # Backup & report files from converting an old project file 447 | # to a newer Visual Studio version. Backup files are not needed, 448 | # because we have git ;-) 449 | _UpgradeReport_Files/ 450 | Backup*/ 451 | UpgradeLog*.XML 452 | UpgradeLog*.htm 453 | ServiceFabricBackup/ 454 | *.rptproj.bak 455 | 456 | # SQL Server files 457 | *.mdf 458 | *.ldf 459 | *.ndf 460 | 461 | # Business Intelligence projects 462 | *.rdl.data 463 | *.bim.layout 464 | *.bim_*.settings 465 | *.rptproj.rsuser 466 | *- [Bb]ackup.rdl 467 | *- [Bb]ackup ([0-9]).rdl 468 | *- [Bb]ackup ([0-9][0-9]).rdl 469 | 470 | # Microsoft Fakes 471 | FakesAssemblies/ 472 | 473 | # GhostDoc plugin setting file 474 | *.GhostDoc.xml 475 | 476 | # Node.js Tools for Visual Studio 477 | .ntvs_analysis.dat 478 | node_modules/ 479 | 480 | # Visual Studio 6 build log 481 | *.plg 482 | 483 | # Visual Studio 6 workspace options file 484 | *.opt 485 | 486 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 487 | *.vbw 488 | 489 | # Visual Studio LightSwitch build output 490 | **/*.HTMLClient/GeneratedArtifacts 491 | **/*.DesktopClient/GeneratedArtifacts 492 | **/*.DesktopClient/ModelManifest.xml 493 | **/*.Server/GeneratedArtifacts 494 | **/*.Server/ModelManifest.xml 495 | _Pvt_Extensions 496 | 497 | # Paket dependency manager 498 | .paket/paket.exe 499 | paket-files/ 500 | 501 | # FAKE - F# Make 502 | .fake/ 503 | 504 | # CodeRush personal settings 505 | .cr/personal 506 | 507 | # Python Tools for Visual Studio (PTVS) 508 | *.pyc 509 | 510 | # Cake - Uncomment if you are using it 511 | # tools/** 512 | # !tools/packages.config 513 | 514 | # Tabs Studio 515 | *.tss 516 | 517 | # Telerik's JustMock configuration file 518 | *.jmconfig 519 | 520 | # BizTalk build output 521 | *.btp.cs 522 | *.btm.cs 523 | *.odx.cs 524 | *.xsd.cs 525 | 526 | # OpenCover UI analysis results 527 | OpenCover/ 528 | 529 | # Azure Stream Analytics local run output 530 | ASALocalRun/ 531 | 532 | # MSBuild Binary and Structured Log 533 | *.binlog 534 | 535 | # NVidia Nsight GPU debugger configuration file 536 | *.nvuser 537 | 538 | # MFractors (Xamarin productivity tool) working folder 539 | .mfractor/ 540 | 541 | # Local History for Visual Studio 542 | .localhistory/ 543 | 544 | # BeatPulse healthcheck temp database 545 | healthchecksdb 546 | 547 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 548 | MigrationBackup/ 549 | 550 | # Ionide (cross platform F# VS Code tools) working folder 551 | .ionide/ 552 | 553 | # Fody - auto-generated XML schema 554 | FodyWeavers.xsd 555 | 556 | # VS Code files for those working on multiple tools 557 | 558 | # Local History for Visual Studio Code 559 | 560 | # Windows Installer files from build outputs 561 | *.cab 562 | *.msi 563 | *.msix 564 | *.msm 565 | *.msp 566 | 567 | # JetBrains Rider 568 | .idea/ 569 | *.sln.iml 570 | 571 | ### VisualStudio Patch ### 572 | # Additional files built by Visual Studio 573 | 574 | # End of https://www.toptal.com/developers/gitignore/api/python,virtualenv,visualstudio,visualstudiocode,linux 575 | /.pypirc 576 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Python bitget API Library 2 | 3 | 4 | [![License](https://img.shields.io/badge/license-MIT-green)](https://github.com/cuongitl/python-bitget/-/blob/main/LICENSE) 5 | [![python-bitget Version](https://img.shields.io/pypi/v/python-bitget?logo=pypi)](https://pypi.org/project/python-bitget/) 6 | [![python-bitget Python Versions](https://img.shields.io/pypi/pyversions/python-bitget?logo=pypi)](https://pypi.org/project/python-bitget/) 7 | [![python-bitget Downloads Per Day](https://img.shields.io/pypi/dd/python-bitget?logo=pypi)](https://pypi.org/project/python-bitget/) 8 | [![python-bitget Downloads Per Week](https://img.shields.io/pypi/dw/python-bitget?logo=pypi)](https://pypi.org/project/python-bitget/) 9 | [![python-bitget Downloads Per Month](https://img.shields.io/pypi/dm/python-bitget?logo=pypi)](https://pypi.org/project/python-bitget/) 10 | [![Downloads](https://static.pepy.tech/badge/python-bitget)](https://pypi.org/project/python-bitget/) 11 | 12 | [bitget](https://www.bitget.com/en/referral/register?from=referral&clacCode=6EKP94LE) is a cryptocurrency derivatives exchange. 13 | 14 | This is a wrapper around the Bitget API as described on Bitget, including all features the API provides using clear and readable objects, both for the REST as the websocket API. 15 | 16 | 17 | I am in no way affiliated with Bitget, use at your own risk. 18 | 19 | **If you think something is broken, something is missing or have any questions, please open an [Issue](https://github.com/cuongitl/python-bitget/issues)** 20 | 21 | # Get Started and Documentation 22 | If you're new to Bitget, use the following link to [save 10% on all of your trade fees, and can get rewards up to $5005.](https://www.bitget.com/en/referral/register?from=referral&clacCode=6EKP94LE) 23 | * [Register an account with Bitget.](https://partner.bitget.com/bg/e55g05831674816745836) 24 | * [Generate an API Key and assign relevant permissions.](https://www.bitget.com/en/support/articles/360038968251-API%20Creation%20Guide) 25 | * [Bitget API docs](https://bitgetlimited.github.io/apidoc/en/mix/#welcome) 26 | * [Example Bitget rest API](https://github.com/cuongitl/python-bitget/blob/master/examples/example_rest_api.py) 27 | * [Example Bitget websocket API](https://github.com/cuongitl/python-bitget/blob/master/examples/example_websocket_api.py) 28 | 29 | # Install 30 | pip install python-bitget 31 | # Usage 32 | 33 | > Change your API KEY and your SECRET KEY. 34 | ### Restful Api Sample Code 35 | 36 | ```python 37 | from pybitget import Client 38 | 39 | api_key = "your-api-key" 40 | api_secret = "your-secret-key" 41 | api_passphrase = "your-api-passphrase" 42 | 43 | client = Client(api_key, api_secret, passphrase=api_passphrase) 44 | result = client.mix_get_accounts(productType='UMCBL') 45 | print(result) 46 | 47 | ``` 48 | ### Websocket Sample Code 49 | 50 | ```python 51 | from pybitget.stream import BitgetWsClient, SubscribeReq, handel_error 52 | 53 | from pybitget.enums import * 54 | from pybitget import logger 55 | 56 | api_key = "your-api-key" 57 | api_secret = "your-secret-key" 58 | api_passphrase = "your-api-passphrase" 59 | 60 | def on_message(message): 61 | logger.info(message) 62 | 63 | 64 | # Auth subscribe 65 | client = BitgetWsClient(api_key=api_key, 66 | api_secret=api_secret, 67 | passphrase=api_passphrase, 68 | verbose=True) \ 69 | .error_listener(handel_error) \ 70 | .build() 71 | 72 | # multi subscribe - Public Channels 73 | channels = [SubscribeReq("mc", "ticker", "BTCUSD"), SubscribeReq("SP", "candle1W", "BTCUSDT")] 74 | client.subscribe(channels, on_message) 75 | 76 | # single subscribe - # multi subscribe Public Channels 77 | channels = [SubscribeReq("mc", "ticker", "BTCUSD")] 78 | client.subscribe(channels, on_message) 79 | 80 | # single subscribe - Order Channel - Private Channels 81 | channels = [SubscribeReq(WS_CHANNEL_INSTTYPE, WS_PRIVATE_ORDERS_CHANNEL, WS_CHANNEL_INSTID)] 82 | client.subscribe(channels, on_message) 83 | ``` 84 | 85 | ## Donate / Sponsor 86 | I develop and maintain this package on my own for free in my spare time. 87 | Donations are greatly appreciated. If you prefer to donate any other currency please contact me. 88 | 89 | * **Buy me a coffee:** https://buymeacoffee.com/cuongitl 90 | 91 | * **BTC**: `19rvFC79eVoCMHxJ44hB3GLhiD2HHsMJoZ` 92 | 93 | * **BTC**: `0xab4686635a02dff0babedddfee813d325f56cfb8` (BEP20) 94 | 95 | * **USDT**: `0xab4686635a02dff0babedddfee813d325f56cfb8` (BEP20) 96 | 97 | * **USDT**: `TCdyZs2mRhwYpCB5dZqiXEUoYRfiVJuq1H` (TRC20) 98 | 99 | * **BGB**: `0x3ee4ca7cc911ad4e423dec2ae8f2846e9a6a0a77` (ERC-20) 100 | 101 | ## Communities - Telegram 102 | * Bitget: [Bitget OPENAPI](https://t.me/bitgetOpenapi) 103 | * Author: [Cuongitl](https://t.me/Cuongitl) 104 | 105 | ## Release Notes 106 | The release notes can be found 107 | [here.](https://github.com/cuongitl/python-bitget/blob/master/release_notes.md) 108 | 109 | ## Contribution 110 | * Fork this repository. 111 | * Make pull requests with proper commit message. -------------------------------------------------------------------------------- /docs/broker.rst: -------------------------------------------------------------------------------- 1 | Broker 2 | =============== 3 | 4 | Sub Account Interface 5 | ------------ 6 | 7 | `Get Broker Info <#>`_ 8 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 9 | .. code:: python 10 | 11 | data = client.broker_get_info() 12 | 13 | `Create Sub Account <#>`_ 14 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15 | .. code:: python 16 | 17 | data = client.broker_sub_create(subName, remark=None) 18 | 19 | `Get Sub List <#>`_ 20 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21 | .. code:: python 22 | 23 | data = client.broker_get_sub_list(pageSize=10, lastEndId=None, status=None) 24 | 25 | `Modify Sub Account <#>`_ 26 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 27 | .. code:: python 28 | 29 | data = client.broker_sub_modify_account(subUid, perm, status) 30 | 31 | `Modify Sub Email <#>`_ 32 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 33 | .. code:: python 34 | 35 | data = client.broker_sub_modify_email(subUid, subEmail): 36 | 37 | `GET Sub Email <#>`_ 38 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 39 | .. code:: python 40 | 41 | data = client.broker_get_sub_email(subUid) 42 | 43 | `Get Sub Spot Assets <#>`_ 44 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 45 | .. code:: python 46 | 47 | data = client.broker_get_sub_spot_assets(subUid) 48 | 49 | `Get Sub Future Assets <#>`_ 50 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 51 | .. code:: python 52 | 53 | data = client.broker_get_sub_future_assets(subUid, productType) 54 | 55 | `Get Sub Deposit Address (Only Broker) <#>`_ 56 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 57 | .. code:: python 58 | 59 | data = client.broker_get_sub_deposit_address(subUid, coin, chain=None) 60 | 61 | `Sub Withdrawal (Only Broker) <#>`_ 62 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 63 | .. code:: python 64 | 65 | data = client.broker_sub_withdrawal(subUid, coin, address, chain, amount, 66 | tag=None, clientOrderId=None, remark=None) 67 | 68 | `Sub Deposit Auto Transfer (Only Broker) <#>`_ 69 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 70 | .. code:: python 71 | 72 | data = client.broker_sub_auto_transfer(subUid, coin, toAccountType) 73 | 74 | Sub API Interface 75 | ------------ 76 | 77 | `Create Sub ApiKey (Only Broker) <#>`_ 78 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 79 | .. code:: python 80 | 81 | data = client.broker_sub_create_api(subUid, passphrase, remark, ip, perm) 82 | 83 | `Get Sub ApiKey List <#>`_ 84 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 85 | .. code:: python 86 | 87 | data = client.broker_get_sub_api_list(subUid) 88 | 89 | `Modify Sub ApiKey (Only Broker) <#>`_ 90 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 91 | .. code:: python 92 | 93 | data = client.broker_sub_modify_api(subUid, apikey, remark=None, ip=None, perm=None) 94 | -------------------------------------------------------------------------------- /docs/conf.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # 4 | # python-bitget documentation build configuration file, created by 5 | # sphinx-quickstart on Thu Sep 21 20:24:54 2017. 6 | # 7 | # This file is execfile()d with the current directory set to its 8 | # containing dir. 9 | # 10 | # Note that not all possible configuration values are present in this 11 | # autogenerated file. 12 | # 13 | # All configuration values have a default; values that are commented out 14 | # serve to show the default. 15 | 16 | # If extensions (or modules to document with autodoc) are in another directory, 17 | # add these directories to sys.path here. If the directory is relative to the 18 | # documentation root, use os.path.abspath to make it absolute, like shown here. 19 | # 20 | import os 21 | import sys 22 | import codecs 23 | import re 24 | # read the contents of your README file 25 | from pathlib import Path 26 | 27 | sys.path.insert(0, os.path.abspath('..')) 28 | 29 | # -- General configuration ------------------------------------------------ 30 | 31 | # If your documentation needs a minimal Sphinx version, state it here. 32 | # 33 | # needs_sphinx = '1.0' 34 | 35 | # Add any Sphinx extension module names here, as strings. They can be 36 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom 37 | # ones. 38 | extensions = [ 39 | 'sphinx.ext.autodoc', 40 | 'sphinx.ext.imgmath', 41 | 'sphinx.ext.viewcode', 42 | 'sphinx.ext.githubpages', 43 | ] 44 | 45 | # Add any paths that contain templates here, relative to this directory. 46 | templates_path = ['_templates'] 47 | 48 | # The suffix(es) of source filenames. 49 | # You can specify multiple suffix as a list of string: 50 | # 51 | source_suffix = ['.rst', '.md'] 52 | # source_suffix = '.rst' 53 | 54 | # The master toctree document. 55 | master_doc = 'index' 56 | 57 | # General information about the project. 58 | project = 'python-bitget' 59 | copyright = '©2023. Built with ❤️by Cuongitl.' 60 | author = 'Cuongitl' 61 | 62 | # The version info for the project you're documenting, acts as replacement for 63 | # |version| and |release|, also used in various other places throughout the 64 | # built documents. 65 | # 66 | version = "1.0.0.4" 67 | release = version 68 | # The language for content autogenerated by Sphinx. Refer to documentation 69 | # for a list of supported languages. 70 | # 71 | # This is also used if you do content translation via gettext catalogs. 72 | # Usually you set "language" from the command line for these cases. 73 | language = None 74 | 75 | # List of patterns, relative to source directory, that match files and 76 | # directories to ignore when looking for source files. 77 | # This patterns also effect to html_static_path and html_extra_path 78 | exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] 79 | 80 | # The name of the Pygments (syntax highlighting) style to use. 81 | pygments_style = 'sphinx' 82 | 83 | # If true, `todo` and `todoList` produce output, else they produce nothing. 84 | todo_include_todos = False 85 | 86 | # -- Options for HTML output ---------------------------------------------- 87 | 88 | # The theme to use for HTML and HTML Help pages. See the documentation for 89 | # a list of builtin themes. 90 | # 91 | # html_theme = 'alabaster' 92 | html_theme = 'sphinx_rtd_theme' 93 | 94 | # Theme options are theme-specific and customize the look and feel of a theme 95 | # further. For a list of options available for each theme, see the 96 | # documentation. 97 | # 98 | # html_theme_options = {} 99 | 100 | # Add any paths that contain custom static files (such as style sheets) here, 101 | # relative to this directory. They are copied after the builtin static files, 102 | # so a file named "default.css" will overwrite the builtin "default.css". 103 | html_static_path = ['_static'] 104 | 105 | # Custom sidebar templates, must be a dictionary that maps document names 106 | # to template names. 107 | # 108 | # This is required for the alabaster theme 109 | # refs: http://alabaster.readthedocs.io/en/latest/installation.html#sidebars 110 | html_sidebars = { 111 | '**': [ 112 | 'about.html', 113 | 'navigation.html', 114 | 'relations.html', # needs 'show_related': True theme option to display 115 | 'searchbox.html', 116 | 'donate.html', 117 | ] 118 | } 119 | 120 | # -- Options for HTMLHelp output ------------------------------------------ 121 | 122 | # Output file base name for HTML help builder. 123 | htmlhelp_basename = 'python-bitgetdoc' 124 | 125 | # -- Options for LaTeX output --------------------------------------------- 126 | 127 | latex_elements = { 128 | # The paper size ('letterpaper' or 'a4paper'). 129 | # 130 | # 'papersize': 'letterpaper', 131 | 132 | # The font size ('10pt', '11pt' or '12pt'). 133 | # 134 | # 'pointsize': '10pt', 135 | 136 | # Additional stuff for the LaTeX preamble. 137 | # 138 | # 'preamble': '', 139 | 140 | # Latex figure (float) alignment 141 | # 142 | # 'figure_align': 'htbp', 143 | } 144 | 145 | # Grouping the document tree into LaTeX files. List of tuples 146 | # (source start file, target name, title, 147 | # author, documentclass [howto, manual, or own class]). 148 | latex_documents = [ 149 | (master_doc, 'python-bitget.tex', 'python-bitget Documentation', 150 | 'Cuongitl', 'manual'), 151 | ] 152 | 153 | # -- Options for manual page output --------------------------------------- 154 | 155 | # One entry per manual page. List of tuples 156 | # (source start file, name, description, authors, manual section). 157 | man_pages = [ 158 | (master_doc, 'python-bitget', 'python-bitget Documentation', 159 | [author], 1) 160 | ] 161 | 162 | # -- Options for Texinfo output ------------------------------------------- 163 | 164 | # Grouping the document tree into Texinfo files. List of tuples 165 | # (source start file, target name, title, author, 166 | # dir menu entry, description, category) 167 | texinfo_documents = [ 168 | (master_doc, 'python-bitget', 'python-bitget Documentation', 169 | author, 'python-bitget', 'One line description of project.', 170 | 'Miscellaneous'), 171 | ] 172 | 173 | 174 | def skip(app, what, name, obj, skip, options): 175 | # Ensure that the __init__ method gets documented. 176 | if name == "__init__": 177 | return False 178 | return skip 179 | 180 | 181 | def setup(app): 182 | app.connect("autodoc-skip-member", skip) 183 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | Welcome to Python-bitget's documentation! 2 | ================================================ 3 | 4 | bitget is a cryptocurrency derivatives exchange. 5 | 6 | If you're new to Bitget, use the following link to `save 10% on all of 7 | your trade fees, and can get rewards up to 8 | $5005. `__ 9 | 10 | This is a wrapper around the Bitget API as described on Bitget, including all features the API provides using clear and readable objects, both for the REST as the websocket API. 11 | 12 | Contents: 13 | 14 | .. toctree:: 15 | :maxdepth: 3 16 | 17 | overview 18 | spot 19 | mix 20 | broker 21 | websockets 22 | 23 | 24 | Index 25 | ================== 26 | 27 | * :ref:`genindex` 28 | -------------------------------------------------------------------------------- /docs/mix.rst: -------------------------------------------------------------------------------- 1 | FuturesⓂ(USDT/Coin) 2 | =============== 3 | 4 | Market 5 | ------------ 6 | 7 | `Get All Symbols <#>`_ 8 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 9 | .. code:: python 10 | 11 | data = client.mix_get_symbols_info(productType) 12 | 13 | `Get Depth <#>`_ 14 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15 | .. code:: python 16 | 17 | data = client.mix_get_depth(symbol, limit=100) 18 | 19 | `Get Single Symbol Ticker <#>`_ 20 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21 | .. code:: python 22 | 23 | data = client.mix_get_single_symbol_ticker(symbol) 24 | 25 | `Get All Symbol Ticker <#>`_ 26 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 27 | .. code:: python 28 | 29 | data = client.mix_get_all_symbol_ticker(productType) 30 | 31 | `Get Fills <#>`_ 32 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 33 | .. code:: python 34 | 35 | # Get recent trades. 36 | data = client.mix_get_fills(symbol, limit=100) 37 | 38 | `Get Candle Data <#>`_ 39 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 40 | .. code:: python 41 | 42 | data = client.mix_get_candles(symbol, granularity, startTime, endTime) 43 | 44 | `Get Symbol Index Price <#>`_ 45 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 46 | .. code:: python 47 | 48 | data = client.mix_get_symbol_index_price(symbol) 49 | 50 | `Get Symbol Next Funding Time <#>`_ 51 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 52 | .. code:: python 53 | 54 | data = client.mix_get_symbol_next_funding(symbol) 55 | 56 | `Get History Funding Rate <#>`_ 57 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 58 | .. code:: python 59 | 60 | data = client.mix_get_history_fund_rate(symbol, pageSize=20, pageNo=1, nextPage=False) 61 | 62 | `Get Current Funding Rate <#>`_ 63 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 64 | .. code:: python 65 | 66 | data = client.mix_get_current_fund_rate(symbol) 67 | 68 | `Get Open Interest <#>`_ 69 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 70 | .. code:: python 71 | 72 | data = client.mix_get_open_interest(symbol) 73 | 74 | `Get Symbol Mark Price <#>`_ 75 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 76 | .. code:: python 77 | 78 | data = client.mix_get_market_price(symbol) 79 | 80 | `Get Symbol Leverage <#>`_ 81 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 82 | .. code:: python 83 | 84 | data = client.mix_get_leverage(symbol) 85 | 86 | Account 87 | ------------ 88 | 89 | `Get Single Account <#>`_ 90 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 91 | .. code:: python 92 | 93 | data = client.mix_get_account(symbol, marginCoin) 94 | 95 | `Get Account List <#>`_ 96 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 97 | .. code:: python 98 | 99 | data = client.mix_get_accounts(productType) 100 | 101 | `Get sub Account Contract Assets <#>`_ 102 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 103 | .. code:: python 104 | 105 | data = client.mix_get_sub_account_contract_assets(productType) 106 | 107 | `Get Open Count <#>`_ 108 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 109 | .. code:: python 110 | 111 | data = client.mix_get_open_count(symbol, marginCoin, openPrice, openAmount, leverage=20) 112 | 113 | `Change Leverage <#>`_ 114 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 115 | .. code:: python 116 | 117 | data = client.mix_adjust_leverage(symbol, marginCoin, leverage, holdSide=None) 118 | 119 | `Change Margin <#>`_ 120 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 121 | .. code:: python 122 | 123 | data = client.mix_adjust_margin(symbol, marginCoin, amount, holdSide=None) 124 | 125 | `Change Margin Mode <#>`_ 126 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 127 | .. code:: python 128 | 129 | data = client.mix_adjust_margintype(symbol, marginCoin, marginMode) 130 | 131 | `Change Hold Mode <#>`_ 132 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 133 | .. code:: python 134 | 135 | data = client.mix_adjust_hold_mode(productType, holdMode) 136 | 137 | `Get Symbol Position <#>`_ 138 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 139 | .. code:: python 140 | 141 | data = client.mix_get_single_position(symbol, marginCoin=None) 142 | 143 | `Get All Position <#>`_ 144 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 145 | .. code:: python 146 | 147 | data = client.mix_get_all_positions(productType, marginCoin=None) 148 | 149 | `Get Account Bill <#>`_ 150 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 151 | .. code:: python 152 | 153 | data = client.mix_get_accountBill(symbol, marginCoin, startTime, endTime, lastEndId='', pageSize=20, next=False) 154 | 155 | `Get Business Account Bill <#>`_ 156 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 157 | .. code:: python 158 | 159 | data = client.mix_get_accountBusinessBill(productType, startTime, endTime, lastEndId='', pageSize=20, next=False) 160 | 161 | Trade 162 | ------------ 163 | 164 | `Place Order <#>`_ 165 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 166 | .. code:: python 167 | 168 | data = client.mix_place_order(symbol, marginCoin, size, side, orderType, 169 | price='', clientOrderId=None, reduceOnly=False, 170 | timeInForceValue='normal', presetTakeProfitPrice='', presetStopLossPrice='') 171 | 172 | `Reversal <#>`_ 173 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 174 | .. code:: python 175 | 176 | data = client.mix_reversal(symbol, marginCoin, side, orderType, 177 | size=None, clientOrderId=None, timeInForceValue='normal', reverse=False) 178 | 179 | `Batch Order <#>`_ 180 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 181 | .. code:: python 182 | 183 | data = client.mix_batch_orders(symbol, marginCoin, orderDataList) 184 | 185 | `Cancel Order <#>`_ 186 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 187 | .. code:: python 188 | 189 | data = client.mix_cancel_order(symbol, marginCoin, orderId) 190 | 191 | `Batch Cancel Order <#>`_ 192 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 193 | .. code:: python 194 | 195 | data = client.mix_batch_cancel_orders(symbol, marginCoin, orderIds) 196 | 197 | `Cancel All Order <#>`_ 198 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 199 | .. code:: python 200 | 201 | data = client.mix_cancel_all_orders(productType, marginCoin) 202 | 203 | `Get Open Order <#>`_ 204 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 205 | .. code:: python 206 | 207 | data = client.mix_get_open_order(symbol) 208 | 209 | `Get All Open Order <#>`_ 210 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 211 | .. code:: python 212 | 213 | data = client.mix_get_all_open_orders(productType, marginCoin=None) 214 | 215 | `Get History Orders <#>`_ 216 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 217 | .. code:: python 218 | 219 | data = client.mix_get_history_orders(symbol, startTime, endTime, pageSize, lastEndId='', isPre=False) 220 | 221 | `Get ProductType History Orders <#>`_ 222 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 223 | .. code:: python 224 | 225 | data = client.mix_get_productType_history_orders(productType, startTime, endTime, pageSize, lastEndId='', isPre=False) 226 | 227 | `Get Order Details <#>`_ 228 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 229 | .. code:: python 230 | 231 | data = client.mix_get_order_details(symbol, orderId=None, clientOrderId=None) 232 | 233 | `Get Order fill detail <#>`_ 234 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 235 | .. code:: python 236 | 237 | data = client.mix_get_order_fill_detail(symbol, orderId=None, startTime=None, endTime=None, lastEndId=None) 238 | 239 | `Get ProductType Order fill detail <#>`_ 240 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 241 | .. code:: python 242 | 243 | data = client.mix_get_productType_order_fill_detail(productType, startTime=None, endTime=None, lastEndId=None) 244 | 245 | `Place Plan order <#>`_ 246 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 247 | .. code:: python 248 | 249 | data = client.mix_place_plan_order(symbol, marginCoin, size, side, orderType, triggerPrice, triggerType 250 | , executePrice=None, clientOrderId=None, presetTakeProfitPrice=None, presetStopLossPrice=None, reduceOnly=False) 251 | 252 | `Modify Plan Order <#>`_ 253 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 254 | .. code:: python 255 | 256 | data = client.mix_modify_plan_order(symbol, marginCoin, orderId, orderType, triggerPrice, triggerType 257 | , executePrice=None) 258 | 259 | `Modify Plan Order TPSL <#>`_ 260 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 261 | .. code:: python 262 | 263 | data = client.mix_modify_plan_order_tpsl(symbol, marginCoin, orderId 264 | , presetTakeProfitPrice=None, presetStopLossPrice=None) 265 | 266 | `Place Stop Order <#>`_ 267 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 268 | .. code:: python 269 | 270 | data = client.mix_place_stop_order(symbol, marginCoin, triggerPrice, planType, holdSide, 271 | triggerType='fill_price', size=None, rangeRate=None) 272 | 273 | `Place Trailing Stop Order <#>`_ 274 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 275 | .. code:: python 276 | 277 | data = client.mix_place_trailing_stop_order(symbol, marginCoin, triggerPrice, side, 278 | triggerType=None, size=None, rangeRate=None) 279 | 280 | `Place Position TPSL <#>`_ 281 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 282 | .. code:: python 283 | 284 | data = client.mix_place_PositionsTPSL(symbol, marginCoin, planType, triggerPrice, triggerType, holdSide=None) 285 | 286 | `Modify Stop Order <#>`_ 287 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 288 | .. code:: python 289 | 290 | data = client.mix_modify_stop_order(symbol, marginCoin, orderId, triggerPrice, planType) 291 | 292 | `Cancel Plan Order (TPSL) <#>`_ 293 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 294 | .. code:: python 295 | 296 | data = client.mix_cancel_plan_order(symbol, marginCoin, orderId, planType) 297 | 298 | `Cancel All trigger Order (TPSL) <#>`_ 299 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 300 | .. code:: python 301 | 302 | data = client.mix_cancel_all_trigger_orders(productType, planType) 303 | 304 | `Get Plan Order (TPSL) List <#>`_ 305 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 306 | .. code:: python 307 | 308 | data = client.mix_get_plan_order_tpsl(symbol=None, productType=None, isPlan=None) 309 | 310 | `Get History Plan Orders (TPSL) <#>`_ 311 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 312 | .. code:: python 313 | 314 | data = client.mix_get_history_plan_orders(symbol, startTime, endTime, pageSize=100, lastEndId=None, isPre=False, isPlan=None) 315 | 316 | CopyTrade 317 | ------------ 318 | 319 | `Get Trader Open order <#>`_ 320 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 321 | .. code:: python 322 | 323 | data = client.mix_get_cp_open_order(symbol, productType, pageSize=20, pageNo=1) 324 | 325 | `Get Follower Open Orders <#>`_ 326 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 327 | .. code:: python 328 | 329 | data = client.mix_get_cp_follower_open_orders(symbol, productType, pageSize=20, pageNo=1) 330 | 331 | `Trader Close Position <#>`_ 332 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 333 | .. code:: python 334 | 335 | data = client.mix_cp_close_position(symbol, trackingNo) 336 | 337 | `Trader Modify TPSL <#>`_ 338 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 339 | .. code:: python 340 | 341 | data = client.mix_cp_modify_tpsl(symbol, trackingNo, stopProfitPrice=None, stopLossPrice=None) 342 | 343 | `Get Traders History Orders <#>`_ 344 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 345 | .. code:: python 346 | 347 | data = client.mix_get_cp_history_orders(startTime, endTime, pageSize=20, pageNo=1) 348 | 349 | `Get Trader Profit Summary <#>`_ 350 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 351 | .. code:: python 352 | 353 | data = client.mix_get_cp_profit_summary() 354 | 355 | `Get Trader History Profit Summary (according to settlement currency) <#>`_ 356 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 357 | .. code:: python 358 | 359 | data = client.mix_get_cp_profit_settle_margin_coin() 360 | 361 | `Get Trader History Profit Summary (according to settlement currency and date) <#>`_ 362 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 363 | .. code:: python 364 | 365 | data = client.mix_get_cp_profit_date_group(pageSize=20, pageNo=1) 366 | 367 | `Get Trader History Profit Detail <#>`_ 368 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 369 | .. code:: python 370 | 371 | data = client.mix_get_cp_profit_date_detail(marginCoin, date, pageSize=20, pageNo=1) 372 | 373 | `Get Trader Profits Details <#>`_ 374 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 375 | .. code:: python 376 | 377 | data = client.mix_get_cp_wait_profit_detail(pageSize=20, pageNo=1) 378 | 379 | `Get CopyTrade Symbols <#>`_ 380 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 381 | .. code:: python 382 | 383 | data = client.mix_get_cp_symbols() 384 | 385 | `Trader Change CopyTrade symbol <#>`_ 386 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 387 | .. code:: python 388 | 389 | data = client.mix_cp_change_symbol(symbol, operation) 390 | -------------------------------------------------------------------------------- /docs/overview.rst: -------------------------------------------------------------------------------- 1 | Getting Started 2 | =============== 3 | 4 | Installation 5 | ------------ 6 | 7 | ``python-bitget`` is available on `PYPI `_. 8 | Install with ``pip``: 9 | 10 | .. code:: bash 11 | 12 | pip install python-bitget 13 | 14 | Register on bitget 15 | ------------------- 16 | 17 | Firstly register an account with bitget `save 10% on all of your trade fee, and can get rewards up to $5005 `_. 18 | 19 | Generate an API Key 20 | ------------------- 21 | 22 | To use signed account methods you are required to `create an API Key `_. 23 | 24 | Initialise the client 25 | --------------------- 26 | 27 | Pass your API Key and Secret 28 | 29 | .. code:: python 30 | 31 | api_key = "your-api-key" 32 | api_secret = "your-secret-key" 33 | api_passphrase = "your-api-passphrase" 34 | client = Client(api_key, api_secret, api_passphrase, use_server_time=False) 35 | 36 | 37 | Making API Calls 38 | ---------------- 39 | 40 | Every method supports the passing of arbitrary parameters via keyword matching those in the 41 | `bitget API documentation `_. 42 | These keyword arguments will be sent directly to the relevant endpoint. 43 | 44 | Each API method returns a dictionary of the JSON response as per the 45 | `bitget API documentation `_. 46 | The docstring of each method in the code references the endpoint it implements. 47 | 48 | The bitget API documentation references a `timestamp` parameter, this is generated for you where required. 49 | 50 | API Endpoints are rate limited by bitget, it's diff on per endpoint, ask them if you require more. 51 | 52 | 53 | 54 | API Rate Limit 55 | -------------- 56 | 57 | The Sub Account and Main Account have their own UIDs. 58 | Because the Limit Rules are based on each UID, every sub account has the same limit rate as main account. 59 | It's not necessary to worry about the limit rate for main account when you are trading with sub accounts Or their API Keys. 60 | And the limit rate is same for every user including VIP account. You may contact your Bitget business manager for more information. 61 | 62 | Some calls have a higher weight than others especially if a call returns information about all symbols. 63 | Read the `official bitget documentation `_ for specific information. 64 | 65 | 66 | Examples 67 | -------------- 68 | 69 | Here are examples to access these 70 | 71 | restAPI example 72 | 73 | .. code:: python 74 | 75 | from bitget import Client 76 | 77 | api_key = "your-api-key" 78 | api_secret = "your-secret-key" 79 | api_passphrase = "your-api-passphrase" 80 | 81 | client = Client(api_key, api_secret, passphrase=api_passphrase) 82 | result = client.mix_get_accounts(productType='UMCBL') 83 | print(result) 84 | 85 | websocketAPI example 86 | 87 | .. code:: python 88 | 89 | from pybitget.stream import BitgetWsClient, SubscribeReq, handel_error 90 | 91 | from pybitget.enums import * 92 | from pybitget import logger 93 | 94 | 95 | def on_message(message): 96 | logger.info(message) 97 | 98 | 99 | api_key = "your-api-key" 100 | api_secret = "your-secret-key" 101 | api_passphrase = "your-api-passphrase" 102 | 103 | if __name__ == '__main__': 104 | # Un-auth subscribe 105 | # client = BitgetWsClient() \ 106 | # .error_listener(handel_error) \ 107 | # .build() 108 | 109 | # Auth subscribe 110 | client = BitgetWsClient(api_key=api_key, 111 | api_secret=api_secret, 112 | passphrase=api_passphrase, 113 | verbose=True) \ 114 | .error_listener(handel_error) \ 115 | .build() 116 | 117 | # multi subscribe - Public Channels 118 | channels = [SubscribeReq("mc", "ticker", "BTCUSD"), SubscribeReq("SP", "candle1W", "BTCUSDT")] 119 | client.subscribe(channels, on_message) 120 | 121 | # single subscribe - # multi subscribe Public Channels 122 | # channels = [SubscribeReq("mc", "ticker", "BTCUSD")] 123 | # client.subscribe(channels, on_message) 124 | 125 | # single subscribe - Order Channel - Private Channels 126 | channels = [SubscribeReq(WS_CHANNEL_INSTTYPE, WS_PRIVATE_ORDERS_CHANNEL, WS_CHANNEL_INSTID)] 127 | client.subscribe(channels, on_message) 128 | -------------------------------------------------------------------------------- /docs/spot.rst: -------------------------------------------------------------------------------- 1 | Spot 2 | =============== 3 | 4 | Public 5 | ------------ 6 | 7 | `Get Server Time <#>`_ 8 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 9 | .. code:: python 10 | 11 | data = client.spot_get_server_time() 12 | 13 | `Get Coin List <#>`_ 14 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 15 | .. code:: python 16 | 17 | data = client.spot_get_coin_list() 18 | 19 | `Get Symbols <#>`_ 20 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21 | .. code:: python 22 | 23 | data = client.spot_get_symbols() 24 | 25 | `Get Single Symbol <#>`_ 26 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 27 | .. code:: python 28 | 29 | data = client.spot_get_symbol() 30 | 31 | Market 32 | ------------ 33 | 34 | `Get Single Ticker <#>`_ 35 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 36 | .. code:: python 37 | 38 | data = client.spot_get_ticker(self, symbol) 39 | 40 | `Get All Tickers <#>`_ 41 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 42 | .. code:: python 43 | 44 | data = client.spot_get_tickers() 45 | 46 | `Get Market Trades <#>`_ 47 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 48 | .. code:: python 49 | 50 | data = client.pot_get_market_trades(self, symbol, limit=100) 51 | 52 | `Get Candle Data <#>`_ 53 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 54 | .. code:: python 55 | 56 | data = client.spot_get_candle_data(self, symbol, period, after='', before='', limit=100) 57 | 58 | `Get Depth <#>`_ 59 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 60 | .. code:: python 61 | 62 | data = client.spot_get_depth(self, symbol, limit='150', type='step0') 63 | 64 | Wallet 65 | ------------ 66 | 67 | `Transfer <#>`_ 68 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 69 | .. code:: python 70 | 71 | data = client.spot_transfer(self, fromType, toType, amount, coin, clientOrderId=None) 72 | 73 | `Sub Transfer <#>`_ 74 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 75 | .. code:: python 76 | 77 | data = client.spot_sub_transfer(self, fromType, toType, amount, coin, clientOrderId, fromUserId, toUserId) 78 | 79 | `Get Coin Address <#>`_ 80 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 81 | .. code:: python 82 | 83 | data = client.spot_get_depositAddress(self, coin, chain) 84 | 85 | `Withdraw <#>`_ 86 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 87 | .. code:: python 88 | 89 | data = client.spot_withdrawal(self, coin, address, chain, amount, remark='', clientOrderId=None, tag=None) 90 | 91 | `Inner Withdraw <#>`_ 92 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 93 | .. code:: python 94 | 95 | data = client.spot_withdrawal_inner(self, coin, toUid, amount, clientOrderId=None) 96 | 97 | `Get Withdraw list <#>`_ 98 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 99 | .. code:: python 100 | 101 | data = client.spot_get_withdrawalList(self, coin, startTime, endTime, pageSize=20, pageNo=1) 102 | 103 | `Get Deposit List <#>`_ 104 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 105 | .. code:: python 106 | 107 | data = client.spot_get_depositList(self, coin, startTime, endTime, pageSize=20, pageNo=1) 108 | 109 | Account 110 | ------------ 111 | 112 | `Get ApiKey Info <#>`_ 113 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 114 | .. code:: python 115 | 116 | data = client.spot_get_ApiKeyInfo() 117 | 118 | `Get Account Assets <#>`_ 119 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 120 | .. code:: python 121 | 122 | data = client.spot_get_account_assets(self, coin=None) 123 | 124 | `Get sub Account Spot Assets <#>`_ 125 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 126 | .. code:: python 127 | 128 | data = client.spot_get_sub_account_assets() 129 | 130 | `Get Bills <#>`_ 131 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 132 | .. code:: python 133 | 134 | data = client.spot_get_bills(self, coinId='', groupType='', bizType='', after='', before='', limit=100) 135 | 136 | `Get Transfer List <#>`_ 137 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 138 | .. code:: python 139 | 140 | data = client.spot_get_transfer_list(self, coinId='', fromType='', after='', before='', limit=100) 141 | 142 | 143 | Trade 144 | ------------ 145 | 146 | `Place order <#>`_ 147 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 148 | .. code:: python 149 | 150 | data = client.spot_place_order(self, symbol, quantity, side, orderType, force, price='', clientOrderId=None) 151 | 152 | `Batch order <#>`_ 153 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 154 | .. code:: python 155 | 156 | data = client.spot_place_batch_orders(self, symbol, orderList) 157 | 158 | `Cancel order <#>`_ 159 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 160 | .. code:: python 161 | 162 | data = client.spot_cance_order(self, symbol, orderId) 163 | 164 | `Cancel order in batch (single instruments) <#>`_ 165 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 166 | .. code:: python 167 | 168 | data = client.spot_cancel_batch_orders(self, symbol, orderIds) 169 | 170 | `Get order details <#>`_ 171 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 172 | .. code:: python 173 | 174 | data = client.spot_get_order_details(self, symbol, orderId, clientOrderId=None) 175 | 176 | `Get order List <#>`_ 177 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 178 | .. code:: python 179 | 180 | data = client.spot_get_open_orders(self, symbol='') 181 | 182 | `Get order history <#>`_ 183 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 184 | .. code:: python 185 | 186 | data = client.spot_get_order_history(self, symbol, after='', before='', limit=100) 187 | 188 | `Get transaction details <#>`_ 189 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 190 | .. code:: python 191 | 192 | data = client.spot_get_transaction_details(self, symbol='', orderId='', after='', before='', limit=100) 193 | 194 | `Place plan order <#>`_ 195 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 196 | .. code:: python 197 | 198 | data = client.spot_place_plan_order(self, symbol, side, triggerPrice, size, triggerType, orderType, 199 | executePrice=None, timeInForceValue=None, clientOrderId=None) 200 | 201 | `Modify plan order <#>`_ 202 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 203 | .. code:: python 204 | 205 | data = client.spot_modify_plan_order(self, orderId, orderType, triggerPrice, 206 | size=None, executePrice=None) 207 | 208 | `Cancel plan order <#>`_ 209 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 210 | .. code:: python 211 | 212 | data = client.spot_cancel_plan_order(self, orderId) 213 | 214 | `Get current plan orders <#>`_ 215 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 216 | .. code:: python 217 | 218 | data = client.spot_get_plan_orders(self, symbol, pageSize=20, lastEndId='') 219 | 220 | `Get history plan orders <#>`_ 221 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 222 | .. code:: python 223 | 224 | data = client.spot_get_history_plan_orders(self, symbol, startTime, endTime, pageSize=20, lastEndId=''): 225 | -------------------------------------------------------------------------------- /docs/websockets.rst: -------------------------------------------------------------------------------- 1 | WebSocketAPI 2 | =============== 3 | 4 | Overview 5 | ------------ 6 | 7 | This is a wrapper around the Bitget API as described on Bitget, so please read the `official documents `_ for more details. 8 | 9 | Example connect 10 | ------------ 11 | 12 | Pass your API Key and Secret 13 | 14 | .. code:: python 15 | 16 | from pybitget.stream import BitgetWsClient, SubscribeReq, handel_error 17 | 18 | from pybitget.enums import * 19 | from pybitget import logger 20 | 21 | 22 | def on_message(message): 23 | logger.info(message) 24 | 25 | 26 | api_key = "your-api-key" 27 | api_secret = "your-secret-key" 28 | api_passphrase = "your-api-passphrase" 29 | 30 | if __name__ == '__main__': 31 | # Un-auth subscribe 32 | # client = BitgetWsClient() \ 33 | # .error_listener(handel_error) \ 34 | # .build() 35 | 36 | # Auth subscribe 37 | client = BitgetWsClient(api_key=api_key, 38 | api_secret=api_secret, 39 | passphrase=api_passphrase, 40 | verbose=True) \ 41 | .error_listener(handel_error) \ 42 | .build() 43 | 44 | # multi subscribe - Public Channels 45 | channels = [SubscribeReq("mc", "ticker", "BTCUSD"), SubscribeReq("SP", "candle1W", "BTCUSDT")] 46 | client.subscribe(channels, on_message) 47 | 48 | # single subscribe - # multi subscribe Public Channels 49 | # channels = [SubscribeReq("mc", "ticker", "BTCUSD")] 50 | # client.subscribe(channels, on_message) 51 | 52 | # single subscribe - Order Channel - Private Channels 53 | channels = [SubscribeReq(WS_CHANNEL_INSTTYPE, WS_PRIVATE_ORDERS_CHANNEL, WS_CHANNEL_INSTID)] 54 | client.subscribe(channels, on_message) 55 | -------------------------------------------------------------------------------- /examples/cancel_orders.py: -------------------------------------------------------------------------------- 1 | from pybitget import Client 2 | from pybitget import logger 3 | 4 | # ========== 5 | api_key = "your-api-key" 6 | api_secret = "your-secret-key" 7 | api_passphrase = "your-api-passphrase" 8 | iClient = Client(api_key, api_secret, api_passphrase, use_server_time=False) 9 | 10 | # ==== 11 | symbol = "SBTCSUSDT_SUMCBL" 12 | marginCoin = "SUSDT" 13 | 14 | 15 | # ==== 16 | def cancel_orders(orderId): 17 | s = iClient.mix_cancel_order(symbol, marginCoin, orderId) 18 | logger.debug(s) 19 | """ 20 | # {'code': '00000', 'msg': 'success', 'requestTime': 1674878544944, 'data': {'orderId': '1003067092170850306', 'clientOid': 'Cuongitl_g9dl0artxawgpqa'}} 21 | """ 22 | 23 | 24 | cancel_orders(1003067092170850306) 25 | -------------------------------------------------------------------------------- /examples/create_orders.py: -------------------------------------------------------------------------------- 1 | from pybitget import Client 2 | from pybitget.utils import random_string 3 | from pybitget.enums import * 4 | from pybitget import logger 5 | 6 | # ========== 7 | api_key = "your-api-key" 8 | api_secret = "your-secret-key" 9 | api_passphrase = "your-api-passphrase" 10 | iClient = Client(api_key, api_secret, api_passphrase, use_server_time=False) 11 | 12 | # ==== 13 | symbol = "SBTCSUSDT_SUMCBL" 14 | marginCoin = "SUSDT" 15 | 16 | 17 | # ==== 18 | def place_order(orderType): 19 | size = "0.01" 20 | side = NEW_BUY 21 | price = 15000 22 | s = iClient.mix_place_order(symbol, marginCoin, size, side, orderType, price=price, clientOrderId=random_string("Cuongitl")) 23 | logger.debug(s) 24 | """ 25 | # {'code': '00000', 'msg': 'success', 'requestTime': 1674875751521, 'data': {'clientOid': 'Cuongitl_g9dl0artxawgpqa', 'orderId': '1003067092170850306'}} 26 | """ 27 | 28 | 29 | def place_tp(): 30 | """ create take-profit """ 31 | planType = "pos_profit" 32 | triggerPrice = "25000.5" 33 | triggerType = "fill_price" # market_price 34 | holdSide = PS_BUY 35 | s = iClient.mix_place_PositionsTPSL(symbol, marginCoin, planType, triggerPrice, triggerType, holdSide=holdSide) 36 | logger.debug(s) 37 | """ 38 | # Place TP: 39 | {'code': '00000', 'msg': 'success', 'requestTime': 1674877422768, 'data': {'clientOid': '1003074101962153984', 'orderId': '1003074101962153985'}} 40 | """ 41 | 42 | 43 | def place_sl(): 44 | """ create stop-loss """ 45 | planType = "pos_loss" 46 | triggerPrice = "13000.5" 47 | triggerType = "fill_price" # market_price 48 | holdSide = PS_BUY 49 | s = iClient.mix_place_PositionsTPSL(symbol, marginCoin, planType, triggerPrice, triggerType, holdSide=holdSide) 50 | logger.debug(s) 51 | """ 52 | # Place SL: 53 | {'code': '00000', 'msg': 'success', 'requestTime': 1674877475451, 'data': {'clientOid': '1003074322897117184', 'orderId': '1003074322897117185'}} 54 | """ 55 | 56 | 57 | # place_order("limit") 58 | place_order("market") 59 | # place_tp() 60 | # place_sl() 61 | -------------------------------------------------------------------------------- /examples/example_rest_api.py: -------------------------------------------------------------------------------- 1 | from pybitget import Client 2 | 3 | api_key = "your-api-key" 4 | api_secret = "your-secret-key" 5 | api_passphrase = "your-api-passphrase" 6 | 7 | client = Client(api_key, api_secret, passphrase=api_passphrase) 8 | result = client.mix_get_accounts(productType='UMCBL') 9 | print(result) 10 | -------------------------------------------------------------------------------- /examples/example_websocket_api.py: -------------------------------------------------------------------------------- 1 | from pybitget.stream import BitgetWsClient, SubscribeReq, handel_error 2 | 3 | from pybitget.enums import * 4 | from pybitget import logger 5 | 6 | 7 | def on_message(message): 8 | logger.info(message) 9 | 10 | 11 | api_key = "your-api-key" 12 | api_secret = "your-secret-key" 13 | api_passphrase = "your-api-passphrase" 14 | 15 | if __name__ == '__main__': 16 | # Un-auth subscribe 17 | # client = BitgetWsClient() \ 18 | # .error_listener(handel_error) \ 19 | # .build() 20 | 21 | # Auth subscribe 22 | client = BitgetWsClient(api_key=api_key, 23 | api_secret=api_secret, 24 | passphrase=api_passphrase, 25 | verbose=True) \ 26 | .error_listener(handel_error) \ 27 | .build() 28 | 29 | # multi subscribe - Public Channels 30 | channels = [SubscribeReq("mc", "ticker", "BTCUSD"), SubscribeReq("SP", "candle1W", "BTCUSDT")] 31 | client.subscribe(channels, on_message) 32 | 33 | # single subscribe - Public Channels 34 | # channels = [SubscribeReq("mc", "ticker", "BTCUSD")] 35 | # client.subscribe(channels, on_message) 36 | 37 | # single subscribe - Order Channel - Private Channels 38 | channels = [SubscribeReq(WS_CHANNEL_INSTTYPE, WS_PRIVATE_ORDERS_CHANNEL, WS_CHANNEL_INSTID)] 39 | client.subscribe(channels, on_message) 40 | -------------------------------------------------------------------------------- /pybitget/__init__.py: -------------------------------------------------------------------------------- 1 | """An unofficial Python wrapper for the bitget exchange API v1 2 | 3 | ... moduleauthor: Cuongitl 4 | 5 | """ 6 | 7 | __version__ = '1.0.8' 8 | 9 | from loguru import logger 10 | from pybitget.client import Client 11 | from pybitget import utils 12 | from pybitget import exceptions 13 | from pybitget.enums import * 14 | -------------------------------------------------------------------------------- /pybitget/client.py: -------------------------------------------------------------------------------- 1 | import requests 2 | import json 3 | from pybitget.enums import * 4 | from pybitget import utils 5 | from pybitget import exceptions 6 | from pybitget import logger 7 | 8 | 9 | class Client(object): 10 | 11 | def __init__(self, api_key, api_secret_key, passphrase, use_server_time=False, verbose=False): 12 | 13 | self.API_KEY = api_key 14 | self.API_SECRET_KEY = api_secret_key 15 | self.PASSPHRASE = passphrase 16 | self.use_server_time = use_server_time 17 | self.verbose = verbose 18 | 19 | def _request(self, method, request_path, params, cursor=False): 20 | if method == GET: 21 | request_path = request_path + utils.parse_params_to_str(params) 22 | # url 23 | url = API_URL + request_path 24 | 25 | # Get local time 26 | timestamp = utils.get_timestamp() 27 | 28 | # sign & header 29 | if self.use_server_time: 30 | # Get server time interface 31 | timestamp = self._get_timestamp() 32 | 33 | body = json.dumps(params) if method == POST else "" 34 | sign = utils.sign(utils.pre_hash(timestamp, method, request_path, str(body)), self.API_SECRET_KEY) 35 | header = utils.get_header(self.API_KEY, sign, timestamp, self.PASSPHRASE) 36 | 37 | # send request 38 | response = None 39 | if method == GET: 40 | response = requests.get(url, headers=header) 41 | elif method == POST: 42 | response = requests.post(url, data=body, headers=header) 43 | elif method == DELETE: 44 | response = requests.delete(url, headers=header) 45 | # exception handle 46 | if not str(response.status_code).startswith('2'): 47 | raise exceptions.BitgetAPIException(response) 48 | try: 49 | res_header = response.headers 50 | if cursor: 51 | r = dict() 52 | try: 53 | r['before'] = res_header['BEFORE'] 54 | r['after'] = res_header['AFTER'] 55 | except: 56 | pass 57 | return response.json(), r 58 | else: 59 | return response.json() 60 | 61 | except ValueError: 62 | raise exceptions.BitgetRequestException('Invalid Response: %s' % response.text) 63 | 64 | def _request_without_params(self, method, request_path): 65 | return self._request(method, request_path, {}) 66 | 67 | def _request_with_params(self, method, request_path, params, cursor=False): 68 | return self._request(method, request_path, params, cursor) 69 | 70 | def _get_timestamp(self): 71 | url = API_URL + SERVER_TIMESTAMP_URL 72 | response = requests.get(url) 73 | if response.status_code == 200: 74 | return response.json()['data'] 75 | else: 76 | return "" 77 | 78 | """ --- MIX-MarkettApi """ 79 | 80 | def mix_get_vip_fee_rate(self): 81 | """ 82 | VIP fee rate: https://bitgetlimited.github.io/apidoc/en/mix/#vip-fee-rate 83 | Limit rule: 10 times/1s (IP) 84 | Required: None 85 | :return: 86 | """ 87 | return self._request_without_params(GET, MIX_MARKET_V1_URL + '/contract-vip-level') 88 | 89 | def mix_get_symbols_info(self, productType): 90 | """ 91 | Get All symbols: https://bitgetlimited.github.io/apidoc/en/mix/#get-all-symbols 92 | Limit rule: 20 times/1s (IP) 93 | Required: productType 94 | :return: 95 | """ 96 | params = {} 97 | if productType: 98 | params["productType"] = productType 99 | return self._request_with_params(GET, MIX_MARKET_V1_URL + '/contracts', params) 100 | else: 101 | logger.error("pls check args") 102 | return False 103 | 104 | def mix_get_depth(self, symbol, limit=100): 105 | """ 106 | Get Depth: https://bitgetlimited.github.io/apidoc/en/mix/#get-depth 107 | 108 | Limit rule: 20 times/1s (IP) 109 | 110 | Required: symbol 111 | 112 | :param symbol: Symbol Id (Must be capitalized) 113 | :type symbol: str 114 | :param limit: Depth gear 5,15,50,100 default 100 115 | :type limit: str 116 | :return: 117 | """ 118 | params = {} 119 | if symbol: 120 | params["symbol"] = symbol 121 | params["limit"] = limit 122 | return self._request_with_params(GET, MIX_MARKET_V1_URL + '/depth', params) 123 | else: 124 | logger.error("pls check args") 125 | return False 126 | 127 | def mix_get_single_symbol_ticker(self, symbol): 128 | """ 129 | Get Single Symbol Ticker: https://bitgetlimited.github.io/apidoc/en/mix/#get-single-symbol-ticker 130 | 131 | Limit rule: 20 times/1s (IP) 132 | 133 | Required: symbol 134 | 135 | :param symbol: Symbol Id (Must be capitalized) 136 | :type symbol: str 137 | :return: 138 | """ 139 | params = {} 140 | if symbol: 141 | params["symbol"] = symbol 142 | return self._request_with_params(GET, MIX_MARKET_V1_URL + '/ticker', params) 143 | else: 144 | logger.error("pls check args") 145 | return False 146 | 147 | def mix_get_all_symbol_ticker(self, productType): 148 | """ 149 | Get All Symbol Ticker: https://bitgetlimited.github.io/apidoc/en/mix/#get-all-symbol-ticker 150 | 151 | Limit rule: 20 times/1s (IP) 152 | 153 | Required: productType 154 | :return: 155 | """ 156 | params = {} 157 | if productType: 158 | params["productType"] = productType 159 | return self._request_with_params(GET, MIX_MARKET_V1_URL + '/tickers', params) 160 | else: 161 | logger.error("pls check args") 162 | return False 163 | 164 | def mix_get_fills(self, symbol, limit=100): 165 | """ 166 | Get recent trades: https://bitgetlimited.github.io/apidoc/en/mix/#get-fills 167 | 168 | Limit rule: 20 times/1s (IP) 169 | 170 | Required: symbol, limit 171 | 172 | :param symbol: Symbol Id (Must be capitalized) 173 | :type symbol: str 174 | :param limit: Default limit is 100 175 | :type limit: str 176 | :return: 177 | """ 178 | params = {} 179 | if symbol: 180 | params["symbol"] = symbol 181 | params["limit"] = limit 182 | return self._request_with_params(GET, MIX_MARKET_V1_URL + '/fills', params) 183 | else: 184 | logger.error("pls check args") 185 | return False 186 | 187 | def mix_get_candles(self, symbol, granularity, startTime, endTime, kLineType='market', limit=100): 188 | """ 189 | Get Candle Data: https://bitgetlimited.github.io/apidoc/en/mix/#get-candle-data 190 | Limit rule: 20 times/1s (IP) 191 | Required: symbol, granularity, startTime, endTime 192 | :return: 193 | """ 194 | params = {} 195 | if symbol and granularity and startTime and endTime: 196 | params["symbol"] = symbol 197 | params["granularity"] = granularity 198 | params["startTime"] = startTime 199 | params["endTime"] = endTime 200 | params["kLineType"] = kLineType 201 | params["limit"] = limit 202 | return self._request_with_params(GET, MIX_MARKET_V1_URL + '/candles', params) 203 | else: 204 | logger.error("pls check args") 205 | return False 206 | 207 | def mix_get_history_candles(self, symbol, granularity, startTime, endTime, limit=100): 208 | """ 209 | Get History Candle Data: https://bitgetlimited.github.io/apidoc/en/mix/#get-history-candle-data 210 | Limit rule: 20 times/1s (IP) 211 | Required: symbol, granularity, startTime, endTime 212 | :return: 213 | """ 214 | params = {} 215 | if symbol and granularity and startTime and endTime: 216 | params["symbol"] = symbol 217 | params["granularity"] = granularity 218 | params["startTime"] = startTime 219 | params["endTime"] = endTime 220 | params["limit"] = limit 221 | return self._request_with_params(GET, MIX_MARKET_V1_URL + '/history-candles', params) 222 | else: 223 | logger.error("pls check args") 224 | return False 225 | 226 | def mix_get_symbol_index_price(self, symbol): 227 | """ 228 | Get Symbol Index Price: https://bitgetlimited.github.io/apidoc/en/mix/#get-symbol-index-price 229 | Limit rule: 20 times/1s (IP) 230 | Required: symbol 231 | :return: 232 | """ 233 | params = {} 234 | if symbol: 235 | params["symbol"] = symbol 236 | return self._request_with_params(GET, MIX_MARKET_V1_URL + '/index', params) 237 | else: 238 | logger.error("pls check args") 239 | return False 240 | 241 | def mix_get_symbol_next_funding(self, symbol): 242 | """ 243 | Get Symbol Next Funding Time: https://bitgetlimited.github.io/apidoc/en/mix/#get-symbol-next-funding-time 244 | Limit rule: 20 times/1s (IP) 245 | Required: symbol 246 | :return: 247 | """ 248 | params = {} 249 | if symbol: 250 | params["symbol"] = symbol 251 | return self._request_with_params(GET, MIX_MARKET_V1_URL + '/funding-time', params) 252 | else: 253 | logger.error("pls check args") 254 | return False 255 | 256 | def mix_get_history_fund_rate(self, symbol, pageSize=20, pageNo=1, nextPage=False): 257 | """ 258 | Get History Funding Rate: https://bitgetlimited.github.io/apidoc/en/mix/#get-history-funding-rate 259 | Limit rule: 20 times/1s (IP) 260 | Required: symbol 261 | :return: 262 | """ 263 | params = {} 264 | if symbol: 265 | params["symbol"] = symbol 266 | params["pageSize"] = pageSize 267 | params["pageNo"] = pageNo 268 | params["nextPage"] = nextPage 269 | return self._request_with_params(GET, MIX_MARKET_V1_URL + '/history-fundRate', params) 270 | else: 271 | logger.error("pls check args") 272 | return False 273 | 274 | def mix_get_current_fund_rate(self, symbol): 275 | """ 276 | Get Current Funding Rate: https://bitgetlimited.github.io/apidoc/en/mix/#get-current-funding-rate 277 | Limit rule: 20 times/1s (IP) 278 | Required: symbol 279 | :return: 280 | """ 281 | params = {} 282 | if symbol: 283 | params["symbol"] = symbol 284 | return self._request_with_params(GET, MIX_MARKET_V1_URL + '/current-fundRate', params) 285 | else: 286 | logger.error("pls check args") 287 | return False 288 | 289 | def mix_get_open_interest(self, symbol): 290 | """ 291 | Get Open Interest: https://bitgetlimited.github.io/apidoc/en/mix/#get-open-interest 292 | Limit rule: 20 times/1s (IP) 293 | Required: symbol 294 | :return: 295 | """ 296 | params = {} 297 | if symbol: 298 | params["symbol"] = symbol 299 | return self._request_with_params(GET, MIX_MARKET_V1_URL + '/open-interest', params) 300 | else: 301 | logger.error("pls check args") 302 | return False 303 | 304 | def mix_get_market_price(self, symbol): 305 | """ 306 | Get Symbol Mark Price: https://bitgetlimited.github.io/apidoc/en/mix/#get-symbol-mark-price 307 | Limit rule: 20 times/1s (IP) 308 | Required: symbol 309 | :return: 310 | """ 311 | params = {} 312 | if symbol: 313 | params["symbol"] = symbol 314 | return self._request_with_params(GET, MIX_MARKET_V1_URL + '/mark-price', params) 315 | else: 316 | logger.error("pls check args") 317 | return False 318 | 319 | def mix_get_leverage(self, symbol): 320 | """ 321 | Get Symbol Leverage: https://bitgetlimited.github.io/apidoc/en/mix/#get-symbol-leverage 322 | Limit rule: 20/sec (IP) 323 | Required: symbol. 324 | 325 | """ 326 | params = {} 327 | if symbol: 328 | params["symbol"] = symbol 329 | return self._request_with_params(GET, MIX_MARKET_V1_URL + '/symbol-leverage', params) 330 | else: 331 | logger.error("pls check args") 332 | return False 333 | 334 | """ --- MIX-AccountApi """ 335 | 336 | def mix_get_account(self, symbol, marginCoin): 337 | """ 338 | Get Single Account: https://bitgetlimited.github.io/apidoc/en/mix/#get-single-account 339 | Required: symbol, marginCoin 340 | :return: 341 | """ 342 | params = {} 343 | if symbol and marginCoin: 344 | params['symbol'] = symbol 345 | params['marginCoin'] = marginCoin 346 | return self._request_with_params(GET, MIX_ACCOUNT_V1_URL + '/account', params) 347 | else: 348 | logger.error("pls check args") 349 | return False 350 | 351 | def mix_get_accounts(self, productType): 352 | """ 353 | Get Account List: https://bitgetlimited.github.io/apidoc/en/mix/#get-account-list 354 | productType: Umcbl (USDT professional contract) dmcbl (mixed contract) sumcbl (USDT professional contract simulation disk) sdmcbl (mixed contract simulation disk) 355 | :return: 356 | """ 357 | params = {} 358 | if productType: 359 | params['productType'] = productType 360 | return self._request_with_params(GET, MIX_ACCOUNT_V1_URL + '/accounts', params) 361 | else: 362 | logger.error("pls check args") 363 | return False 364 | 365 | def mix_get_sub_account_contract_assets(self, productType): 366 | """ 367 | Get sub Account Contract Assets: https://bitgetlimited.github.io/apidoc/en/mix/#get-sub-account-contract-assets 368 | Limit rule: 1 times/10s (uid) 369 | Required: productType 370 | :return: 371 | """ 372 | params = {} 373 | if productType: 374 | params['productType'] = productType 375 | return self._request_with_params(GET, MIX_ACCOUNT_V1_URL + '/sub-account-contract-assets', params) 376 | else: 377 | logger.error("pls check args") 378 | return False 379 | 380 | def mix_get_open_count(self, symbol, marginCoin, openPrice, openAmount, leverage=20): 381 | """ 382 | Get Open Count: https://bitgetlimited.github.io/apidoc/en/mix/#get-open-count 383 | Limit rule: 20 times/1s (IP) 384 | Required: symbol, marginCoin, openPrice, openAmount 385 | 386 | """ 387 | params = {} 388 | if symbol and marginCoin and openPrice and openAmount: 389 | params["symbol"] = symbol 390 | params["marginCoin"] = marginCoin 391 | params["openPrice"] = openPrice 392 | params["openAmount"] = openAmount 393 | params["leverage"] = leverage 394 | return self._request_with_params(GET, MIX_ACCOUNT_V1_URL + '/open-count', params) 395 | else: 396 | logger.error("pls check args") 397 | return False 398 | 399 | def mix_adjust_leverage(self, symbol, marginCoin, leverage, holdSide=None): 400 | """ 401 | Change Leverage: https://bitgetlimited.github.io/apidoc/en/mix/#change-leverage 402 | Limit rule: 5 times/1s (uid) 403 | The leverage could set to different number in fixed margin mode(holdSide is required) 404 | Required: symbol, marginCoin, leverage 405 | 406 | """ 407 | params = {} 408 | if symbol and marginCoin and leverage: 409 | params["symbol"] = symbol 410 | params["marginCoin"] = marginCoin 411 | params["leverage"] = leverage 412 | if holdSide is not None: 413 | params["holdSide"] = holdSide 414 | return self._request_with_params(POST, MIX_ACCOUNT_V1_URL + '/setLeverage', params) 415 | else: 416 | logger.error("pls check args") 417 | return False 418 | 419 | def mix_adjust_margin(self, symbol, marginCoin, amount, holdSide=None): 420 | """ 421 | Change Margin: https://bitgetlimited.github.io/apidoc/en/mix/#change-margin 422 | Limit rule: 5 times/1s (uid) 423 | Required: symbol, marginCoin, marginMode 424 | """ 425 | params = {} 426 | if symbol and marginCoin and amount: 427 | params["symbol"] = symbol 428 | params["marginCoin"] = marginCoin 429 | params["marginMode"] = amount 430 | if holdSide is not None: 431 | params["holdSide"] = holdSide 432 | return self._request_with_params(POST, MIX_ACCOUNT_V1_URL + '/setMargin', params) 433 | else: 434 | logger.error("pls check args") 435 | return False 436 | 437 | def mix_adjust_margintype(self, symbol, marginCoin, marginMode): 438 | """ 439 | Change Margin Mode: https://bitgetlimited.github.io/apidoc/en/mix/#change-margin-mode 440 | Limit rule: 5 times/1s (uid) 441 | Required: symbol, marginCoin, marginMode 442 | """ 443 | params = {} 444 | if symbol and marginCoin and marginMode: 445 | params["symbol"] = symbol 446 | params["marginCoin"] = marginCoin 447 | params["marginMode"] = marginMode 448 | 449 | return self._request_with_params(POST, MIX_ACCOUNT_V1_URL + '/setMarginMode', params) 450 | else: 451 | logger.error("pls check args") 452 | return False 453 | 454 | def mix_adjust_hold_mode(self, productType, holdMode): 455 | """ 456 | Change Hold Mode: https://bitgetlimited.github.io/apidoc/en/mix/#change-hold-mode 457 | Limit rule: 5 times/1s (uid) 458 | Required: productType, holdMode 459 | """ 460 | params = {} 461 | if productType and holdMode: 462 | params["productType"] = productType 463 | params["holdMode"] = holdMode 464 | return self._request_with_params(POST, MIX_ACCOUNT_V1_URL + '/setPositionMode', params) 465 | else: 466 | logger.error("pls check args") 467 | return False 468 | 469 | def mix_get_single_position(self, symbol, marginCoin=None): 470 | """ 471 | Obtain the user's single position information. 472 | Get Symbol Position: https://bitgetlimited.github.io/apidoc/en/mix/#get-symbol-position 473 | 474 | :param symbol: Name of symbol 475 | :type symbol: str 476 | :param marginCoin: Margin currency (Must be capitalized) 477 | :type marginCoin: str 478 | :return: 479 | """ 480 | params = {} 481 | if symbol: 482 | params["symbol"] = symbol 483 | if marginCoin is not None: 484 | params["marginCoin"] = marginCoin 485 | return self._request_with_params(GET, MIX_POSITION_V1_URL + '/singlePosition', params) 486 | else: 487 | logger.error("pls check args") 488 | return False 489 | 490 | def mix_get_all_positions(self, productType, marginCoin=None): 491 | """ 492 | Obtain all position information of the user. 493 | Get All Position: https://bitgetlimited.github.io/apidoc/en/mix/#get-all-position 494 | 495 | :param productType: Umcbl (USDT professional contract) dmcbl (mixed contract) sumcbl (USDT professional contract simulation disk) sdmcbl (mixed contract simulation disk) 496 | :type productType: str 497 | :param marginCoin: Margin currency (Must be capitalized) 498 | :type marginCoin: str 499 | :return: 500 | """ 501 | params = {} 502 | if productType: 503 | params["productType"] = productType 504 | if marginCoin is not None: 505 | params["marginCoin"] = marginCoin 506 | return self._request_with_params(GET, MIX_POSITION_V1_URL + '/allPosition', params) 507 | else: 508 | logger.error("pls check args") 509 | return False 510 | 511 | def mix_get_accountBill(self, symbol, marginCoin, startTime, endTime, lastEndId='', pageSize=20, next=False): 512 | """ 513 | Get Account Bill: https://bitgetlimited.github.io/apidoc/en/mix/#get-account-bill 514 | Limit rule: 10/sec (uid) 515 | Required: symbol, marginCoin, startTime, endTime 516 | :return: 517 | """ 518 | params = {} 519 | if symbol and marginCoin and startTime and endTime: 520 | params['symbol'] = symbol 521 | params['marginCoin'] = marginCoin 522 | params['startTime'] = startTime 523 | params['endTime'] = endTime 524 | params['lastEndId'] = lastEndId 525 | params['pageSize'] = pageSize 526 | params['next'] = next 527 | return self._request_with_params(GET, MIX_ACCOUNT_V1_URL + '/accountBill', params) 528 | else: 529 | logger.error("pls check args") 530 | return False 531 | 532 | def mix_get_accountBusinessBill(self, productType, startTime, endTime, lastEndId='', pageSize=20, next=False): 533 | """ 534 | Get Business Account Bill: https://bitgetlimited.github.io/apidoc/en/mix/#get-business-account-bill 535 | Limit rule: 5/sec (uid) 536 | Required: productType, startTime, endTime 537 | :return: 538 | """ 539 | params = {} 540 | if productType and startTime and endTime: 541 | params['productType'] = productType 542 | params['startTime'] = startTime 543 | params['endTime'] = endTime 544 | params['lastEndId'] = lastEndId 545 | params['pageSize'] = pageSize 546 | params['next'] = next 547 | return self._request_with_params(GET, MIX_ACCOUNT_V1_URL + '/accountBusinessBill', params) 548 | else: 549 | logger.error("pls check args") 550 | return False 551 | 552 | """ --- MIX-tradeApi """ 553 | 554 | def mix_place_order(self, symbol, marginCoin, size, side, orderType, 555 | price='', clientOrderId=None, reduceOnly=False, 556 | timeInForceValue='normal', presetTakeProfitPrice='', presetStopLossPrice=''): 557 | """ 558 | place an order: https://bitgetlimited.github.io/apidoc/en/mix/#place-order 559 | Limit rule: 10 times/1s (uid) 560 | Trader Limit rule: 1 times/1s (uid) 561 | 562 | Required: symbol, marginCoin, size, price, side, orderType. 563 | 564 | price: Mandatory in case of price limit 565 | marginCoin: Deposit currency 566 | size: It is quantity when the price is limited. The market price is the limit. The sales is the quantity 567 | side:open_long open_short close_long close_short 568 | orderType: limit(fixed price) market(market price) 569 | timeInForceValue: normal(Ordinary price limit order) postOnly(It is only a maker. The market price is not allowed to use this) ioc(Close immediately and cancel the remaining) fok(Complete transaction or immediate cancellation) 570 | presetTakeProfitPrice: Default stop profit price 571 | presetStopLossPrice:Preset stop loss price 572 | :return: 573 | """ 574 | params = {} 575 | if symbol and marginCoin and side and orderType and size: 576 | params["symbol"] = symbol 577 | params["marginCoin"] = marginCoin 578 | params["price"] = price 579 | params["size"] = size 580 | params["side"] = side 581 | params["orderType"] = orderType 582 | params["reduceOnly"] = reduceOnly 583 | params["timeInForceValue"] = timeInForceValue 584 | if clientOrderId is not None: 585 | params["clientOid"] = clientOrderId 586 | params["presetTakeProfitPrice"] = presetTakeProfitPrice 587 | params["presetStopLossPrice"] = presetStopLossPrice 588 | return self._request_with_params(POST, MIX_ORDER_V1_URL + '/placeOrder', params) 589 | else: 590 | logger.error("pls check args") 591 | return False 592 | 593 | def mix_reversal(self, symbol, marginCoin, side, orderType, 594 | size=None, clientOrderId=None, timeInForceValue='normal', reverse=False): 595 | """ 596 | Reversal: https://bitgetlimited.github.io/apidoc/en/mix/#reversal 597 | Limit rule: 10 times/1s (uid), counted together with placeOrder 598 | Reversal share the same interface with Place order. 599 | 600 | Required: symbol, marginCoin, side, orderType 601 | 602 | :return: 603 | """ 604 | params = {} 605 | if symbol and marginCoin and side and orderType: 606 | params["symbol"] = symbol 607 | params["marginCoin"] = marginCoin 608 | params["side"] = side 609 | params["orderType"] = orderType 610 | if size is not None: 611 | params["size"] = size 612 | if clientOrderId is not None: 613 | params["clientOid"] = clientOrderId 614 | params["timeInForceValue"] = timeInForceValue 615 | params["reverse"] = reverse 616 | return self._request_with_params(POST, MIX_ORDER_V1_URL + '/placeOrder', params) 617 | else: 618 | logger.error("pls check args") 619 | return False 620 | 621 | def mix_batch_orders(self, symbol, marginCoin, orderDataList): 622 | """ 623 | Batch Order: https://bitgetlimited.github.io/apidoc/en/mix/#batch-order 624 | Limit rule: 10 times/1s (uid) 625 | Trader Limit rule: 1 times/1s (uid) 626 | Required: symbol, marginCoin, orderDataList 627 | """ 628 | params = {} 629 | if symbol and marginCoin and orderDataList: 630 | params["symbol"] = symbol 631 | params["marginCoin"] = marginCoin 632 | params["orderDataList"] = orderDataList 633 | return self._request_with_params(POST, MIX_ORDER_V1_URL + '/batch-orders', params) 634 | else: 635 | logger.error("pls check args") 636 | return False 637 | 638 | def mix_cancel_order(self, symbol, marginCoin, orderId='', clientOid=''): 639 | """ 640 | Cancel Order: https://bitgetlimited.github.io/apidoc/en/mix/#cancel-order 641 | Limit rule: 10 times/1s (uid) 642 | Required: symbol, marginCoin, orderId or clientOid 643 | - Order Id, int64 in string format, 'orderId' or 'clientOid' must have one 644 | - Client Order Id, 'orderId' or 'clientOid' must have one 645 | """ 646 | params = {} 647 | if symbol and marginCoin and (orderId != '' or clientOid != ''): 648 | params["symbol"] = symbol 649 | params["marginCoin"] = marginCoin 650 | if orderId != '': 651 | params["orderId"] = orderId 652 | elif clientOid != '': 653 | params["clientOid"] = clientOid 654 | 655 | return self._request_with_params(POST, MIX_ORDER_V1_URL + '/cancel-order', params) 656 | else: 657 | logger.error("pls check args") 658 | return False 659 | 660 | def mix_batch_cancel_orders(self, symbol, marginCoin, orderId: list = None, clientOid: list = None): 661 | """ Batch Cancel Order 662 | https://bitgetlimited.github.io/apidoc/en/mix/#batch-cancel-order 663 | Limit rule: 10 times/1s (uid) 664 | Required: symbol, marginCoin, orderIds or clientOids 665 | - Order Id list, int64 in string format, 'orderIds' or 'clientOids' must have one 666 | - Client Order Id list, 'orderIds' or 'clientOids' must have one 667 | """ 668 | params = {} 669 | if symbol and marginCoin and orderIds: 670 | params["symbol"] = symbol 671 | params["marginCoin"] = marginCoin 672 | if orderId is not None: 673 | params["orderId"] = orderId 674 | elif clientOid is not None: 675 | params["clientOid"] = clientOid 676 | return self._request_with_params(POST, MIX_ORDER_V1_URL + '/cancel-batch-orders', params) 677 | else: 678 | logger.error("pls check args") 679 | return False 680 | 681 | def mix_cancel_all_orders(self, productType, marginCoin): 682 | """ Cancel All Order 683 | https://bitgetlimited.github.io/apidoc/en/mix/#cancel-all-order 684 | Limit rule: 10 times/1s (uid) 685 | 686 | Required: productType, marginCoin 687 | """ 688 | params = {} 689 | if productType and marginCoin: 690 | params["productType"] = productType 691 | params["marginCoin"] = marginCoin 692 | return self._request_with_params(POST, MIX_ORDER_V1_URL + '/cancel-all-orders', params) 693 | else: 694 | logger.error("pls check args") 695 | return False 696 | 697 | def mix_get_open_order(self, symbol): 698 | """ 699 | Get the current order: https://bitgetlimited.github.io/apidoc/en/mix/#get-open-order 700 | Required: symbol 701 | :return: 702 | """ 703 | params = {} 704 | if symbol: 705 | params["symbol"] = symbol 706 | return self._request_with_params(GET, MIX_ORDER_V1_URL + '/current', params) 707 | else: 708 | logger.error("pls check args") 709 | return False 710 | 711 | def mix_get_all_open_orders(self, productType, marginCoin=None): 712 | """ 713 | Get All Open Order:::https://bitgetlimited.github.io/apidoc/en/mix/#get-all-open-order 714 | Required: productType 715 | :return: 716 | """ 717 | params = {} 718 | if productType: 719 | params["productType"] = productType 720 | if marginCoin is not None: 721 | params["marginCoin"] = marginCoin 722 | return self._request_with_params(GET, MIX_ORDER_V1_URL + '/marginCoinCurrent', params) 723 | else: 724 | logger.error("pls check args") 725 | return False 726 | 727 | def mix_get_history_orders(self, symbol, startTime, endTime, pageSize, lastEndId='', isPre=False): 728 | """ 729 | Get History Orders: https://bitgetlimited.github.io/apidoc/en/mix/#get-history-orders 730 | 731 | Limit rule: 20 times/2s (uid) 732 | 733 | Required: symbol, startTime, endTime, pageSize 734 | 735 | :param symbol: Symbol Id (Must be capitalized) 736 | :type symbol: str 737 | :param startTime: Start time, milliseconds 738 | :type startTime: str 739 | :param endTime: End time, milliseconds 740 | :type endTime: str 741 | :param pageSize: page Size 742 | :type pageSize: str 743 | :param lastEndId: last end Id of last query 744 | :type lastEndId: str 745 | :param isPre: true: order by order Id asc; default false 746 | :type isPre: Boolean 747 | :return: 748 | """ 749 | params = {} 750 | if symbol and startTime and endTime and pageSize: 751 | params["symbol"] = symbol 752 | params["startTime"] = startTime 753 | params["endTime"] = endTime 754 | params["pageSize"] = pageSize 755 | params["lastEndId"] = lastEndId 756 | params["isPre"] = isPre 757 | return self._request_with_params(GET, MIX_ORDER_V1_URL + '/history', params) 758 | else: 759 | logger.error("pls check args") 760 | return False 761 | 762 | def mix_get_productType_history_orders(self, productType, startTime, endTime, pageSize, lastEndId='', isPre=False): 763 | """ 764 | Get ProductType History Orders: https://bitgetlimited.github.io/apidoc/en/mix/#get-producttype-history-orders 765 | 766 | Limit rule: 5/1s (uid) 767 | 768 | Required: productType, startTime, endTime, pageSize 769 | 770 | :param productType 771 | :type productType: str 772 | :param startTime: Start time, milliseconds 773 | :type startTime: str 774 | :param endTime: End time, milliseconds 775 | :type endTime: str 776 | :param pageSize: page Size 777 | :type pageSize: str 778 | :param lastEndId: last end Id of last query 779 | :type lastEndId: str 780 | :param isPre: true: order by order Id asc; default false 781 | :type isPre: Boolean 782 | :return: 783 | """ 784 | params = {} 785 | if productType and startTime and endTime and pageSize: 786 | params["productType"] = productType 787 | params["startTime"] = startTime 788 | params["endTime"] = endTime 789 | params["pageSize"] = pageSize 790 | params["lastEndId"] = lastEndId 791 | params["isPre"] = isPre 792 | return self._request_with_params(GET, MIX_ORDER_V1_URL + '/historyProductType', params) 793 | else: 794 | logger.error("pls check args") 795 | return False 796 | 797 | def mix_get_order_details(self, symbol, orderId=None, clientOrderId=None): 798 | """ 799 | Get Order Details: https://bitgetlimited.github.io/apidoc/en/mix/#get-order-details 800 | Limit rule: 20 times/2s (uid) 801 | Required: symbol 802 | :return: 803 | """ 804 | params = {} 805 | if symbol: 806 | params["symbol"] = symbol 807 | if orderId is not None: 808 | params["orderId"] = orderId 809 | if clientOrderId is not None: 810 | params["clientOid"] = clientOrderId 811 | return self._request_with_params(GET, MIX_ORDER_V1_URL + '/detail', params) 812 | else: 813 | logger.error("pls check args") 814 | return False 815 | 816 | def mix_get_order_fill_detail(self, symbol, orderId=None, startTime=None, endTime=None, lastEndId=None): 817 | """ 818 | Get Order fill detail: https://bitgetlimited.github.io/apidoc/en/mix/#get-order-fill-detail 819 | Limit rule: 20 times/2s (uid) 820 | Required: symbol 821 | :return: 822 | """ 823 | params = {} 824 | if symbol: 825 | params["symbol"] = symbol 826 | if orderId is not None: 827 | params["orderId"] = orderId 828 | if startTime is not None: 829 | params["startTime"] = startTime 830 | if endTime is not None: 831 | params["endTime"] = endTime 832 | if lastEndId is not None: 833 | params["lastEndId"] = lastEndId 834 | return self._request_with_params(GET, MIX_ORDER_V1_URL + '/fills', params) 835 | else: 836 | logger.error("pls check args") 837 | return False 838 | 839 | def mix_get_productType_order_fill_detail(self, productType, startTime=None, endTime=None, lastEndId=None): 840 | """ 841 | Get ProductType Order fill detail: https://bitgetlimited.github.io/apidoc/en/mix/#get-producttype-order-fill-detail 842 | Limit rule: 10 times/1s (uid) 843 | Required: productType 844 | :return: 845 | """ 846 | params = {} 847 | if productType: 848 | params["productType"] = productType 849 | if startTime is not None: 850 | params["startTime"] = startTime 851 | if endTime is not None: 852 | params["endTime"] = endTime 853 | if lastEndId is not None: 854 | params["lastEndId"] = lastEndId 855 | return self._request_with_params(GET, MIX_ORDER_V1_URL + '/allFills', params) 856 | else: 857 | logger.error("pls check args") 858 | return False 859 | 860 | def mix_place_plan_order(self, symbol, marginCoin, size, side, orderType, triggerPrice, triggerType 861 | , executePrice=None, clientOrderId=None, presetTakeProfitPrice=None, presetStopLossPrice=None, reduceOnly=False): 862 | """ 863 | Place Plan order: https://bitgetlimited.github.io/apidoc/en/mix/#place-plan-order 864 | Limit rule: 10 times/1s (uid) 865 | 866 | Required: symbol, marginCoin, size, side, orderType, triggerPrice, triggerType 867 | :return: 868 | """ 869 | params = {} 870 | if symbol and marginCoin and side and size and orderType and triggerPrice and triggerType: 871 | params["symbol"] = symbol 872 | params["marginCoin"] = marginCoin 873 | params["size"] = size 874 | params["side"] = side 875 | params["orderType"] = orderType 876 | params["triggerPrice"] = triggerPrice 877 | params["triggerType"] = triggerType 878 | params["reduceOnly"] = reduceOnly 879 | if executePrice is not None: 880 | params["executePrice"] = executePrice 881 | if clientOrderId is not None: 882 | params["clientOid"] = clientOrderId 883 | if presetTakeProfitPrice is not None: 884 | params["presetTakeProfitPrice"] = presetTakeProfitPrice 885 | if presetStopLossPrice is not None: 886 | params["presetStopLossPrice"] = presetStopLossPrice 887 | return self._request_with_params(POST, MIX_PLAN_V1_URL + '/placePlan', params) 888 | else: 889 | logger.error("pls check args") 890 | return False 891 | 892 | def mix_modify_plan_order(self, symbol, marginCoin, orderId, orderType, triggerPrice, triggerType 893 | , executePrice=None): 894 | """ 895 | Modify Plan Order: https://bitgetlimited.github.io/apidoc/en/mix/#modify-plan-order 896 | Limit rule: 10 times/1s (uid) 897 | 898 | Required: symbol, marginCoin, orderId, orderType, triggerPrice, triggerType 899 | :return: 900 | """ 901 | params = {} 902 | if symbol and marginCoin and orderId and orderType and triggerPrice and triggerType: 903 | params["symbol"] = symbol 904 | params["marginCoin"] = marginCoin 905 | params["orderId"] = orderId 906 | params["orderType"] = orderType 907 | params["triggerPrice"] = triggerPrice 908 | params["triggerType"] = triggerType 909 | if executePrice is not None: 910 | params["executePrice"] = executePrice 911 | return self._request_with_params(POST, MIX_PLAN_V1_URL + '/modifyPlan', params) 912 | else: 913 | logger.error("pls check args") 914 | return False 915 | 916 | def mix_modify_plan_order_tpsl(self, symbol, marginCoin, orderId 917 | , presetTakeProfitPrice=None, presetStopLossPrice=None): 918 | """ 919 | Modify Plan Order TPSL: https://bitgetlimited.github.io/apidoc/en/mix/#modify-plan-order-tpsl 920 | Limit rule: 10 times/1s (uid) 921 | 922 | Required: symbol, marginCoin, orderId 923 | :return: 924 | """ 925 | params = {} 926 | if symbol and marginCoin and orderId: 927 | params["symbol"] = symbol 928 | params["marginCoin"] = marginCoin 929 | params["orderId"] = orderId 930 | if presetTakeProfitPrice is not None: 931 | params["presetTakeProfitPrice"] = presetTakeProfitPrice 932 | if presetStopLossPrice is not None: 933 | params["presetStopLossPrice"] = presetStopLossPrice 934 | return self._request_with_params(POST, MIX_PLAN_V1_URL + '/modifyPlanPreset', params) 935 | else: 936 | logger.error("pls check args") 937 | return False 938 | 939 | def mix_place_stop_order(self, symbol, marginCoin, triggerPrice, planType, holdSide, 940 | triggerType='fill_price', size=None, rangeRate=None): 941 | """ 942 | Place Stop Order: https://bitgetlimited.github.io/apidoc/en/mix/#place-stop-order 943 | Limit rule: 10 times/1s (uid) 944 | 945 | Required: symbol, marginCoin, triggerPrice, planType, holdSide 946 | :return: 947 | """ 948 | params = {} 949 | if symbol and marginCoin and planType and holdSide and triggerPrice: 950 | params["symbol"] = symbol 951 | params["marginCoin"] = marginCoin 952 | params["planType"] = planType 953 | params["holdSide"] = holdSide 954 | params["triggerPrice"] = triggerPrice 955 | params["triggerType"] = triggerType 956 | if size is not None: 957 | params["size"] = size 958 | if rangeRate is not None: 959 | params["rangeRate"] = rangeRate 960 | return self._request_with_params(POST, MIX_PLAN_V1_URL + '/placeTPSL', params) 961 | else: 962 | logger.error("pls check args") 963 | return False 964 | 965 | def mix_place_trailing_stop_order(self, symbol, marginCoin, triggerPrice, side, 966 | triggerType=None, size=None, rangeRate=None): 967 | """ 968 | Place Trailing Stop Order: https://bitgetlimited.github.io/apidoc/en/mix/#place-trailing-stop-order 969 | Limit rule: 10 times/1s (uid) 970 | 971 | Required: symbol, marginCoin, triggerPrice, side 972 | :return: 973 | """ 974 | params = {} 975 | if symbol and marginCoin and side and triggerPrice: 976 | params["symbol"] = symbol 977 | params["marginCoin"] = marginCoin 978 | params["side"] = side 979 | params["triggerPrice"] = triggerPrice 980 | if triggerType is not None: 981 | params["triggerType"] = triggerType 982 | if size is not None: 983 | params["size"] = size 984 | if rangeRate is not None: 985 | params["rangeRate"] = rangeRate 986 | return self._request_with_params(POST, MIX_PLAN_V1_URL + '/placeTrailStop', params) 987 | else: 988 | logger.error("pls check args") 989 | return False 990 | 991 | def mix_place_PositionsTPSL(self, symbol, marginCoin, planType, triggerPrice, triggerType, holdSide=None): 992 | """ 993 | Place Position TPSL: https://bitgetlimited.github.io/apidoc/en/mix/#place-position-tpsl 994 | Limit rule: 10 times/1s (uid) 995 | When the position take profit and stop loss are triggered, the full amount of the position will be entrusted at the market price by default. 996 | Required: marginCoin, symbol, planType, triggerPrice, triggerType 997 | triggertype: fill_price, market_price 998 | """ 999 | params = {} 1000 | if marginCoin and symbol and planType and triggerPrice and triggerType: 1001 | params["symbol"] = symbol 1002 | params["marginCoin"] = marginCoin 1003 | params["planType"] = planType 1004 | params["triggerPrice"] = triggerPrice 1005 | params["triggerType"] = triggerType 1006 | if holdSide is not None: 1007 | params["holdSide"] = holdSide 1008 | return self._request_with_params(POST, MIX_PLAN_V1_URL + '/placePositionsTPSL', params) 1009 | else: 1010 | logger.error("pls check args") 1011 | return False 1012 | 1013 | def mix_modify_stop_order(self, symbol, marginCoin, orderId, triggerPrice, planType): 1014 | """ 1015 | Modify Stop Order: https://bitgetlimited.github.io/apidoc/en/mix/#modify-stop-order 1016 | Limit rule: 10 times/1s (uid) 1017 | Required: symbol, marginCoin, orderId, triggerPrice, planType 1018 | """ 1019 | params = {} 1020 | if symbol and marginCoin and orderId and triggerPrice and planType: 1021 | params["symbol"] = symbol 1022 | params["marginCoin"] = marginCoin 1023 | params["orderId"] = orderId 1024 | params["triggerPrice"] = triggerPrice 1025 | params["planType"] = planType 1026 | return self._request_with_params(POST, MIX_PLAN_V1_URL + '/modifyTPSLPlan', params) 1027 | else: 1028 | logger.error("pls check args") 1029 | return False 1030 | 1031 | def mix_cancel_plan_order(self, symbol, marginCoin, orderId, planType): 1032 | """ 1033 | Cancel Plan Order (TPSL): https://bitgetlimited.github.io/apidoc/en/mix/#cancel-plan-order-tpsl 1034 | Required: symbol, marginCoin, orderId, planType 1035 | Limit rule: 10 times/1s (uid) 1036 | """ 1037 | params = {} 1038 | if symbol and marginCoin and orderId and planType: 1039 | params["symbol"] = symbol 1040 | params["marginCoin"] = marginCoin 1041 | params["orderId"] = orderId 1042 | params["planType"] = planType 1043 | return self._request_with_params(POST, MIX_PLAN_V1_URL + '/cancelPlan', params) 1044 | else: 1045 | logger.error("pls check args") 1046 | return False 1047 | 1048 | def mix_cancel_all_trigger_orders(self, productType, planType): 1049 | """ 1050 | Cancel All trigger Order (TPSL): https://bitgetlimited.github.io/apidoc/en/mix/#cancel-all-trigger-order-tpsl 1051 | Required: productType, planType 1052 | Limit rule: 10 times/1s (uid) 1053 | """ 1054 | params = {} 1055 | if productType and planType: 1056 | params["productType"] = productType 1057 | params["planType"] = planType 1058 | return self._request_with_params(POST, MIX_PLAN_V1_URL + '/cancelAllPlan', params) 1059 | else: 1060 | logger.error("pls check args") 1061 | return False 1062 | 1063 | def mix_get_plan_order_tpsl(self, symbol=None, productType=None, isPlan=None): 1064 | """ 1065 | Get Plan Order (TPSL) List:https://bitgetlimited.github.io/apidoc/en/mix/#get-plan-order-tpsl-list 1066 | can get orders without symbol parameter. 1067 | But either or both of symbol and productType have to be set as request parameters. 1068 | Required: symbol or productType 1069 | isPlan: plan/profit_loss 1070 | Limit rule: 10 times/1s (uid) 1071 | :return: 1072 | """ 1073 | params = {} 1074 | if symbol is not None or productType is not None: 1075 | if symbol is not None: 1076 | params["symbol"] = symbol 1077 | if productType is not None: 1078 | params["productType"] = productType 1079 | if isPlan is not None: 1080 | params["isPlan"] = isPlan 1081 | return self._request_with_params(GET, MIX_PLAN_V1_URL + '/currentPlan', params) 1082 | else: 1083 | logger.error("pls check args") 1084 | return False 1085 | 1086 | def mix_get_history_plan_orders(self, symbol, startTime, endTime, pageSize=100, lastEndId=None, isPre=False, isPlan=None): 1087 | """ 1088 | Get History Plan Orders (TPSL): https://bitgetlimited.github.io/apidoc/en/mix/#get-history-plan-orders-tpsl 1089 | Limit rule: 10 times/1s (uid) 1090 | Required: symbol, startTime, endTime 1091 | :return: 1092 | """ 1093 | params = {} 1094 | if symbol and startTime and endTime: 1095 | params["symbol"] = symbol 1096 | params["startTime"] = startTime 1097 | params["endTime"] = endTime 1098 | params["pageSize"] = pageSize 1099 | params["isPre"] = isPre 1100 | if lastEndId is not None: 1101 | params["lastEndId"] = lastEndId 1102 | if isPlan is not None: 1103 | params["isPlan"] = isPlan 1104 | return self._request_with_params(GET, MIX_PLAN_V1_URL + '/historyPlan', params) 1105 | else: 1106 | logger.error("pls check args") 1107 | return False 1108 | 1109 | """ --- MIX-CopyTradeApi """ 1110 | 1111 | # https://bitgetlimited.github.io/apidoc/en/mix/#copytrade 1112 | # CopyTrade (cp) 1113 | def mix_get_cp_open_order(self, symbol, productType, pageSize=20, pageNo=1): 1114 | """ 1115 | Get Trader Open order: https://bitgetlimited.github.io/apidoc/en/mix/#get-trader-open-order 1116 | Limit rule: 10 times/1s (uid) 1117 | Required: symbol, productType 1118 | :return: 1119 | """ 1120 | params = {} 1121 | if symbol and productType: 1122 | params["symbol"] = symbol 1123 | params["productType"] = productType 1124 | params["pageSize"] = pageSize 1125 | params["pageNo"] = pageNo 1126 | return self._request_with_params(GET, MIX_TRACE_V1_URL + '/currentTrack', params) 1127 | else: 1128 | logger.error("pls check args") 1129 | return False 1130 | 1131 | def mix_get_cp_follower_open_orders(self, symbol, productType, pageSize=20, pageNo=1): 1132 | """ 1133 | Get Follower Open Orders: https://bitgetlimited.github.io/apidoc/en/mix/#get-follower-open-orders 1134 | Limit rule: 10 times/1s (uid) 1135 | Required: symbol, productType 1136 | :return: 1137 | """ 1138 | params = {} 1139 | if symbol and productType: 1140 | params["symbol"] = symbol 1141 | params["productType"] = productType 1142 | params["pageSize"] = pageSize 1143 | params["pageNo"] = pageNo 1144 | return self._request_with_params(GET, MIX_TRACE_V1_URL + '/followerOrder', params) 1145 | else: 1146 | logger.error("pls check args") 1147 | return False 1148 | 1149 | def mix_get_cp_follower_history_orders(self, startTime, endTime, pageSize=20, pageNo=1): 1150 | """ 1151 | Get Follower History Orders: https://bitgetlimited.github.io/apidoc/en/mix/#get-follower-history-orders 1152 | Limit rule: 10 times/1s (uid) 1153 | Required: startTime, endTime 1154 | :return: 1155 | """ 1156 | params = {} 1157 | if startTime and endTime: 1158 | params["startTime"] = startTime 1159 | params["endTime"] = endTime 1160 | params["pageSize"] = pageSize 1161 | params["pageNo"] = pageNo 1162 | return self._request_with_params(GET, MIX_TRACE_V1_URL + '/followerHistoryOrders', params) 1163 | else: 1164 | logger.error("pls check args") 1165 | return False 1166 | 1167 | def mix_cp_close_position(self, symbol, trackingNo): 1168 | """ 1169 | Trader Close Position: https://bitgetlimited.github.io/apidoc/en/mix/#trader-close-position 1170 | Limit rule: 10 times/1s (uid) 1171 | Required: symbol, trackingNo 1172 | :return: 1173 | """ 1174 | params = {} 1175 | if symbol and trackingNo: 1176 | params["symbol"] = symbol 1177 | params["trackingNo"] = trackingNo 1178 | return self._request_with_params(POST, MIX_TRACE_V1_URL + '/closeTrackOrder', params) 1179 | else: 1180 | logger.error("pls check args") 1181 | return False 1182 | 1183 | def mix_cp_modify_tpsl(self, symbol, trackingNo, stopProfitPrice=None, stopLossPrice=None): 1184 | """ 1185 | Trader Modify TPSL: https://bitgetlimited.github.io/apidoc/en/mix/#trader-modify-tpsl 1186 | Limit rule: 10 times/1s (uid) 1187 | Required: symbol, trackingNo 1188 | 1189 | :stopProfitPrice set to null means to disable/cancel TP 1190 | 1191 | :stopLossPrice set to null means to disable/cancel SL 1192 | 1193 | :return: 1194 | """ 1195 | params = {} 1196 | if symbol and trackingNo: 1197 | params["symbol"] = symbol 1198 | params["trackingNo"] = trackingNo 1199 | if stopProfitPrice is not None: 1200 | params["stopProfitPrice"] = stopProfitPrice 1201 | if stopLossPrice is not None: 1202 | params["stopLossPrice"] = stopLossPrice 1203 | return self._request_with_params(POST, MIX_TRACE_V1_URL + '/modifyTPSL', params) 1204 | else: 1205 | logger.error("pls check args") 1206 | return False 1207 | 1208 | def mix_get_cp_history_orders(self, startTime, endTime, pageSize=20, pageNo=1): 1209 | """ 1210 | Get Traders History Orders: https://bitgetlimited.github.io/apidoc/en/mix/#get-traders-history-orders 1211 | Limit rule: 10 times/1s (uid) 1212 | Required: startTime, endTime 1213 | :return: 1214 | """ 1215 | params = {} 1216 | if startTime and endTime: 1217 | params["startTime"] = startTime 1218 | params["endTime"] = endTime 1219 | params["pageSize"] = pageSize 1220 | params["pageNo"] = pageNo 1221 | return self._request_with_params(GET, MIX_TRACE_V1_URL + '/historyTrack', params) 1222 | else: 1223 | logger.error("pls check args") 1224 | return False 1225 | 1226 | def mix_get_cp_profit_summary(self): 1227 | """ 1228 | Get Trader Profit Summary: https://bitgetlimited.github.io/apidoc/en/mix/#get-trader-profit-summary 1229 | Limit rule 20 times/1s (uid) 1230 | Required: None 1231 | :return: 1232 | """ 1233 | return self._request_without_params(GET, MIX_TRACE_V1_URL + '/summary') 1234 | 1235 | def mix_get_cp_profit_settle_margin_coin(self): 1236 | """ 1237 | Get Trader History Profit Summary (according to settlement currency): 1238 | https://bitgetlimited.github.io/apidoc/en/mix/#get-trader-history-profit-summary-according-to-settlement-currency 1239 | Limit rule 20 times/1s (uid) 1240 | Summary of traders' profit sharing (by settlement currency) 1241 | :return: 1242 | """ 1243 | return self._request_without_params(GET, MIX_TRACE_V1_URL + '/profitSettleTokenIdGroup') 1244 | 1245 | def mix_get_cp_profit_date_group(self, pageSize=20, pageNo=1): 1246 | """ 1247 | https://bitgetlimited.github.io/apidoc/en/mix/#get-trader-history-profit-summary-according-to-settlement-currency-and-date 1248 | Limit rule 20 times/1s (uid) 1249 | Summary of traders' profit sharing (by date) 1250 | :return: 1251 | """ 1252 | params = {'pageSize': pageSize, 'pageNo': pageNo} 1253 | return self._request_with_params(GET, MIX_TRACE_V1_URL + '/profitDateGroupList', params) 1254 | 1255 | def mix_get_cp_profit_date_detail(self, marginCoin, date, pageSize=20, pageNo=1): 1256 | """ 1257 | Get Trader History Profit Detail 1258 | https://bitgetlimited.github.io/apidoc/en/mix/#get-trader-history-profit-detail 1259 | Limit rule 20 times/1s (uid) 1260 | Historical profit distribution details of traders 1261 | :return: 1262 | """ 1263 | params = {} 1264 | if marginCoin and date and pageSize and pageNo: 1265 | params["marginCoin"] = marginCoin 1266 | params["date"] = date 1267 | params["pageSize"] = pageSize 1268 | params["pageNo"] = pageNo 1269 | return self._request_with_params(GET, MIX_TRACE_V1_URL + '/profitDateList', params) 1270 | else: 1271 | logger.error("pls check args") 1272 | return False 1273 | 1274 | def mix_get_cp_wait_profit_detail(self, pageSize=20, pageNo=1): 1275 | """ 1276 | Get Trader Profits Details 1277 | https://bitgetlimited.github.io/apidoc/en/mix/#get-trader-profits-details 1278 | Limit rule 20 times/1s (uid) 1279 | Details of traders to be distributed 1280 | :return: 1281 | """ 1282 | params = {} 1283 | if pageSize and pageNo: 1284 | params["pageSize"] = pageSize 1285 | params["pageNo"] = pageNo 1286 | return self._request_with_params(GET, MIX_TRACE_V1_URL + '/waitProfitDateList', params) 1287 | else: 1288 | logger.error("pls check args") 1289 | return False 1290 | 1291 | def mix_get_cp_symbols(self): 1292 | """ 1293 | Get CopyTrade Symbols 1294 | https://bitgetlimited.github.io/apidoc/en/mix/#get-copytrade-symbols 1295 | Limit rule 20 times/1s (uid) 1296 | :return: 1297 | """ 1298 | return self._request_without_params(GET, MIX_TRACE_V1_URL + '/traderSymbols') 1299 | 1300 | def mix_cp_change_symbol(self, symbol, operation): 1301 | """ 1302 | Trader Change CopyTrade symbol: https://bitgetlimited.github.io/apidoc/en/mix/#trader-change-copytrade-symbol 1303 | Limit rule: 10 times/1s (uid) 1304 | Required: symbol, operation 1305 | :return: 1306 | """ 1307 | params = {} 1308 | if symbol and operation: 1309 | params["symbol"] = symbol 1310 | params["operation"] = operation 1311 | return self._request_with_params(POST, MIX_TRACE_V1_URL + '/setUpCopySymbols', params) 1312 | else: 1313 | logger.error("pls check args") 1314 | return False 1315 | 1316 | """ Bitget-Spot-Endpoints""" 1317 | """ Spot-PublicApi""" 1318 | 1319 | def spot_get_server_time(self): 1320 | """ 1321 | Get Server Time: https://bitgetlimited.github.io/apidoc/en/spot/#get-server-time 1322 | Rate Limit: 20 times/1s (IP) 1323 | :return: 1324 | """ 1325 | return self._request_without_params(GET, SPOT_PUBLIC_V1_URL + '/time') 1326 | 1327 | def spot_get_coin_list(self): 1328 | """ 1329 | Get Coin List: https://bitgetlimited.github.io/apidoc/en/spot/#get-coin-list 1330 | Rate Limit: 3 times/1s (IP) 1331 | :return: 1332 | """ 1333 | return self._request_without_params(GET, SPOT_PUBLIC_V1_URL + '/currencies') 1334 | 1335 | def spot_get_symbols(self): 1336 | """ 1337 | Get Symbols: https://bitgetlimited.github.io/apidoc/en/spot/#get-symbols 1338 | Rate Limit: 20 times/1s (IP) 1339 | :return: 1340 | """ 1341 | return self._request_without_params(GET, SPOT_PUBLIC_V1_URL + '/products') 1342 | 1343 | def spot_get_symbol(self, symbol): 1344 | """ 1345 | Get Single Symbol: https://bitgetlimited.github.io/apidoc/en/spot/#get-single-symbol 1346 | Rate Limit: 20 times/1s (IP) 1347 | :return: 1348 | """ 1349 | params = {} 1350 | if symbol: 1351 | params["symbol"] = symbol 1352 | return self._request_with_params(GET, SPOT_PUBLIC_V1_URL + '/product', params) 1353 | else: 1354 | logger.error("pls check args") 1355 | return False 1356 | 1357 | """ Spot-MarketApi""" 1358 | 1359 | def spot_get_tickers(self): 1360 | """ 1361 | Get All Tickers: https://bitgetlimited.github.io/apidoc/en/spot/#get-all-tickers 1362 | 1363 | Rate Limit: 20 times/1s (IP) 1364 | 1365 | Get all transaction pair ticker information 1366 | :return: 1367 | """ 1368 | return self._request_without_params(GET, SPOT_MARKET_V1_URL + '/tickers') 1369 | 1370 | def spot_get_ticker(self, symbol): 1371 | """ 1372 | Get Single Ticker: https://bitgetlimited.github.io/apidoc/en/spot/#get-single-ticker 1373 | 1374 | Rate Limit: 20 times/1s (IP) 1375 | 1376 | Get ticker information according to the currency pair 1377 | :return: 1378 | """ 1379 | params = {} 1380 | if symbol: 1381 | params["symbol"] = symbol 1382 | return self._request_with_params(GET, SPOT_MARKET_V1_URL + '/ticker', params) 1383 | else: 1384 | logger.error("pls check args") 1385 | return False 1386 | 1387 | def spot_get_market_trades(self, symbol, limit=100): 1388 | """ 1389 | Get Market Trades: https://bitgetlimited.github.io/apidoc/en/spot/#get-market-trades 1390 | 1391 | Rate Limit: 20 times/1s (IP) 1392 | 1393 | Get real-time transaction 1394 | :return: 1395 | """ 1396 | params = {} 1397 | if symbol and limit: 1398 | params["symbol"] = symbol 1399 | params["limit"] = limit 1400 | return self._request_with_params(GET, SPOT_MARKET_V1_URL + '/fills', params) 1401 | else: 1402 | logger.error("pls check args") 1403 | return False 1404 | 1405 | def spot_get_candle_data(self, symbol, period, after='', before='', limit=100): 1406 | """ 1407 | Get Candle Data: https://bitgetlimited.github.io/apidoc/en/spot/#get-candle-data 1408 | 1409 | Rate Limit: 20 times/1s (IP) 1410 | 1411 | Obtain K line information 1412 | 1413 | period: 1min, 5min, 15min, 30min, 1h,4h,12h, 1day, 1week 1414 | 1415 | after: Time after, milliseconds 1416 | 1417 | before: Time before, milliseconds 1418 | :return: 1419 | """ 1420 | params = {} 1421 | if symbol and period: 1422 | params["symbol"] = symbol 1423 | params["period"] = period 1424 | params["after"] = after 1425 | params["before"] = before 1426 | params["limit"] = limit 1427 | return self._request_with_params(GET, SPOT_MARKET_V1_URL + '/candles', params) 1428 | else: 1429 | logger.error("pls check args") 1430 | return False 1431 | 1432 | def spot_get_depth(self, symbol, limit='150', type='step0'): 1433 | """ 1434 | Get Depth: https://bitgetlimited.github.io/apidoc/en/spot/#get-depth 1435 | 1436 | Rate Limit: 20 times/1s (IP) 1437 | 1438 | Get depth data 1439 | 1440 | Depth Merge Type 1441 | 1442 | type: step0(default) step1 step2 step3 step4 step5 1443 | :return: 1444 | """ 1445 | params = {} 1446 | if symbol and limit and type: 1447 | params["symbol"] = symbol 1448 | params["limit"] = limit 1449 | params["type"] = type 1450 | return self._request_with_params(GET, SPOT_MARKET_V1_URL + '/depth', params) 1451 | else: 1452 | logger.error("pls check args") 1453 | return False 1454 | 1455 | def spot_get_vip_fee_rate(self): 1456 | """ 1457 | VIP fee rate: https://bitgetlimited.github.io/apidoc/en/spot/#vip-fee-rate 1458 | Limit rule: 10 times/1s (IP) 1459 | Required: None 1460 | :return: 1461 | """ 1462 | return self._request_without_params(GET, SPOT_MARKET_V1_URL + '/spot-vip-level') 1463 | 1464 | """ Spot-WalletApi""" 1465 | 1466 | def spot_transfer(self, fromType, toType, amount, coin, clientOrderId=None): 1467 | """ 1468 | Transfer: https://bitgetlimited.github.io/apidoc/en/spot/#transfer 1469 | 1470 | fromType: spot, mix_usdt, mix_usd 1471 | 1472 | toType: spot, mix_usdt, mix_usd 1473 | 1474 | amount: transfer amount 1475 | 1476 | coin: crypto currency 1477 | :return: 1478 | """ 1479 | params = {} 1480 | if fromType and toType and amount and coin: 1481 | params["fromType"] = fromType 1482 | params["toType"] = toType 1483 | params["amount"] = amount 1484 | params["coin"] = coin 1485 | if clientOrderId is not None: 1486 | params["clientOid"] = clientOrderId 1487 | return self._request_with_params(POST, SPOT_WALLET_V1_URL + '/transfer', params) 1488 | else: 1489 | logger.error("pls check args") 1490 | return False 1491 | 1492 | def spot_sub_transfer(self, fromType, toType, amount, coin, clientOrderId, fromUserId, toUserId): 1493 | """ 1494 | Sub Transfer: https://bitgetlimited.github.io/apidoc/en/spot/#sub-transfer 1495 | Rate Limit:2/sec (uid) 1496 | 1497 | :return: 1498 | """ 1499 | params = {} 1500 | if fromType and toType and amount and coin and fromUserId and toUserId: 1501 | params["fromType"] = fromType 1502 | params["toType"] = toType 1503 | params["amount"] = amount 1504 | params["coin"] = coin 1505 | params["clientOid"] = clientOrderId 1506 | params["fromUserId"] = fromUserId 1507 | params["toUserId"] = toUserId 1508 | return self._request_with_params(POST, SPOT_WALLET_V1_URL + '/subTransfer', params) 1509 | else: 1510 | logger.error("pls check args") 1511 | return False 1512 | 1513 | def spot_get_depositAddress(self, coin, chain): 1514 | """ 1515 | Get Coin Address: https://bitgetlimited.github.io/apidoc/en/spot/#get-coin-address 1516 | 1517 | Rate Limit:5/sec (uid) 1518 | 1519 | GET deposit address 1520 | 1521 | coin: btc usdt 1522 | 1523 | chain: trc20 erc20 1524 | 1525 | :return: 1526 | """ 1527 | params = {} 1528 | if coin and chain: 1529 | params["coin"] = coin 1530 | params["chain"] = chain 1531 | return self._request_with_params(GET, SPOT_WALLET_V1_URL + '/deposit-address', params) 1532 | else: 1533 | logger.error("pls check args") 1534 | return False 1535 | 1536 | def spot_withdrawal(self, coin, address, chain, amount, remark='', clientOrderId=None, tag=None): 1537 | """ 1538 | Withdraw: https://bitgetlimited.github.io/apidoc/en/spot/#withdraw 1539 | 1540 | Just withdraw coins on the chain 1541 | 1542 | Rate Limit:5/sec (Uid) 1543 | 1544 | :return: 1545 | """ 1546 | params = {} 1547 | if coin: 1548 | params["coin"] = coin 1549 | params["address"] = address 1550 | params["chain"] = chain 1551 | params["amount"] = amount 1552 | params["remark"] = remark 1553 | if clientOrderId is not None: 1554 | params["clientOid"] = clientOrderId 1555 | if tag is not None: 1556 | params["tag"] = tag 1557 | return self._request_with_params(POST, SPOT_WALLET_V1_URL + '/withdrawal', params) 1558 | else: 1559 | logger.error("pls check args") 1560 | return False 1561 | 1562 | def spot_withdrawal_inner(self, coin, toUid, amount, clientOrderId=None): 1563 | """ 1564 | Inner Withdraw: https://bitgetlimited.github.io/apidoc/en/spot/#inner-withdraw 1565 | 1566 | Internal withdrawal means that both users are on the Bitget platform 1567 | 1568 | Withdraw money directly in the form of uid, without going on the chain, no need to pass the address 1569 | 1570 | Rate Limit: 5/sec (Uid) 1571 | 1572 | :return: 1573 | """ 1574 | params = {} 1575 | if coin and toUid and amount: 1576 | params["coin"] = coin 1577 | params["amount"] = amount 1578 | params["toUid"] = toUid 1579 | if clientOrderId is not None: 1580 | params["clientOid"] = clientOrderId 1581 | return self._request_with_params(POST, SPOT_WALLET_V1_URL + '/withdrawal-inner', params) 1582 | else: 1583 | logger.error("pls check args") 1584 | return False 1585 | 1586 | def spot_get_withdrawalList(self, coin, startTime, endTime, pageSize=20, pageNo=1): 1587 | """ 1588 | Get Withdraw list: https://bitgetlimited.github.io/apidoc/en/spot/#get-withdraw-list 1589 | 1590 | Rate Limit:20/1s (Uid) 1591 | 1592 | :return: 1593 | """ 1594 | params = {} 1595 | if coin and startTime and endTime: 1596 | params["coin"] = coin 1597 | params["startTime"] = startTime 1598 | params["endTime"] = endTime 1599 | params["pageNo"] = pageNo 1600 | params["pageSize"] = pageSize 1601 | return self._request_with_params(GET, SPOT_WALLET_V1_URL + '/withdrawal-list', params) 1602 | else: 1603 | logger.error("pls check args") 1604 | return False 1605 | 1606 | def spot_get_depositList(self, coin, startTime, endTime, pageSize=20, pageNo=1): 1607 | """ 1608 | Get Deposit List: https://bitgetlimited.github.io/apidoc/en/spot/#get-deposit-list 1609 | 1610 | Rate Limit:20/1s (Uid) 1611 | 1612 | :return: 1613 | """ 1614 | params = {} 1615 | if coin and startTime and endTime: 1616 | params["coin"] = coin 1617 | params["startTime"] = startTime 1618 | params["endTime"] = endTime 1619 | params["pageNo"] = pageNo 1620 | params["pageSize"] = pageSize 1621 | return self._request_with_params(GET, SPOT_WALLET_V1_URL + '/deposit-list', params) 1622 | else: 1623 | logger.error("pls check args") 1624 | return False 1625 | 1626 | """ Spot-AccountApi""" 1627 | 1628 | def spot_get_ApiKeyInfo(self): 1629 | """ 1630 | Get ApiKey Info: https://bitgetlimited.github.io/apidoc/en/spot/#get-apikey-info 1631 | 1632 | Rate Limit: 1/sec (Uid) 1633 | 1634 | :return: 1635 | """ 1636 | return self._request_without_params(GET, SPOT_ACCOUNT_V1_URL + '/getInfo') 1637 | 1638 | def spot_get_account_assets(self, coin=None): 1639 | """ 1640 | Get Account Assets: https://bitgetlimited.github.io/apidoc/en/spot/#get-account-assets 1641 | 1642 | Rate Limit: 10 times/1s (uid) 1643 | 1644 | Obtain all asset currency information of the user 1645 | 1646 | :return: 1647 | """ 1648 | params = {} 1649 | if coin is not None: 1650 | params["coin"] = coin 1651 | return self._request_with_params(GET, SPOT_ACCOUNT_V1_URL + '/assets', params) 1652 | 1653 | def spot_get_sub_account_assets(self): 1654 | """ 1655 | Get sub Account Spot Assets: https://bitgetlimited.github.io/apidoc/en/spot/#get-sub-account-spot-assets 1656 | 1657 | Rate Limit: 1 times/10s (uid) 1658 | 1659 | ***Warning*** This endpoint's worked on POST, but the Request Example is GET. 1660 | 1661 | Why this endpoint name is "Get sub Account Spot Assets", but it's used POST ?!! 1662 | 1663 | :return: 1664 | """ 1665 | if self.verbose: 1666 | logger.warning("***Warning*** This endpoint's worked on POST") 1667 | return self._request_without_params(POST, SPOT_ACCOUNT_V1_URL + '/sub-account-spot-assets') 1668 | 1669 | def spot_get_bills(self, coinId='', groupType='', bizType='', after='', before='', limit=100): 1670 | """ 1671 | Get Bills: https://bitgetlimited.github.io/apidoc/en/spot/#get-bills 1672 | 1673 | Rate Limit: 10 times/1s (uid) 1674 | 1675 | Obtain all asset currency information of the user 1676 | 1677 | groupType: Deposit, withdraw, transaction, transfer, other 1678 | 1679 | bizType:Dispose, withdraw, buy, sell, transfer in, transfer out 1680 | 1681 | after: Pass in billId, the data before this billId 1682 | 1683 | before: Incoming billId data after this billId 1684 | 1685 | :return: 1686 | """ 1687 | params = {} 1688 | 1689 | if coinId: 1690 | params["coinId"] = coinId 1691 | if groupType: 1692 | params["groupType"] = groupType 1693 | if bizType: 1694 | params["bizType"] = bizType 1695 | if after: 1696 | params["after"] = after 1697 | if before: 1698 | params["before"] = before 1699 | 1700 | params["limit"] = limit 1701 | return self._request_with_params(POST, SPOT_ACCOUNT_V1_URL + '/bills', params) 1702 | 1703 | def spot_get_transfer_list(self, coinId='', fromType='', after='', before='', limit=100): 1704 | """ 1705 | Get Transfer List: https://bitgetlimited.github.io/apidoc/en/spot/#get-transfer-list 1706 | 1707 | Rate Limit: 20 times/1s (uid) 1708 | 1709 | query transfer records 1710 | 1711 | fromType: exchange(spot) USD_MIX(coin future) USDT_MIX(usdt future) 1712 | 1713 | :return: 1714 | """ 1715 | params = {} 1716 | 1717 | if coinId: 1718 | params["coinId"] = coinId 1719 | if fromType: 1720 | params["fromType"] = fromType 1721 | if after: 1722 | params["after"] = after 1723 | if before: 1724 | params["before"] = before 1725 | 1726 | params["limit"] = limit 1727 | return self._request_with_params(GET, SPOT_ACCOUNT_V1_URL + '/transferRecords', params) 1728 | 1729 | """ Spot-TradeApi""" 1730 | 1731 | def spot_place_order(self, symbol, quantity, side, orderType, force, price='', clientOrderId=None): 1732 | """ 1733 | Place order: https://bitgetlimited.github.io/apidoc/en/spot/#place-order 1734 | 1735 | Rate Limit: 10/sec (uid) 1736 | 1737 | price: Mandatory in case of price limit 1738 | 1739 | quantity: It is quantity when the price is limited. The market price is the limit. The sales is the quantity 1740 | 1741 | side:buy sell 1742 | 1743 | orderType: limit(fixed price) market(market price) 1744 | 1745 | force:normal(Ordinary price limit order) postOnly(It is only a maker. 1746 | 1747 | The market price is not allowed to use this) ioc(Close immediately and cancel the remaining) fok(Complete transaction or immediate cancellation) 1748 | 1749 | :return: 1750 | """ 1751 | params = {} 1752 | 1753 | if symbol and quantity and side and orderType and force: 1754 | params["symbol"] = symbol 1755 | params["price"] = price 1756 | params["quantity"] = quantity 1757 | params["side"] = side 1758 | params["orderType"] = orderType 1759 | params["force"] = force 1760 | if clientOrderId is not None: 1761 | params["clientOrderId"] = clientOrderId 1762 | return self._request_with_params(POST, SPOT_ORDER_V1_URL + '/orders', params) 1763 | else: 1764 | logger.error("pls check args") 1765 | return False 1766 | 1767 | def spot_place_batch_orders(self, symbol, orderList): 1768 | """ 1769 | Batch order: https://bitgetlimited.github.io/apidoc/en/spot/#batch-order 1770 | 1771 | Rate Limit: 5/sec (uid) 1772 | 1773 | Place orders in batches 1774 | 1775 | :return: 1776 | """ 1777 | 1778 | if symbol and orderList: 1779 | params = {'symbol': symbol, 'orderList': orderList} 1780 | return self._request_with_params(POST, SPOT_ORDER_V1_URL + "/batch-orders", params) 1781 | else: 1782 | logger.error("pls check args") 1783 | return False 1784 | 1785 | def spot_cance_order(self, symbol, orderId): 1786 | """ 1787 | Cancel order: https://bitgetlimited.github.io/apidoc/en/spot/#cancel-order 1788 | 1789 | Rate Limit: 10 times/sec (uid) 1790 | 1791 | :return: 1792 | """ 1793 | params = {} 1794 | 1795 | if symbol and orderId: 1796 | params["symbol"] = symbol 1797 | params["orderId"] = orderId 1798 | return self._request_with_params(POST, SPOT_ORDER_V1_URL + '/cancel-order', params) 1799 | else: 1800 | logger.error("pls check args") 1801 | return False 1802 | 1803 | def spot_cancel_batch_orders(self, symbol, orderIds): 1804 | """ 1805 | Cancel order in batch (single instruments): https://bitgetlimited.github.io/apidoc/en/spot/#cancel-order-in-batch-single-instruments 1806 | 1807 | Rate Limit: 5 times/1s (uid) 1808 | 1809 | Batch cancellation 1810 | 1811 | :return: 1812 | """ 1813 | 1814 | if symbol and orderIds: 1815 | params = {'symbol': symbol, 'orderIds': orderIds} 1816 | return self._request_with_params(POST, SPOT_ORDER_V1_URL + "/cancel-batch-orders", params) 1817 | else: 1818 | logger.error("pls check args") 1819 | return False 1820 | 1821 | def spot_get_order_details(self, symbol, orderId, clientOrderId=None): 1822 | """ 1823 | Get order details:https://bitgetlimited.github.io/apidoc/en/spot/#get-order-details 1824 | 1825 | Rate Limit: 20 times/sec(uid) 1826 | 1827 | User could query cancelled/filled order details within 24 hours; Noted that after 24 hours should query via history interface. 1828 | :return: 1829 | """ 1830 | params = {} 1831 | if symbol and orderId: 1832 | params["symbol"] = symbol 1833 | params["orderId"] = orderId 1834 | if clientOrderId is not None: 1835 | params["clientOrderId"] = clientOrderId 1836 | 1837 | if self.verbose: 1838 | logger.warning("***Warning*** This endpoint's worked on POST") 1839 | 1840 | return self._request_with_params(POST, SPOT_ORDER_V1_URL + '/orderInfo', params) 1841 | else: 1842 | logger.error("pls check args") 1843 | return False 1844 | 1845 | def spot_get_open_orders(self, symbol=''): 1846 | """ 1847 | Get order List: https://bitgetlimited.github.io/apidoc/en/spot/#get-order-list 1848 | 1849 | Rate Limit: 20 times/sec(uid) 1850 | 1851 | :return: 1852 | """ 1853 | params = {"symbol": symbol} 1854 | if self.verbose: 1855 | logger.warning("***Warning*** This endpoint's worked on POST") 1856 | 1857 | return self._request_with_params(POST, SPOT_ORDER_V1_URL + '/open-orders', params) 1858 | 1859 | def spot_get_order_history(self, symbol, after='', before='', limit=100): 1860 | """ 1861 | Get order history: https://bitgetlimited.github.io/apidoc/en/spot/#get-order-history 1862 | 1863 | Rate Limit: 20 times/sec(uid) 1864 | 1865 | Get Historical Delegation 1866 | after: The orderId is passed in. The data before the orderId desc 1867 | 1868 | before: Pass in the data after the orderId asc 1869 | 1870 | :return: 1871 | """ 1872 | params = {} 1873 | if symbol: 1874 | params["symbol"] = symbol 1875 | params["after"] = after 1876 | params["before"] = before 1877 | params["limit"] = limit 1878 | if self.verbose: 1879 | logger.warning("***Warning*** This endpoint's worked on POST") 1880 | 1881 | return self._request_with_params(POST, SPOT_ORDER_V1_URL + '/history', params) 1882 | else: 1883 | logger.error("pls check args") 1884 | return False 1885 | 1886 | def spot_get_transaction_details(self, symbol='', orderId='', after='', before='', limit=100): 1887 | """ 1888 | Get transaction details: https://bitgetlimited.github.io/apidoc/en/spot/#get-transaction-details 1889 | 1890 | Rate Limit: 20 times/sec(uid) 1891 | 1892 | Obtain transaction details 1893 | 1894 | after: Only the data before the fillId can be passed in 1895 | 1896 | before: Only data passing in the fillId after this fillId is supported 1897 | :return: 1898 | """ 1899 | params = {} 1900 | if symbol: 1901 | params["symbol"] = symbol 1902 | params["orderId"] = orderId 1903 | params["after"] = after 1904 | params["before"] = before 1905 | params["limit"] = limit 1906 | if self.verbose: 1907 | logger.warning("***Warning*** This endpoint's worked on POST") 1908 | 1909 | return self._request_with_params(POST, SPOT_ORDER_V1_URL + '/fills', params) 1910 | else: 1911 | logger.error("pls check args") 1912 | return False 1913 | 1914 | def spot_place_plan_order(self, symbol, side, triggerPrice, size, triggerType, orderType, 1915 | executePrice=None, timeInForceValue=None, clientOrderId=None): 1916 | """ 1917 | Place plan order: https://bitgetlimited.github.io/apidoc/en/spot/#place-plan-order 1918 | 1919 | Rate Limit: 20 times/sec (uid) 1920 | 1921 | Required: symbol, side, triggerPrice, size, triggerType, orderType 1922 | 1923 | :return: 1924 | """ 1925 | params = {} 1926 | 1927 | if symbol and side and triggerPrice and size and triggerType: 1928 | params["symbol"] = symbol 1929 | params["side"] = side 1930 | params["triggerPrice"] = triggerPrice 1931 | params["size"] = size 1932 | params["triggerType"] = triggerType 1933 | params["orderType"] = orderType 1934 | if clientOrderId is not None: 1935 | params["clientOid"] = clientOrderId 1936 | if executePrice is not None: 1937 | params["executePrice"] = executePrice 1938 | if timeInForceValue is not None: 1939 | params["timeInForceValue"] = timeInForceValue 1940 | return self._request_with_params(POST, SPOT_PLAN_V1_URL + '/placePlan', params) 1941 | else: 1942 | logger.error("pls check args") 1943 | return False 1944 | 1945 | def spot_modify_plan_order(self, orderId, orderType, triggerPrice, 1946 | size=None, executePrice=None): 1947 | """ 1948 | Modify Plan Order: https://bitgetlimited.github.io/apidoc/en/spot/#modify-plan-order 1949 | Limit rule: 20 times/sec (uid) 1950 | 1951 | Required: orderId, orderType, triggerPrice 1952 | :return: 1953 | """ 1954 | params = {} 1955 | if orderId and orderType and triggerPrice: 1956 | params["orderId"] = orderId 1957 | params["orderType"] = orderType 1958 | params["triggerPrice"] = triggerPrice 1959 | if executePrice is not None: 1960 | params["executePrice"] = executePrice 1961 | if size is not None: 1962 | params["size"] = size 1963 | return self._request_with_params(POST, SPOT_PLAN_V1_URL + '/modifyPlan', params) 1964 | else: 1965 | logger.error("pls check args") 1966 | return False 1967 | 1968 | def spot_cancel_plan_order(self, orderId): 1969 | """ 1970 | Cancel plan order: https://bitgetlimited.github.io/apidoc/en/spot/#cancel-plan-order 1971 | Required: orderId 1972 | Limit rule: 20 times/sec (uid) 1973 | """ 1974 | params = {} 1975 | if orderId: 1976 | params["orderId"] = orderId 1977 | return self._request_with_params(POST, MIX_PLAN_V1_URL + '/cancelPlan', params) 1978 | else: 1979 | logger.error("pls check args") 1980 | return False 1981 | 1982 | def spot_get_plan_orders(self, symbol, pageSize=20, lastEndId=''): 1983 | """ 1984 | Get current plan orders: https://bitgetlimited.github.io/apidoc/en/spot/#get-current-plan-orders 1985 | 1986 | Rate Limit: 20 times/sec(uid) 1987 | 1988 | :return: 1989 | """ 1990 | params = {} 1991 | if symbol: 1992 | params["symbol"] = symbol 1993 | params["pageSize"] = pageSize 1994 | params["lastEndId"] = lastEndId 1995 | if self.verbose: 1996 | logger.warning("***Warning*** This endpoint's worked on POST") 1997 | 1998 | return self._request_with_params(POST, SPOT_PLAN_V1_URL + '/currentPlan', params) 1999 | else: 2000 | logger.error("pls check args") 2001 | return False 2002 | 2003 | def spot_get_history_plan_orders(self, symbol, startTime, endTime, pageSize=20, lastEndId=''): 2004 | """ 2005 | Get history plan orders: https://bitgetlimited.github.io/apidoc/en/spot/#get-history-plan-orders 2006 | 2007 | Rate Limit: 20 times/sec(uid) 2008 | 2009 | :return: 2010 | """ 2011 | params = {} 2012 | if symbol and startTime and endTime: 2013 | params["symbol"] = symbol 2014 | params["startTime"] = startTime 2015 | params["endTime"] = endTime 2016 | params["pageSize"] = pageSize 2017 | params["lastEndId"] = lastEndId 2018 | if self.verbose: 2019 | logger.warning("***Warning*** This endpoint's worked on POST") 2020 | 2021 | return self._request_with_params(POST, SPOT_PLAN_V1_URL + '/historyPlan', params) 2022 | else: 2023 | logger.error("pls check args") 2024 | return False 2025 | 2026 | """ Broker-Sub-API-Interface""" 2027 | 2028 | def broker_sub_create_api(self, subUid, passphrase, remark, ip, perm): 2029 | """ Create Sub ApiKey (Only Broker) : https://bitgetlimited.github.io/apidoc/en/broker/#create-sub-apikey-only-broker 2030 | 2031 | Limit rule:10/sec (uid) 2032 | 2033 | broker create sub apikey 2034 | 2035 | :return: 2036 | """ 2037 | params = {} 2038 | if subUid and passphrase and perm: 2039 | params["subUid"] = subUid 2040 | params["passphrase"] = passphrase 2041 | params["remark"] = remark 2042 | params["ip"] = ip 2043 | params["perm"] = perm 2044 | return self._request_with_params(POST, BROKER_MANAGE_V1_URL + '/sub-api-create', params) 2045 | else: 2046 | logger.error("pls check args") 2047 | return False 2048 | 2049 | def broker_get_sub_api_list(self, subUid): 2050 | """ Get Sub ApiKey List : https://bitgetlimited.github.io/apidoc/en/broker/#get-sub-apikey-list 2051 | 2052 | Limit rule:10/sec (uid) 2053 | 2054 | 2055 | :return: 2056 | """ 2057 | params = {} 2058 | if subUid: 2059 | params["subUid"] = subUid 2060 | return self._request_with_params(GET, BROKER_MANAGE_V1_URL + '/sub-api-list', params) 2061 | else: 2062 | logger.error("pls check args") 2063 | return False 2064 | 2065 | def broker_sub_modify_api(self, subUid, apikey, remark=None, ip=None, perm=None): 2066 | """ Modify Sub ApiKey (Only Broker) : https://bitgetlimited.github.io/apidoc/en/broker/#modify-sub-apikey-only-broker 2067 | 2068 | Limit rule:10/sec (uid) 2069 | 2070 | :return: 2071 | """ 2072 | params = {} 2073 | if subUid and apikey: 2074 | params["subUid"] = subUid 2075 | params["apikey"] = apikey 2076 | if remark is not None: 2077 | params["remark"] = remark 2078 | if ip is not None: 2079 | params["ip"] = ip 2080 | if perm is not None: 2081 | params["perm"] = perm 2082 | return self._request_with_params(POST, BROKER_MANAGE_V1_URL + '/sub-api-modify', params) 2083 | else: 2084 | logger.error("pls check args") 2085 | return False 2086 | 2087 | """ Broker-Sub-Account-Interface""" 2088 | 2089 | def broker_get_info(self): 2090 | """ Get Broker Info 2091 | https://bitgetlimited.github.io/apidoc/en/broker/#get-broker-info """ 2092 | return self._request_without_params(GET, BROKER_ACCOUNT_V1_URL + '/info') 2093 | 2094 | def broker_sub_create(self, subName, remark=None): 2095 | """ Create Sub Account 2096 | https://bitgetlimited.github.io/apidoc/en/broker/#create-sub-account """ 2097 | params = {} 2098 | if subName: 2099 | params["subName"] = subName 2100 | if remark is not None: 2101 | params["remark"] = remark 2102 | return self._request_with_params(POST, BROKER_ACCOUNT_V1_URL + '/sub-create', params) 2103 | else: 2104 | logger.error("pls check args") 2105 | return False 2106 | 2107 | def broker_get_sub_list(self, pageSize=10, lastEndId=None, status=None): 2108 | """ Get Sub List 2109 | https://bitgetlimited.github.io/apidoc/en/broker/#get-sub-list """ 2110 | params = {} 2111 | if pageSize: 2112 | params["pageSize"] = pageSize 2113 | if lastEndId is not None: 2114 | params["lastEndId"] = lastEndId 2115 | if status is not None: 2116 | params["status"] = status 2117 | return self._request_with_params(GET, BROKER_ACCOUNT_V1_URL + '/sub-list', params) 2118 | else: 2119 | logger.error("pls check args") 2120 | return False 2121 | 2122 | def broker_sub_modify_account(self, subUid, perm, status): 2123 | """ Modify Sub Account 2124 | https://bitgetlimited.github.io/apidoc/en/broker/#modify-sub-account """ 2125 | params = {} 2126 | if subUid and perm and status: 2127 | params["subUid"] = subUid 2128 | params["perm"] = perm 2129 | params["status"] = status 2130 | return self._request_with_params(POST, BROKER_ACCOUNT_V1_URL + '/sub-modify', params) 2131 | else: 2132 | logger.error("pls check args") 2133 | return False 2134 | 2135 | def broker_sub_modify_email(self, subUid, subEmail): 2136 | """ Modify Sub Email 2137 | https://bitgetlimited.github.io/apidoc/en/broker/#modify-sub-email """ 2138 | params = {} 2139 | if subUid and subEmail: 2140 | params["subUid"] = subUid 2141 | params["subEmail"] = subEmail 2142 | return self._request_with_params(POST, BROKER_ACCOUNT_V1_URL + '/sub-modify-email', params) 2143 | else: 2144 | logger.error("pls check args") 2145 | return False 2146 | 2147 | def broker_get_sub_email(self, subUid): 2148 | """ GET Sub Email 2149 | https://bitgetlimited.github.io/apidoc/en/broker/#get-sub-email """ 2150 | params = {} 2151 | if subUid: 2152 | params["subUid"] = subUid 2153 | return self._request_with_params(GET, BROKER_ACCOUNT_V1_URL + '/sub-email', params) 2154 | else: 2155 | logger.error("pls check args") 2156 | return False 2157 | 2158 | def broker_get_sub_spot_assets(self, subUid): 2159 | """ Get Sub Spot Assets 2160 | https://bitgetlimited.github.io/apidoc/en/broker/#get-sub-spot-assets """ 2161 | params = {} 2162 | if subUid: 2163 | params["subUid"] = subUid 2164 | return self._request_with_params(GET, BROKER_ACCOUNT_V1_URL + '/sub-spot-assets', params) 2165 | else: 2166 | logger.error("pls check args") 2167 | return False 2168 | 2169 | def broker_get_sub_future_assets(self, subUid, productType): 2170 | """ Get Sub Future Assets 2171 | https://bitgetlimited.github.io/apidoc/en/broker/#get-sub-future-assets """ 2172 | params = {} 2173 | if subUid and productType: 2174 | params["subUid"] = subUid 2175 | params["productType"] = productType 2176 | return self._request_with_params(GET, BROKER_ACCOUNT_V1_URL + '/sub-future-assets', params) 2177 | else: 2178 | logger.error("pls check args") 2179 | return False 2180 | 2181 | def broker_get_sub_deposit_address(self, subUid, coin, chain=None): 2182 | """ Get Sub Deposit Address (Only Broker) 2183 | https://bitgetlimited.github.io/apidoc/en/broker/#get-sub-deposit-address-only-broker """ 2184 | params = {} 2185 | if subUid and coin: 2186 | params["subUid"] = subUid 2187 | params["coin"] = coin 2188 | if chain is not None: 2189 | params["chain"] = chain 2190 | if self.verbose: 2191 | logger.warning("***Warning*** This endpoint's worked on POST") 2192 | return self._request_with_params(POST, BROKER_ACCOUNT_V1_URL + '/sub-address', params) 2193 | else: 2194 | logger.error("pls check args") 2195 | return False 2196 | 2197 | def broker_sub_withdrawal(self, subUid, coin, address, chain, amount, 2198 | tag=None, clientOrderId=None, remark=None): 2199 | """ Sub Withdrawal (Only Broker) 2200 | https://bitgetlimited.github.io/apidoc/en/broker/#sub-withdrawal-only-broker """ 2201 | params = {} 2202 | if subUid and coin and chain and address and amount: 2203 | params["subUid"] = subUid 2204 | params["coin"] = coin 2205 | params["chain"] = chain 2206 | params["address"] = address 2207 | params["amount"] = amount 2208 | if tag is not None: 2209 | params["tag"] = tag 2210 | if remark is not None: 2211 | params["remark"] = remark 2212 | if clientOrderId is not None: 2213 | params["clientOid"] = clientOrderId 2214 | return self._request_with_params(POST, BROKER_ACCOUNT_V1_URL + '/sub-withdrawal', params) 2215 | else: 2216 | logger.error("pls check args") 2217 | return False 2218 | 2219 | def broker_sub_auto_transfer(self, subUid, coin, toAccountType): 2220 | """ Sub Deposit Auto Transfer (Only Broker) 2221 | https://bitgetlimited.github.io/apidoc/en/broker/#sub-deposit-auto-transfer-only-broker """ 2222 | params = {} 2223 | if subUid and coin and toAccountType: 2224 | params["subUid"] = subUid 2225 | params["coin"] = coin 2226 | params["toAccountType"] = toAccountType 2227 | return self._request_with_params(POST, BROKER_ACCOUNT_V1_URL + '/sub-auto-transfer', params) 2228 | else: 2229 | logger.error("pls check args") 2230 | return False 2231 | -------------------------------------------------------------------------------- /pybitget/enums.py: -------------------------------------------------------------------------------- 1 | # http header 2 | CONTENT_TYPE = 'Content-Type' 3 | ACCESS_KEY = 'ACCESS-KEY' 4 | ACCESS_SIGN = 'ACCESS-SIGN' 5 | ACCESS_TIMESTAMP = 'ACCESS-TIMESTAMP' 6 | ACCESS_PASSPHRASE = 'ACCESS-PASSPHRASE' 7 | APPLICATION_JSON = 'application/json' 8 | 9 | # header key 10 | ACEEPT = 'Accept' 11 | COOKIE = 'Cookie' 12 | LOCALE = 'locale=' 13 | 14 | # method 15 | GET = "GET" 16 | POST = "POST" 17 | DELETE = "DELETE" 18 | 19 | # Base Url 20 | API_URL = 'https://api.bitget.com' 21 | 22 | # ws Url 23 | CONTRACT_WS_URL = 'wss://ws.bitget.com/mix/v1/stream' 24 | 25 | # ######################################## 26 | # ##############【spot url】############### 27 | # ######################################## 28 | 29 | SPOT_PUBLIC_V1_URL = '/api/spot/v1/public' 30 | SPOT_MARKET_V1_URL = '/api/spot/v1/market' 31 | SPOT_ACCOUNT_V1_URL = '/api/spot/v1/account' 32 | SPOT_ORDER_V1_URL = '/api/spot/v1/trade' 33 | SPOT_WALLET_V1_URL = '/api/spot/v1/wallet' 34 | SPOT_PLAN_V1_URL = '/api/spot/v1/plan' 35 | 36 | # ######################################## 37 | # ##############【mix url】################ 38 | # ######################################## 39 | 40 | MIX_MARKET_V1_URL = '/api/mix/v1/market' 41 | MIX_ACCOUNT_V1_URL = '/api/mix/v1/account' 42 | MIX_POSITION_V1_URL = '/api/mix/v1/position' 43 | MIX_ORDER_V1_URL = '/api/mix/v1/order' 44 | MIX_PLAN_V1_URL = '/api/mix/v1/plan' 45 | MIX_TRACE_V1_URL = '/api/mix/v1/trace' 46 | 47 | BROKER_ACCOUNT_V1_URL = '/api/broker/v1/account' 48 | BROKER_MANAGE_V1_URL = '/api/broker/v1/manage' 49 | 50 | SUBSCRIBE = 'subscribe' 51 | UNSUBSCRIBE = 'unsubscribe' 52 | LOGIN = 'login' 53 | 54 | REQUEST_PATH = '/user/verify' 55 | 56 | SERVER_TIMESTAMP_URL = '/api/spot/v1/public/time' 57 | 58 | # SIDE - Order direction 59 | NEW_BUY = "open_long" 60 | NEW_SELL = "open_short" 61 | BUY_CLOSE = 'close_long' 62 | SELL_CLOSE = 'close_short' 63 | PS_BUY = "long" 64 | PS_SELL = "short" 65 | 66 | # orderType 67 | ORDER_TYPES = ['limit', 'market'] 68 | ORDER_TYPE_LIMIT = 'limit' 69 | ORDER_TYPE_MARKET = 'market' 70 | ORDER_SIDES = ['long', 'short'] 71 | 72 | 73 | # orderStatus - state 74 | ORDER_STATUS_OP = ['new'] 75 | ORDER_STATUS_NEW = 'new' 76 | ORDER_STATUS_CANCELED = 'canceled' 77 | ORDER_STATUS_FILLED = 'filled' 78 | ORDER_STATUS_FILLEDs = ['partially_filled', 'filled'] 79 | ORDER_STATUS_TYPES = ['init', 'new', 'partially_filled', 'filled', 'canceled'] 80 | 81 | # stopType 82 | STOP_TYPES = ['profit', 'loss'] 83 | STOP_TYPE_PROFIT = "profit" 84 | STOP_TYPE_LOSS = "loss" 85 | 86 | # timeInForceValue 87 | TIME_IN_FORCE_TYPES = ['normal', 'post_only', 'fok', 'ioc'] 88 | # triggerType 89 | TRIGGER_TYPES = ['fill_price', 'market_price'] 90 | 91 | # planType 92 | PLAN_TYPES = ['profit_plan', 'loss_plan', 'normal_plan', 'pos_profit', 'pos_loss', 'moving_plan', 'track_plan'] 93 | 94 | # planStatus 95 | PLAN_STATUS_NOT_TRIGGER = "not_trigger" 96 | PLAN_STATUS_TRIGGERED = "triggered" 97 | PLAN_STATUS_FAIL_TRIGGER = "fail_trigger" 98 | PLAN_STATUS_CANCEL = "cancel" 99 | PLAN_TYPE_POS_PROFIT = "pos_profit" 100 | PLAN_TYPE_POS_LOSS = "pos_loss" 101 | 102 | # isPlan 103 | IS_PLAN_TYPES = ['plan', 'profit_loss'] 104 | # Plan 105 | isPlan_plan = "plan" 106 | isPlan_profit_loss = "profit_loss" 107 | 108 | 109 | # symbolStatus 110 | SYMBOL_STATUS_TYPES = ['normal', 'maintain', 'off'] 111 | 112 | 113 | PRODUCT_TYPE_UMCBL = 'umcbl' 114 | PRODUCT_TYPE_SUMCBL = 'sumcbl' # demo ? 115 | MARGIN_COIN_USDT = 'USDT' 116 | MARGIN_COIN_USDC = 'USDC' 117 | MARGIN_COIN_SUSDT = 'SUSDT' # demo? 118 | # Websocket planType 119 | WS_PLAN_TYPES = ['pl', 'tp', 'sl', 'ptp', 'psl'] 120 | 121 | # Websocket channels type 122 | WS_PRIVATE_ACCOUNT_CHANNEL = "account" 123 | WS_PRIVATE_ORDERS_CHANNEL = "orders" 124 | WS_PRIVATE_POSITIONS_CHANNEL = "positions" 125 | WS_PRIVATE_PLAN_ORDERS_CHANNEL = "ordersAlgo" 126 | WS_CHANNEL_INSTTYPE = "UMCBL" 127 | WS_CHANNEL_INSTID = "default" 128 | 129 | 130 | # === API define fields name 131 | ORDER_STATUS = "state" 132 | ORDER_TYPE_NAME = "orderType" 133 | STOP_PRICE_FIELD = "triggerPrice" 134 | -------------------------------------------------------------------------------- /pybitget/exceptions.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | import json 3 | 4 | 5 | class BitgetAPIException(Exception): 6 | 7 | def __init__(self, response): 8 | self.code = 0 9 | try: 10 | json_res = response.json() 11 | except ValueError: 12 | self.message = 'Invalid JSON error message from Bitget: {}'.format(response.text) 13 | else: 14 | if "code" in json_res.keys() and "msg" in json_res.keys(): 15 | self.code = json_res['code'] 16 | self.message = json_res['msg'] 17 | 18 | self.status_code = response.status_code 19 | self.response = response 20 | self.request = getattr(response, 'request', None) 21 | 22 | def __str__(self): # pragma: no cover 23 | return 'API Request Error(code=%s): %s' % (self.code, self.message) 24 | 25 | 26 | class BitgetRequestException(Exception): 27 | 28 | def __init__(self, message): 29 | self.message = message 30 | 31 | def __str__(self): 32 | return 'BitgetRequestException: %s' % self.message 33 | 34 | 35 | class BitgetParamsException(Exception): 36 | 37 | def __init__(self, message): 38 | self.message = message 39 | 40 | def __str__(self): 41 | return 'BitgetParamsException: %s' % self.message 42 | 43 | -------------------------------------------------------------------------------- /pybitget/stream.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | import json 3 | import math 4 | import threading 5 | import time 6 | import traceback 7 | from threading import Timer 8 | from zlib import crc32 9 | import hmac 10 | import base64 11 | 12 | import websocket 13 | from typing import Optional 14 | from pybitget.enums import GET, REQUEST_PATH, CONTRACT_WS_URL 15 | from pybitget import logger 16 | 17 | WS_OP_LOGIN = 'login' 18 | WS_OP_SUBSCRIBE = "subscribe" 19 | WS_OP_UNSUBSCRIBE = "unsubscribe" 20 | 21 | 22 | def handle(message): 23 | logger.info(message) 24 | 25 | 26 | def handel_error(message): 27 | logger.error(message) 28 | 29 | 30 | def create_sign(message, secret_key): 31 | mac = hmac.new(bytes(secret_key, encoding='utf8'), bytes(message, encoding='utf-8'), digestmod='sha256') 32 | d = mac.digest() 33 | return str(base64.b64encode(d), 'utf8') 34 | 35 | 36 | def pre_hash(timestamp, method, request_path): 37 | return str(timestamp) + str.upper(method) + str(request_path) 38 | 39 | 40 | class BitgetWsClient: 41 | def __init__(self, 42 | api_key: Optional[str] = None, 43 | api_secret: Optional[str] = None, 44 | passphrase: Optional[str] = None, 45 | ws_url: Optional[str] = None, 46 | verbose: Optional[str] = False, 47 | ): 48 | self.__api_key = api_key 49 | self.__api_secret_key = api_secret 50 | self.__passphrase = passphrase 51 | self.__connection = False 52 | self.__login_status = False 53 | self.__reconnect_status = False 54 | self.__all_suribe = set() 55 | self.__listener = handle 56 | self.__error_listener = handel_error 57 | self.__scribe_map = {} 58 | self.__allbooks_map = {} 59 | self.__ws_client = None 60 | 61 | if ws_url is None: 62 | self.STREAM_URL = CONTRACT_WS_URL 63 | else: 64 | self.STREAM_URL = ws_url 65 | self.verbose = verbose 66 | 67 | def build(self): 68 | self.__ws_client = self.__init_client() 69 | __thread = threading.Thread(target=self.connect) 70 | __thread.start() 71 | 72 | while not self.has_connect(): 73 | logger.info("start connecting...%s" % self.STREAM_URL) 74 | time.sleep(1) 75 | 76 | if self.__api_key is not None and self.__api_secret_key is not None and self.__passphrase is not None: 77 | self.__login() 78 | 79 | self.__keep_connected(25) 80 | 81 | return self 82 | 83 | def listener(self, listener): 84 | self.__listener = listener 85 | return self 86 | 87 | def error_listener(self, error_listener): 88 | self.__error_listener = error_listener 89 | return self 90 | 91 | def has_connect(self): 92 | return self.__connection 93 | 94 | def __init_client(self): 95 | try: 96 | return websocket.WebSocketApp(self.STREAM_URL, 97 | on_open=self.__on_open, 98 | on_message=self.__on_message, 99 | on_error=self.__on_error, 100 | on_close=self.__on_close) 101 | 102 | except Exception as ex: 103 | logger.error(ex) 104 | 105 | def __login(self): 106 | timestamp = int(round(time.time())) 107 | sign = create_sign(pre_hash(timestamp, GET, REQUEST_PATH), self.__api_secret_key) 108 | ws_login_req = WsLoginReq(self.__api_key, self.__passphrase, str(timestamp), sign) 109 | self.send_message(WS_OP_LOGIN, [ws_login_req]) 110 | logger.info("logging in......") 111 | while not self.__login_status: 112 | time.sleep(1) 113 | 114 | def connect(self): 115 | try: 116 | self.__ws_client.run_forever(ping_timeout=10) 117 | except Exception as ex: 118 | logger.error(ex) 119 | 120 | def __keep_connected(self, interval): 121 | try: 122 | __timer_thread = Timer(interval, self.__keep_connected, (interval,)) 123 | __timer_thread.start() 124 | self.__ws_client.send("ping") 125 | except Exception as ex: 126 | logger.error(ex) 127 | 128 | def send_message(self, op, args): 129 | message = json.dumps(BaseWsReq(op, args), default=lambda o: o.__dict__) 130 | if self.verbose: 131 | logger.debug(message) 132 | self.__ws_client.send(message) 133 | 134 | def subscribe(self, channels, listener=None): 135 | 136 | if listener: 137 | for chanel in channels: 138 | chanel.inst_type = str(chanel.inst_type).lower() 139 | self.__scribe_map[chanel] = listener 140 | 141 | for channel in channels: 142 | self.__all_suribe.add(channel) 143 | 144 | self.send_message(WS_OP_SUBSCRIBE, channels) 145 | 146 | def unsubscribe(self, channels): 147 | try: 148 | for channel in channels: 149 | if channel in self.__scribe_map: 150 | del self.__scribe_map[channel] 151 | 152 | for channel in channels: 153 | if channel in self.__all_suribe: 154 | self.__all_suribe.remove(channel) 155 | 156 | self.send_message(WS_OP_UNSUBSCRIBE, channels) 157 | except Exception as e: 158 | logger.error(e) 159 | pass 160 | 161 | def __on_open(self, ws): 162 | logger.info('connection is success....') 163 | self.__connection = True 164 | self.__reconnect_status = False 165 | 166 | def __on_message(self, ws, message): 167 | 168 | if message == 'pong': 169 | # if self.verbose: 170 | # logger.info("Keep connected: %s" % message) 171 | return 172 | json_obj = json.loads(message) 173 | if "code" in json_obj and json_obj.get("code") != 0: 174 | if self.__error_listener: 175 | self.__error_listener(message) 176 | return 177 | 178 | if "event" in json_obj and json_obj.get("event") == "login": 179 | if self.verbose: 180 | logger.debug("login msg: %s" % message) 181 | self.__login_status = True 182 | return 183 | listenner = None 184 | if "data" in json_obj: 185 | if not self.__check_sum(json_obj): 186 | return 187 | 188 | listenner = self.get_listener(json_obj) 189 | 190 | if listenner: 191 | listenner(message) 192 | return 193 | 194 | self.__listener(message) 195 | 196 | def __dict_books_info(self, a_dict): 197 | return BooksInfo(a_dict['asks'], a_dict['bids'], a_dict['checksum']) 198 | 199 | def __dict_to_subscribe_req(self, a_dict): 200 | return SubscribeReq(a_dict['instType'], a_dict['channel'], a_dict['instId']) 201 | 202 | def get_listener(self, json_obj): 203 | try: 204 | if json_obj.get('arg'): 205 | json_str = str(json_obj.get('arg')).replace("\'", "\"") 206 | subscribe_req = json.loads(json_str, object_hook=self.__dict_to_subscribe_req) 207 | return self.__scribe_map.get(subscribe_req) 208 | except Exception as e: 209 | logger.error("%s %s " % (json_obj.get('arg'), e)) 210 | pass 211 | 212 | def __on_error(self, ws, msg): 213 | logger.error(msg) 214 | self.__close() 215 | if not self.__reconnect_status: 216 | self.__re_connect() 217 | 218 | def __on_close(self, ws, close_status_code, close_msg): 219 | logger.info("ws is closeing ......close_status:{},close_msg:{}".format(close_status_code, close_msg)) 220 | self.__close() 221 | if not self.__reconnect_status: 222 | self.__re_connect() 223 | 224 | def __re_connect(self): 225 | self.__reconnect_status = True 226 | logger.info("start reconnection ...") 227 | self.build() 228 | for channel in self.__all_suribe: 229 | self.subscribe([channel]) 230 | pass 231 | 232 | def __close(self): 233 | self.__login_status = False 234 | self.__connection = False 235 | self.__ws_client.close() 236 | 237 | def __check_sum(self, json_obj): 238 | # noinspection PyBroadException 239 | try: 240 | if "arg" not in json_obj or "action" not in json_obj: 241 | return True 242 | arg = str(json_obj.get('arg')).replace("\'", "\"") 243 | action = str(json_obj.get('action')).replace("\'", "\"") 244 | data = str(json_obj.get('data')).replace("\'", "\"") 245 | 246 | subscribe_req = json.loads(arg, object_hook=self.__dict_to_subscribe_req) 247 | 248 | if subscribe_req.channel != "books": 249 | return True 250 | 251 | books_info = json.loads(data, object_hook=self.__dict_books_info)[0] 252 | 253 | if action == "snapshot": 254 | self.__allbooks_map[subscribe_req] = books_info 255 | return True 256 | if action == "update": 257 | all_books = self.__allbooks_map[subscribe_req] 258 | if all_books is None: 259 | return False 260 | 261 | all_books = all_books.merge(books_info) 262 | check_sum = all_books.check_sum(books_info.checksum) 263 | if not check_sum: 264 | self.unsubscribe([subscribe_req]) 265 | self.subscribe([subscribe_req]) 266 | return False 267 | self.__allbooks_map[subscribe_req] = all_books 268 | except Exception as e: 269 | msg = traceback.format_exc() 270 | logger.error("%s %s" % (msg, e)) 271 | 272 | return True 273 | 274 | 275 | class BooksInfo: 276 | def __init__(self, asks, bids, checksum): 277 | self.asks = asks 278 | self.bids = bids 279 | self.checksum = checksum 280 | 281 | def merge(self, book_info): 282 | self.asks = self.innerMerge(self.asks, book_info.asks, False) 283 | self.bids = self.innerMerge(self.bids, book_info.bids, True) 284 | return self 285 | 286 | def innerMerge(self, all_list, update_list, is_reverse): 287 | price_and_value = {} 288 | for v in all_list: 289 | price_and_value[v[0]] = v 290 | 291 | for v in update_list: 292 | if v[1] == "0": 293 | del price_and_value[v[0]] 294 | continue 295 | price_and_value[v[0]] = v 296 | 297 | keys = sorted(price_and_value.keys(), reverse=is_reverse) 298 | 299 | result = [] 300 | 301 | for i in keys: 302 | result.append(price_and_value[i]) 303 | 304 | return result 305 | 306 | def check_sum(self, new_check_sum): 307 | crc32str = '' 308 | for x in range(25): 309 | if self.bids[x] is not None: 310 | crc32str = crc32str + self.bids[x][0] + ":" + self.bids[x][1] + ":" 311 | 312 | if self.asks[x] is not None: 313 | crc32str = crc32str + self.asks[x][0] + ":" + self.asks[x][1] + ":" 314 | 315 | crc32str = crc32str[0:len(crc32str) - 1] 316 | # logger.debug(crc32str) 317 | merge_num = crc32(bytes(crc32str, encoding="utf8")) 318 | # print("start checknum mergeVal:" + str(merge_num) + ",checkVal:" + str(new_check_sum) + ",checkSin:" + str(self.__signed_int(merge_num))) 319 | return self.__signed_int(merge_num) == new_check_sum 320 | 321 | def __signed_int(self, checknum): 322 | int_max = math.pow(2, 31) - 1 323 | if checknum > int_max: 324 | return checknum - int_max * 2 - 2 325 | return checknum 326 | 327 | 328 | class SubscribeReq: 329 | 330 | def __init__(self, inst_type, channel, instId): 331 | self.inst_type = inst_type 332 | self.channel = channel 333 | self.inst_id = instId 334 | 335 | def __eq__(self, other) -> bool: 336 | return self.__dict__ == other.__dict__ 337 | 338 | def __hash__(self) -> int: 339 | return hash(self.inst_type + self.channel + self.inst_id) 340 | 341 | 342 | class BaseWsReq: 343 | 344 | def __init__(self, op, args): 345 | self.op = op 346 | self.args = args 347 | 348 | 349 | class WsLoginReq: 350 | 351 | def __init__(self, api_key, passphrase, timestamp, sign): 352 | self.api_key = api_key 353 | self.passphrase = passphrase 354 | self.timestamp = timestamp 355 | self.sign = sign 356 | -------------------------------------------------------------------------------- /pybitget/utils.py: -------------------------------------------------------------------------------- 1 | import hmac 2 | import base64 3 | import time 4 | from .enums import * 5 | import string 6 | import random 7 | 8 | def sign(message, secret_key): 9 | mac = hmac.new(bytes(secret_key, encoding='utf8'), bytes(message, encoding='utf-8'), digestmod='sha256') 10 | d = mac.digest() 11 | return base64.b64encode(d) 12 | 13 | 14 | def pre_hash(timestamp, method, request_path, body): 15 | return str(timestamp) + str.upper(method) + request_path + body 16 | 17 | 18 | def get_header(api_key, a_sign, timestamp, passphrase): 19 | header = dict() 20 | header[CONTENT_TYPE] = APPLICATION_JSON 21 | header[ACCESS_KEY] = api_key 22 | header[ACCESS_SIGN] = a_sign 23 | header[ACCESS_TIMESTAMP] = str(timestamp) 24 | header[ACCESS_PASSPHRASE] = passphrase 25 | 26 | return header 27 | 28 | 29 | def parse_params_to_str(params): 30 | url = '?' 31 | for key, value in params.items(): 32 | url = url + str(key) + '=' + str(value) + '&' 33 | 34 | return url[0:-1] 35 | 36 | 37 | def get_timestamp(): 38 | return int(time.time() * 1000) 39 | 40 | 41 | def signature(timestamp, method, request_path, body, secret_key): 42 | if str(body) == '{}' or str(body) == 'None': 43 | body = '' 44 | message = str(timestamp) + str.upper(method) + request_path + str(body) 45 | mac = hmac.new(bytes(secret_key, encoding='utf8'), bytes(message, encoding='utf-8'), digestmod='sha256') 46 | d = mac.digest() 47 | return base64.b64encode(d) 48 | 49 | 50 | def id_random(size=3, chars=string.ascii_uppercase + string.digits): 51 | return ''.join(random.choice(chars) for _ in range(size)) 52 | 53 | 54 | def random_string(keyword=None, length=15): 55 | if keyword is None: 56 | keyword = 'Cuongitl' 57 | return "{}_{}".format(keyword, id_random(length).lower()) 58 | -------------------------------------------------------------------------------- /release_notes.md: -------------------------------------------------------------------------------- 1 | # python-bitget 2 | 3 | [Bitget](https://www.bitget.com/en/referral/register?from=referral&clacCode=6EKP94LE) 4 | python wrapper with rest API, websocket API. 5 | 6 | 7 | # Release notes 8 | * Version 1.0.8 - 08 July 2024. 9 | * [x] [Get History Candle Data](https://bitgetlimited.github.io/apidoc/en/mix/#get-history-candle-data) 10 | * Version 1.0.7 - Fix bug. 11 | * Version 1.0.6 - Fix bug. 12 | * Version 1.0.5 - 02 Feb 2023. 13 | * Fixed bug [#5](https://github.com/cuongitl/python-bitget/issues/5) 14 | * Version 1.0.4 - 30 Jan 2023. 15 | * Full support for all api-endpoint: spot/mix/broker 16 | * Update some functions by [Bitget Update log](https://bitgetlimited.github.io/apidoc/en/mix/#update-log) 17 | * Version 1.0.3 - 29 Jan 2023. 18 | * Full support for all mix-endpoints. 19 | * Version 1.0.2 - 29 Jan 2023. 20 | * Full support mix-endpoints: market, account 21 | * [x] [Get Depth](https://bitgetlimited.github.io/apidoc/en/mix/#get-depth) 22 | * [x] [Get Single Symbol Ticker](https://bitgetlimited.github.io/apidoc/en/mix/#get-single-symbol-ticker) 23 | * [x] [Get All Symbol Ticker](https://bitgetlimited.github.io/apidoc/en/mix/#get-all-symbol-ticker) 24 | * [x] [Get Candle Data](https://bitgetlimited.github.io/apidoc/en/mix/#get-candle-data) 25 | * [x] [Get Symbol Index Price](https://bitgetlimited.github.io/apidoc/en/mix/#get-symbol-index-price) 26 | * [x] [Get Symbol Next Funding Time](https://bitgetlimited.github.io/apidoc/en/mix/#get-symbol-next-funding-time) 27 | * [x] [Get History Funding Rate](https://bitgetlimited.github.io/apidoc/en/mix/#get-history-funding-rate) 28 | * [x] [Get Current Funding Rate](https://bitgetlimited.github.io/apidoc/en/mix/#get-current-funding-rate) 29 | * [x] [Get sub Account Contract Assets](https://bitgetlimited.github.io/apidoc/en/mix/#get-sub-account-contract-assets) 30 | * [x] [Get Open Count](https://bitgetlimited.github.io/apidoc/en/mix/#get-open-count) 31 | * [x] [Change Margin](https://bitgetlimited.github.io/apidoc/en/mix/#change-margin) 32 | * [x] [Change Hold Mode](https://bitgetlimited.github.io/apidoc/en/mix/#change-hold-mode) 33 | * [x] [Get Account Bill](https://bitgetlimited.github.io/apidoc/en/mix/#get-account-bill) 34 | * [x] [Get Business Account Bill](https://bitgetlimited.github.io/apidoc/en/mix/#get-business-account-bill) 35 | 36 | * Version 1.0.1 - 28 Jan 2023. 37 | * Add some examples 38 | * Version 1.0.0 - 27 Jan 2023. Supported: 39 | * [x] [Get Symbol Mark Price](https://bitgetlimited.github.io/apidoc/en/mix/#get-symbol-mark-price) 40 | * [x] [Get All Symbols](https://bitgetlimited.github.io/apidoc/en/mix/#get-all-symbols) 41 | * [x] [Get Single Account](https://bitgetlimited.github.io/apidoc/en/mix/#get-single-account) 42 | * [x] [Get Account List](https://bitgetlimited.github.io/apidoc/en/mix/#get-account-list) 43 | * [x] [Get Symbol Leverage](https://bitgetlimited.github.io/apidoc/en/mix/#get-symbol-leverage) 44 | * [x] [Get Symbol Position](https://bitgetlimited.github.io/apidoc/en/mix/#get-symbol-position) 45 | * [x] [Get All Position](https://bitgetlimited.github.io/apidoc/en/mix/#get-all-position) 46 | * [x] [Get Open Order](https://bitgetlimited.github.io/apidoc/en/mix/#get-open-order) 47 | * [x] [Get All Open Order](https://bitgetlimited.github.io/apidoc/en/mix/#get-all-open-order) 48 | * [x] [Get Plan Order (TPSL) List](https://bitgetlimited.github.io/apidoc/en/mix/#get-plan-order-tpsl-list) 49 | * [x] [Get Fills](https://bitgetlimited.github.io/apidoc/en/mix/#get-fills) 50 | * [x] [Get History Orders](https://bitgetlimited.github.io/apidoc/en/mix/#get-history-orders) 51 | * [x] [Get ProductType History Orders](https://bitgetlimited.github.io/apidoc/en/mix/#get-producttype-history-orders) 52 | * [x] [Change Leverage](https://bitgetlimited.github.io/apidoc/en/mix/#change-leverage) 53 | * [x] [Change Margin Mode](https://bitgetlimited.github.io/apidoc/en/mix/#change-margin-mode) 54 | * [x] [Place Order](https://bitgetlimited.github.io/apidoc/en/mix/#place-order) 55 | * [x] [Cancel All Order](https://bitgetlimited.github.io/apidoc/en/mix/#cancel-all-order) 56 | * [x] [Cancel Order](https://bitgetlimited.github.io/apidoc/en/mix/#cancel-order) 57 | * [x] [Cancel Plan Order (TPSL)](https://bitgetlimited.github.io/apidoc/en/mix/#cancel-plan-order-tpsl) 58 | * [x] [Place Position TPSL](https://bitgetlimited.github.io/apidoc/en/mix/#place-position-tpsl) --------------------------------------------------------------------------------