GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — ccxt/python/ccxt/blofin.py at master · ccxt/ccxt Expand file tree/ Copy pathblofin.pyMore file actions 3540 lines (3376 loc) · 169 KB / Copy pathblofin.pyFile metadata and controls3540 lines (3376 loc) · 169 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 # -*- coding: utf-8 -*- # PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN: # https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code from ccxt.base.exchange import Exchange from ccxt.abstract.blofin import ImplicitAPI import hashlib from ccxt.base.types import ADL, Balances, Currencies, Currency, CurrencyInterface, DepositAddress, Int, LedgerEntry, Leverage, Leverages, LeverageTier, MarginMode, Market, Num, Order, OrderBook, OrderRequest, OrderSide, OrderType, Position, PositionModeInfo, Str, Strings, Ticker, Tickers, FundingRate, Trade, TradingFeeInterface, DepositWithdrawFees, Transaction, FundingRateHistory, TransferEntry from ccxt.base.errors import ExchangeError from ccxt.base.errors import AuthenticationError from ccxt.base.errors import PermissionDenied from ccxt.base.errors import ArgumentsRequired from ccxt.base.errors import BadRequest from ccxt.base.errors import InsufficientFunds from ccxt.base.errors import InvalidAddress from ccxt.base.errors import InvalidOrder from ccxt.base.errors import OrderNotFound from ccxt.base.errors import DuplicateOrderId from ccxt.base.errors import RateLimitExceeded from ccxt.base.errors import ExchangeNotAvailable from ccxt.base.errors import InvalidNonce from ccxt.base.errors import NullResponse from ccxt.base.decimal_to_precision import TICK_SIZE from ccxt.base.precise import Precise class blofin(Exchange, ImplicitAPI): def describe(self) -> dict: return self.deep_extend(super(blofin, self).describe(), { 'id': 'blofin', 'name': 'BloFin', 'countries': ['MH'], # Marshall Islands 'version': 'v1', 'rateLimit': 200, # 1500 requests per 5 minutes per IP is the binding budget => 200ms per request (500/min allows 120ms, but 1500/5min does not) 'pro': True, 'has': { 'CORS': None, 'spot': False, 'margin': False, 'swap': True, 'future': False, 'option': False, 'addMargin': False, 'borrowMargin': False, 'cancelAllOrders': False, 'cancelOrder': True, 'cancelOrders': True, 'closeAllPositions': False, 'closePosition': True, 'createDepositAddress': False, 'createMarketBuyOrderWithCost': False, 'createMarketSellOrderWithCost': False, 'createOrder': True, 'createOrders': True, 'createOrderWithTakeProfitAndStopLoss': True, 'createPostOnlyOrder': False, 'createReduceOnlyOrder': False, 'createStopLimitOrder': False, 'createStopLossOrder': True, 'createStopMarketOrder': False, 'createStopOrder': False, 'createTakeProfitOrder': True, 'createTriggerOrder': True, 'editOrder': True, 'fetchAccounts': False, 'fetchBalance': True, 'fetchBidsAsks': None, 'fetchBorrowInterest': False, 'fetchBorrowRateHistories': False, 'fetchBorrowRateHistory': False, 'fetchCanceledOrders': False, 'fetchClosedOrder': False, 'fetchClosedOrders': True, 'fetchCrossBorrowRate': False, 'fetchCrossBorrowRates': False, 'fetchCurrencies': True, 'fetchDeposit': True, 'fetchDepositAddress': True, 'fetchDepositAddresses': False, 'fetchDepositAddressesByNetwork': False, 'fetchDeposits': True, 'fetchDepositsWithdrawals': False, 'fetchDepositWithdrawFee': 'emulated', 'fetchDepositWithdrawFees': True, 'fetchFundingHistory': True, 'fetchFundingRate': True, 'fetchFundingRateHistory': True, 'fetchFundingRates': False, 'fetchGreeks': False, 'fetchIndexOHLCV': False, 'fetchIsolatedBorrowRate': False, 'fetchIsolatedBorrowRates': False, 'fetchL3OrderBook': False, 'fetchLedger': True, 'fetchLedgerEntry': None, 'fetchLeverage': True, 'fetchLeverages': True, 'fetchLeverageTiers': False, 'fetchMarginMode': True, 'fetchMarginModes': False, 'fetchMarketLeverageTiers': True, 'fetchMarkets': True, 'fetchMarkOHLCV': False, 'fetchMySettlementHistory': False, 'fetchMyTrades': True, 'fetchOHLCV': True, 'fetchOpenInterest': False, 'fetchOpenInterestHistory': False, 'fetchOpenOrder': None, 'fetchOpenOrders': True, 'fetchOrder': True, 'fetchOrderBook': True, 'fetchOrderBooks': False, 'fetchOrders': False, 'fetchOrderTrades': True, 'fetchPosition': True, 'fetchPositionADLRank': True, 'fetchPositionMode': True, 'fetchPositions': True, 'fetchPositionsADLRank': True, 'fetchPositionsForSymbol': False, 'fetchPositionsHistory': True, 'fetchPositionsRisk': False, 'fetchPremiumIndexOHLCV': False, 'fetchSettlementHistory': False, 'fetchStatus': False, 'fetchTicker': True, 'fetchTickers': True, 'fetchTime': False, 'fetchTrades': True, 'fetchTradingFee': False, 'fetchTradingFees': False, 'fetchTradingLimits': False, 'fetchTransactionFee': False, 'fetchTransactionFees': False, 'fetchTransactions': False, 'fetchTransfer': False, 'fetchTransfers': False, 'fetchUnderlyingAssets': False, 'fetchVolatilityHistory': False, 'fetchWithdrawal': True, 'fetchWithdrawals': True, 'fetchWithdrawalWhitelist': False, 'reduceMargin': False, 'repayCrossMargin': False, 'setLeverage': True, 'setMargin': False, 'setMarginMode': True, 'setPositionMode': True, 'signIn': False, 'transfer': True, 'withdraw': True, }, 'timeframes': { '1m': '1m', '3m': '3m', '5m': '5m', '15m': '15m', '30m': '30m', '1h': '1H', '2h': '2H', '4h': '4H', '6h': '6H', '8h': '8H', '12h': '12H', '1d': '1D', '3d': '3D', '1w': '1W', '1M': '1M', }, 'urls': { 'logo': 'https://github.com/user-attachments/assets/67edf117-6217-4cb8-95e7-9b03f314b1b1', 'api': { 'rest': 'https://openapi.blofin.com', }, 'test': { 'rest': 'https://demo-trading-openapi.blofin.com', }, 'referral': { 'url': 'https://blofin.com/register?referral_code=f79EsS', 'discount': 0.05, }, 'www': 'https://www.blofin.com', 'doc': 'https://blofin.com/docs', }, 'api': { 'public': { 'get': { 'market/instruments': {'cost': 1}, 'market/instruments-history': {'cost': 1}, 'market/tickers': {'cost': 1}, 'market/books': {'cost': 1}, 'market/trades': {'cost': 1}, 'market/mark-price': {'cost': 1}, 'market/funding-rate': {'cost': 1}, 'market/funding-rate-history': {'cost': 1}, 'market/candles': {'cost': 1}, 'market/index-candles': {'cost': 1}, 'market/mark-price-candles': {'cost': 1}, 'market/position-tiers': {'cost': 1}, # spot 'spot/market/instruments': {'cost': 1}, 'spot/market/tickers': {'cost': 1}, 'spot/market/books': {'cost': 1}, 'spot/market/trades': {'cost': 1}, 'spot/market/candles': {'cost': 1}, }, }, 'private': { 'get': { # account 'asset/balances': {'cost': 1}, 'asset/bills': {'cost': 1}, 'asset/withdrawal-history': {'cost': 1}, 'asset/deposit-history': {'cost': 1}, 'asset/deposit-address': {'cost': 1}, 'account/config': {'cost': 1}, 'asset/currencies': {'cost': 1}, # trading 'account/balance': {'cost': 1}, 'account/positions': {'cost': 1}, 'account/positions-history': {'cost': 1}, 'account/funding-fees': {'cost': 1}, 'account/margin-mode': {'cost': 1}, 'account/position-mode': {'cost': 1}, 'account/leverage-info': {'cost': 1}, 'account/batch-leverage-info': {'cost': 1}, 'trade/orders-pending': {'cost': 1.67}, 'trade/order-detail': {'cost': 1.67}, 'trade/orders-tpsl-pending': {'cost': 1.67}, 'trade/order-tpsl-detail': {'cost': 1.67}, 'trade/orders-algo-pending': {'cost': 1.67}, 'trade/orders-history': {'cost': 1.67}, 'trade/orders-tpsl-history': {'cost': 1.67}, 'trade/orders-algo-history': {'cost': 1.67}, # todo new 'trade/fills-history': {'cost': 1.67}, 'trade/order/price-range': {'cost': 1.67}, # affiliate 'affiliate/basic': {'cost': 1}, 'affiliate/referral-code': {'cost': 1}, 'affiliate/invitees': {'cost': 1}, 'affiliate/sub-invitees': {'cost': 1}, 'affiliate/sub-affiliates': {'cost': 1}, 'affiliate/invitees/daily/info': {'cost': 1}, # copy trading 'copytrading/instruments': {'cost': 1}, 'copytrading/config': {'cost': 1}, 'copytrading/account/balance': {'cost': 1}, 'copytrading/account/positions-by-order': {'cost': 1}, 'copytrading/account/positions-details-by-order': {'cost': 1}, 'copytrading/account/positions-by-contract': {'cost': 1}, 'copytrading/account/position-mode': {'cost': 1}, 'copytrading/account/leverage-info': {'cost': 1}, 'copytrading/trade/orders-pending': {'cost': 1.67}, 'copytrading/trade/pending-tpsl-by-contract': {'cost': 1.67}, 'copytrading/trade/position-history-by-order': {'cost': 1.67}, 'copytrading/trade/orders-history': {'cost': 1.67}, 'copytrading/trade/pending-tpsl-by-order': {'cost': 1.67}, # user 'user/query-apikey': {'cost': 1}, # tax 'spot/trade/fills-history': {'cost': 1}, # spot 'spot/trade/orders-pending': {'cost': 1.67}, 'spot/trade/order-detail': {'cost': 1.67}, 'spot/trade/orders-algo-pending': {'cost': 1.67}, 'spot/trade/orders-history': {'cost': 1.67}, 'spot/trade/orders-algo-history': {'cost': 1.67}, 'spot/trade/order/price-range': {'cost': 1.67}, }, 'post': { # account 'asset/transfer': {'cost': 1}, 'asset/demo-apply-money': {'cost': 1}, 'asset/withdrawal-apply': {'cost': 1}, # trading 'account/set-margin-mode': {'cost': 1.67}, 'account/set-position-mode': {'cost': 1.67}, 'account/set-leverage': {'cost': 1.67}, 'trade/order': {'cost': 1.67}, 'trade/batch-orders': {'cost': 1.67}, 'trade/order-tpsl': {'cost': 1.67}, 'trade/order-algo': {'cost': 1.67}, 'trade/cancel-order': {'cost': 1.67}, 'trade/cancel-batch-orders': {'cost': 1.67}, 'trade/cancel-tpsl': {'cost': 1.67}, 'trade/cancel-algo': {'cost': 1.67}, 'trade/amend-order': {'cost': 1.67}, 'trade/amend-batch-orders': {'cost': 1.67}, 'trade/amend-tpsl': {'cost': 1.67}, 'trade/amend-algo': {'cost': 1.67}, 'trade/close-position': {'cost': 1.67}, # spot 'spot/trade/order': {'cost': 1.67}, 'spot/trade/batch-orders': {'cost': 1.67}, 'spot/trade/order-algo': {'cost': 1.67}, 'spot/trade/cancel-order': {'cost': 1.67}, 'spot/trade/cancel-batch-orders': {'cost': 1.67}, 'spot/trade/cancel-algo': {'cost': 1.67}, # copy trading 'copytrading/account/set-position-mode': {'cost': 1.67}, 'copytrading/account/set-leverage': {'cost': 1.67}, 'copytrading/trade/place-order': {'cost': 1.67}, 'copytrading/trade/cancel-order': {'cost': 1.67}, 'copytrading/trade/place-tpsl-by-contract': {'cost': 1.67}, 'copytrading/trade/cancel-tpsl-by-contract': {'cost': 1.67}, 'copytrading/trade/place-tpsl-by-order': {'cost': 1.67}, 'copytrading/trade/cancel-tpsl-by-order': {'cost': 1.67}, 'copytrading/trade/close-position-by-order': {'cost': 1.67}, 'copytrading/trade/close-position-by-contract': {'cost': 1.67}, }, }, }, 'fees': { 'swap': { 'taker': self.parse_number('0.00060'), 'maker': self.parse_number('0.00020'), }, }, 'requiredCredentials': { 'apiKey': True, 'secret': True, 'password': True, }, 'features': { 'default': { 'sandbox': False, 'createOrder': { 'timeInForce': { 'IOC': True, 'FOK': True, 'PO': True, 'GTD': False, }, 'leverage': False, 'marketBuyRequiresPrice': False, 'marketBuyByCost': False, 'selfTradePrevention': False, 'trailing': False, 'iceberg': False, }, 'createOrders': { 'max': 10, }, 'fetchMyTrades': { 'marginMode': False, 'limit': 100, 'daysBack': 100000, 'untilDays': 100000, 'symbolRequired': False, }, 'fetchOrder': { 'marginMode': False, 'trigger': False, 'trailing': False, 'symbolRequired': True, }, 'fetchOpenOrders': { 'marginMode': False, 'limit': 100, 'trigger': True, 'trailing': False, 'symbolRequired': False, }, 'fetchOrders': None, 'fetchClosedOrders': { 'marginMode': False, 'limit': 1000, 'daysBack': 100000, 'daysBackCanceled': 1, 'untilDays': 100000, 'trigger': True, 'trailing': False, 'symbolRequired': False, }, 'fetchOHLCV': { 'limit': 1440, }, }, 'spot': { 'extends': 'default', 'fetchCurrencies': { 'private': True, }, 'createOrder': { 'marginMode': False, 'triggerPrice': False, 'triggerPriceType': None, 'triggerDirection': False, 'stopLossPrice': False, 'takeProfitPrice': False, 'attachedStopLossTakeProfit': None, 'hedged': False, }, }, 'forDerivatives': { 'extends': 'default', 'createOrder': { 'marginMode': True, 'triggerPrice': False, # todo 'triggerPriceType': None, 'triggerDirection': False, 'stopLossPrice': True, 'takeProfitPrice': True, 'attachedStopLossTakeProfit': { 'triggerPriceType': None, 'price': True, }, 'hedged': True, }, }, 'swap': { 'linear': { 'extends': 'forDerivatives', }, 'inverse': { 'extends': 'forDerivatives', }, }, 'future': { 'linear': None, 'inverse': None, }, }, 'exceptions': { 'exact': { '400': BadRequest, # Body can not be empty '401': AuthenticationError, # Invalid signature '500': ExchangeError, # Internal Server Error '404': BadRequest, # not found '405': BadRequest, # Method Not Allowed '406': BadRequest, # Not Acceptable '429': RateLimitExceeded, # Too Many Requests '152001': BadRequest, # Parameter {} cannot be empty - verified live 2026-09-14 (withdrawal-apply without addrType) '152002': BadRequest, # Parameter {} error - verified live 2026-09-14 (short-form chain id in withdrawal-apply; NOTE the live message omits the field name) '152003': BadRequest, # Either parameter {} or {} is required '152004': BadRequest, # JSON syntax error '152005': BadRequest, # Parameter error: wrong or empty '152006': InvalidOrder, # Batch orders can be placed for up to 20 at once '152007': InvalidOrder, # Batch orders can only be placed with the same instId and marginMode '152008': InvalidOrder, # Only the same field is allowed for bulk cancellation of orders, orderId is preferred '152009': InvalidOrder, # {} must be a combination of numbers, letters, or underscores, and the maximum length of characters is 32 '150003': InvalidOrder, # clientId already exist '150004': InvalidOrder, # Insufficient balance. please adjust the amount and try again '542': InvalidOrder, # Exceeded the maximum order size limit '102002': InvalidOrder, # Duplicate customized order ID '102005': InvalidOrder, # Position had been closed '102014': InvalidOrder, # Limit order exceeds maximum order size limit '102015': InvalidOrder, # Market order exceeds maximum order size limit '102022': InvalidOrder, # Failed to place order. You don’t have any positions of this contract. Turn off Reduce-only to continue. '102037': InvalidOrder, # TP trigger price should be higher than the latest trading price '102038': InvalidOrder, # SL trigger price should be lower than the latest trading price '102039': InvalidOrder, # TP trigger price should be lower than the latest trading price '102040': InvalidOrder, # SL trigger price should be higher than the latest trading price '102047': InvalidOrder, # Stop loss trigger price should be higher than the order price '102048': InvalidOrder, # stop loss trigger price must be higher than the best bid price '102049': InvalidOrder, # Take profit trigger price should be lower than the order price '102050': InvalidOrder, # stop loss trigger price must be lower than the best ask price '102051': InvalidOrder, # stop loss trigger price should be lower than the order price '102052': InvalidOrder, # take profit trigger price should be higher than the order price '102053': InvalidOrder, # take profit trigger price should be lower than the best bid price '102054': InvalidOrder, # take profit trigger price should be higher than the best ask price '102055': InvalidOrder, # stop loss trigger price should be lower than the best ask price '102064': BadRequest, # Buy price is not within the price limit (Minimum: 310.40; Maximum:1,629.40) '102065': BadRequest, # Sell price is not within the price limit '102068': BadRequest, # Cancel failed as the order has been filled, triggered, canceled or does not exist '103013': ExchangeError, # Internal error; unable to process your request. Please try again. '102067': OrderNotFound, # Order modification failed as the order has been filled, triggered, canceled or does not exist. '102089': BadRequest, # Position mode mismatch '102148': DuplicateOrderId, # Duplicate requestId, request ignored. '103003': InsufficientFunds, # Order failed. Insufficient USDT margin in account '110006': InvalidOrder, # You have pending cross orders. Please cancel them before adjusting your leverage. '110019': InvalidOrder, # Setting failed. Cancel any open orders, and close positions first. '148082': BadRequest, # Callback percentage range 0.1% - 100% '148083': BadRequest, # Callback constant range '152011': PermissionDenied, # Transaction API Key does not support brokerId '152012': BadRequest, # BrokerId is required '152013': PermissionDenied, # Unmatched brokerId, please check your API key's bound broker '152014': BadRequest, # Instrument ID does not exist '152015': BadRequest, # Number of instId values exceeds the maximum limit of 20 '152020': InvalidAddress, # Address binding not found. '152022': BadRequest, # Current network is not available. '152023': PermissionDenied, # This address is still within the 24-hour withdrawal lock period. '152024': PermissionDenied, # Your account now can only withdraw to whitelist addresses. '152025': PermissionDenied, # Deposits not supported yet, contact customer support for details. '152026': BadRequest, # Amount precision error. '152027': BadRequest, # The withdrawal must exceed the minimum limit. '152028': InsufficientFunds, # Insufficient balance. '152029': PermissionDenied, # The maximum daily withdrawal amount has been reached. '152030': DuplicateOrderId, # Duplicated clientId. '152031': InvalidAddress, # This address is not marked as verification-free. - verified live 2026-09-14 (account-policy rejection, address must carry the verification-free flag for api withdrawals) '152032': PermissionDenied, # Quick withdrawal daily limit exceeded. Please complete 2FA verification. '152401': AuthenticationError, # Access key does not exist '152402': AuthenticationError, # Access key has expired '152404': PermissionDenied, # This operation is not supported, Please check the requestPath or API key permissions. - verified live 2026-09-14 (api key without the withdrawal permission) '152405': InvalidNonce, # Timestamp in header or signature has expired, need to be within 60s '152406': PermissionDenied, # Your IP is not included in your API key's IP whitelist '152407': InvalidNonce, # Repeated nonce, Reusing within 60 seconds is not allowed. '152408': AuthenticationError, # Passphrase error '152409': AuthenticationError, # Signature verification failed '152410': InvalidNonce, # The value of ACCESS-TIMESTAMP needs to be a millisecond timestamp '152420': DuplicateOrderId, # Duplicate order in batch request '152421': DuplicateOrderId, # requestId already exists, please try again later '152422': BadRequest, # Exactly one of callbackRatio and callbackSpread must be provided '152423': InvalidOrder, # New size cannot be less than filled size '152428': BadRequest, # Invalid trigger price type '152429': BadRequest, # Request expired, ttl exceeded 'Order failed. Insufficient USDT margin in account': InsufficientFunds, # Insufficient USDT margin in account }, 'broad': { 'Internal Server Error': ExchangeNotAvailable, # {"code":500,"data":{},"detailMsg":"","error_code":"500","error_message":"Internal Server Error","msg":"Internal Server Error"} 'server error': ExchangeNotAvailable, # {"code":500,"data":{},"detailMsg":"","error_code":"500","error_message":"server error 1236805249","msg":"server error 1236805249"} }, }, 'httpExceptions': { '429': ExchangeNotAvailable, # https://github.com/ccxt/ccxt/issues/9612 }, 'precisionMode': TICK_SIZE, 'options': { 'accountsByType': { 'swap': 'futures', 'funding': 'funding', 'future': 'futures', 'copy_trading': 'copy_trading', 'earn': 'earn', 'spot': 'spot', }, 'accountsById': { 'funding': 'funding', 'futures': 'swap', 'copy_trading': 'copy_trading', 'earn': 'earn', 'spot': 'spot', }, 'defaultNetwork': 'ERC20', 'defaultNetworks': { 'ETH': 'ERC20', 'BTC': 'BTC', 'USDT': 'TRC20', }, 'networks': { # code -> the live withdrawal-apply chain identifier where # it carries no parenthesized suffix; the suffix family # ('Tron (TRC20)' and friends) is constructed at runtime # in networkCodeToChainId from networkPrefixes, because a # space before a paren inside a source literal is not # transpiler-safe 'BTC': 'Bitcoin', 'SOL': 'Solana', 'MATIC': 'Polygon POS', 'AVAXC': 'AVAX C-Chain', 'ARBITRUM': 'Arbitrum One', 'OPTIMISM': 'Optimism', 'KAIA': 'KAIA', 'PLASMA': 'Plasma', }, 'networkCodeAliases': { # legacy codes accepted on input, resolved to the unified code 'OP': 'OPTIMISM', }, 'networkPrefixes': { # code -> the display-name prefix; the venue id is # prefix + space + parenthesized suffix, where the suffix # defaults to the unified code itself 'TRC20': 'Tron', 'ERC20': 'Ethereum', 'BEP20': 'BNB Smart Chain', 'APT': 'APT', 'TON': 'TON', }, 'networkSuffixes': { # only where the parenthesized suffix differs from the code 'TON': 'Toncoin', }, 'networkCodesBySuffix': { # reverse of networkSuffixes for parsing venue ids 'Toncoin': 'TON', }, 'networksById': { # paren-free venue ids and legacy short forms -> unified; # ids with a parenthesized suffix are parsed at runtime in # chainIdToNetworkCode 'Bitcoin': 'BTC', 'Solana': 'SOL', 'Polygon POS': 'MATIC', 'AVAX C-Chain': 'AVAXC', 'Arbitrum One': 'ARBITRUM', 'Optimism': 'OPTIMISM', 'BSC': 'BEP20', 'Plasma': 'PLASMA', }, 'fetchOpenInterestHistory': { 'timeframes': { '5m': '5m', '1h': '1H', '8h': '8H', '1d': '1D', '5M': '5m', '1H': '1H', '8H': '8H', '1D': '1D', }, }, 'defaultType': 'swap', 'brokerId': 'ec6dd3a7dd982d0b', 'fetchOpenOrders': { 'method': 'privateGetTradeOrdersPending', }, 'cancelOrders': { 'method': 'privatePostTradeCancelBatchOrders', }, 'fetchClosedOrders': { 'method': 'privateGetTradeOrdersHistory', # privateGetTradeOrdersTpslHistory }, 'withdraw': { # a funding password credential is required by the exchange for the # withdraw call (not to be confused with the api password credential) 'password': None, 'pwd': None, # password or pwd both work }, 'exchangeType': { 'spot': 'SPOT', 'swap': 'SWAP', 'SPOT': 'SPOT', 'SWAP': 'SWAP', }, }, }) def fetch_markets(self, params: dict = {}) -> list[Market]: """ retrieves data on all markets for blofin https://blofin.com/docs#get-instruments :param dict [params]: extra parameters specific to the exchange API endpoint :returns dict[]: an array of objects representing market data """ response = self.publicGetMarketInstruments(params) data = self.safe_list(response, 'data', []) return self.parse_markets(data) def parse_market(self, market: dict) -> Market: id = self.safe_string(market, 'instId') type = self.safe_string_lower(market, 'instType') spot = (type == 'spot') future = (type == 'future') swap = (type == 'swap') option = (type == 'option') contract = swap or future baseId = self.safe_string(market, 'baseCurrency') quoteId = self.safe_string(market, 'quoteCurrency') settleId = self.safe_string(market, 'settleCurrency', quoteId) settle = self.safe_currency_code(settleId) base = self.safe_currency_code(baseId) quote = self.safe_currency_code(quoteId) if (base is None) or (quote is None): return None symbol = base + '/' + quote if swap: symbol = base + '/' + quote + ':' + settle expiry = None strikePrice = None optionType = None tickSize = self.safe_string(market, 'tickSize') fees = self.safe_dict_2(self.fees, type, 'trading', {}) taker = self.safe_number(fees, 'taker') maker = self.safe_number(fees, 'maker') maxLeverage = self.safe_string(market, 'maxLeverage', '100') maxLeverage = Precise.string_max(maxLeverage, '1') isActive = (self.safe_string(market, 'state') == 'live') contractType = self.safe_string(market, 'contractType') maxLimitAmount = self.safe_number(market, 'maxLimitSize') maxSpotCost = self.safe_number(market, 'maxMarketSize') # for spot, market-buy size is denominated in the quote currency, i.e. cost return self.safe_market_structure({ 'id': id, 'symbol': symbol, 'base': base, 'quote': quote, 'baseId': baseId, 'quoteId': quoteId, 'settle': settle, 'settleId': settleId, 'type': type, 'spot': spot, 'option': option, 'margin': (spot and Precise.string_gt(maxLeverage, '1')), 'swap': swap, 'future': future, 'active': isActive, 'taker': taker, 'maker': maker, 'contract': contract, 'linear': (contractType == 'linear') if contract else None, 'inverse': (contractType == 'inverse') if contract else None, 'contractSize': self.safe_number(market, 'contractValue') if contract else None, 'expiry': expiry, 'expiryDatetime': expiry, 'strike': strikePrice, 'optionType': optionType, 'created': self.safe_integer(market, 'listTime'), 'precision': { 'amount': self.safe_number(market, 'lotSize'), 'price': self.parse_number(tickSize), }, 'limits': { 'leverage': { 'min': self.parse_number('1'), 'max': self.parse_number(maxLeverage), }, 'amount': { 'min': self.safe_number(market, 'minSize'), 'max': maxLimitAmount, }, 'price': { 'min': None, 'max': None, }, 'cost': { 'min': None, 'max': None if contract else maxSpotCost, }, }, 'info': market, }) def fetch_order_book(self, symbol: str, limit: Int = None, params: dict = {}) -> OrderBook: """ fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data https://blofin.com/docs#get-order-book :param str symbol: unified symbol of the market to fetch the order book for :param int [limit]: the maximum amount of order book entries to return :param dict [params]: extra parameters specific to the exchange API endpoint :returns dict: an `order book structure <https://docs.ccxt.com/?id=order-book-structure>` """ if self.markets is None: self.load_markets() market = self.market(symbol) request = { 'instId': market['id'], } limitValue = 50 if (limit is None) else limit request['size'] = limitValue # max 100 response = self.publicGetMarketBooks(self.extend(request, params)) # # { # "code": "0", # "msg": "", # "data": [ # { # "asks": [ # ["0.07228","4.211619","0","2"], // price, amount, liquidated orders, total open orders # ["0.0723","299.880364","0","2"], # ["0.07231","3.72832","0","1"], # ], # "bids": [ # ["0.07221","18.5","0","1"], # ["0.0722","18.5","0","1"], # ["0.07219","0.505407","0","1"], # ], # "ts": "1621438475342" # } # ] # } # data = self.safe_list(response, 'data', []) first = self.safe_dict(data, 0, {}) timestamp = self.safe_integer(first, 'ts') return self.parse_order_book(first, symbol, timestamp) def parse_ticker(self, ticker: dict, market: Market = None) -> Ticker: # # response similar for REST & WS # # { # instId: "ADA-USDT", # ts: "1707736811486", # last: "0.5315", # lastSize: "4", # askPrice: "0.5318", # askSize: "248", # bidPrice: "0.5315", # bidSize: "63", # open24h: "0.5555", # high24h: "0.5563", # low24h: "0.5315", # volCurrency24h: "198560100", # vol24h: "1985601", # } # timestamp = self.safe_integer(ticker, 'ts') marketId = self.safe_string(ticker, 'instId') marketResolved = self.safe_market(marketId, market, '-') symbol = marketResolved['symbol'] last = self.safe_string(ticker, 'last') open = self.safe_string(ticker, 'open24h') spot = self.safe_bool(marketResolved, 'spot', False) quoteVolume = self.safe_string(ticker, 'volCurrency24h') if (spot) else None baseVolume = self.safe_string(ticker, 'vol24h') high = self.safe_string(ticker, 'high24h') low = self.safe_string(ticker, 'low24h') return self.safe_ticker({ 'symbol': symbol, 'timestamp': timestamp, 'datetime': self.iso8601(timestamp), 'high': high, 'low': low, 'bid': self.safe_string(ticker, 'bidPrice'), 'bidVolume': self.safe_string(ticker, 'bidSize'), 'ask': self.safe_string(ticker, 'askPrice'), 'askVolume': self.safe_string(ticker, 'askSize'), 'vwap': None, 'open': open, 'close': last, 'last': last, 'previousClose': None, 'change': None, 'percentage': None, 'average': None, 'baseVolume': baseVolume, 'quoteVolume': quoteVolume, 'indexPrice': self.safe_string(ticker, 'indexPrice'), 'markPrice': self.safe_string(ticker, 'markPrice'), 'info': ticker, }, marketResolved) def fetch_ticker(self, symbol: str, params: dict = {}) -> Ticker: """ fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market https://blofin.com/docs#get-tickers :param str symbol: unified symbol of the market to fetch the ticker for :param dict [params]: extra parameters specific to the exchange API endpoint :returns dict: a `ticker structure <https://docs.ccxt.com/?id=ticker-structure>` """ if self.markets is None: self.load_markets() market = self.market(symbol) request = { 'instId': market['id'], } response = self.publicGetMarketTickers(self.extend(request, params)) data = self.safe_list(response, 'data', []) first = self.safe_dict(data, 0, {}) return self.parse_ticker(first, market) def fetch_mark_price(self, symbol: str, params: dict = {}) -> Ticker: """ fetches mark price for the market https://docs.blofin.com/index.html#get-mark-price :param str symbol: unified market symbol :param dict [params]: extra parameters specific to the exchange API endpoint :param str [params.subType]: "linear" or "inverse" :returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/?id=ticker-structure>` """ if self.markets is None: self.load_markets() market = self.market(symbol) request = { 'instId': market['id'], } response = self.publicGetMarketMarkPrice(self.extend(request, params)) data = self.safe_list(response, 'data', []) first = self.safe_dict(data, 0, {}) return self.parse_ticker(first, market) def fetch_tickers(self, symbols: Strings = None, params: dict = {}) -> Tickers: """ fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market https://blofin.com/docs#get-tickers :param str[] [symbols]: unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned :param dict [params]: extra parameters specific to the exchange API endpoint :returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/?id=ticker-structure>` """ if self.markets is None: self.load_markets() symbolsNormalized = self.market_symbols(symbols) response = self.publicGetMarketTickers(params) tickers = self.safe_list(response, 'data', []) return self.parse_tickers(tickers, symbolsNormalized) def parse_trade(self, trade: dict, market: Market = None) -> Trade: # # fetch trades (response similar for REST & WS) # # { # "tradeId": "3263934920", # "instId": "LTC-USDT", # "price": "67.87", # "size": "1", # "side": "buy", # "ts": "1707232020854" # } # # my trades # { # "instId": "LTC-USDT", # "tradeId": "1440847", # "orderId": "2075705202", # "fillPrice": "67.850000000000000000", # "fillSize": "1.000000000000000000", # "fillPnl": "0.000000000000000000", # "side": "buy", # "positionSide": "net", # "fee": "0.040710000000000000", # "ts": "1707224678878", # "brokerId": "" # } # # fetchMyTrades spot # { # "instId": "DOGE-USDT", # "tradeId": "6000001623870", # "orderId": "6000011777113", # "fillPrice": "0.091480000000000000", # "fillSize": "30.000000000000000000", # "fillPnl": null, # "side": "buy", # "fee": "0.030000000000000000", # "ts": "1775213753407", # "brokerId": null, # "feeCurrency": "base_currency" # } # id = self.safe_string(trade, 'tradeId') marketId = self.safe_string(trade, 'instId') marketResolved = self.safe_market(marketId, market, '-') symbol = marketResolved['symbol'] timestamp = self.safe_integer(trade, 'ts') price = self.safe_string_2(trade, 'price', 'fillPrice') amount = self.safe_string_2(trade, 'size', 'fillSize') side = self.safe_string(trade, 'side') orderId = self.safe_string(trade, 'orderId') feeCost = self.safe_string(trade, 'fee') fee = None feeCurrency = self.safe_string(trade, 'feeCurrency') isSpot = feeCurrency is not None if feeCurrency is None: feeCurrency = self.safe_string(marketResolved, 'settle') elif feeCurrency == 'base_currency': feeCurrency = self.safe_string(marketResolved, 'base') elif feeCurrency == 'quote_currency': feeCurrency = self.safe_string(marketResolved, 'quote') if feeCost is not None: fee = { 'cost': feeCost, 'currency': feeCurrency, } if isSpot: spotBase = self.safe_string(marketResolved, 'base', '') spotQuote = self.safe_string(marketResolved, 'quote', '') spotSymbol = spotBase + '/' + spotQuote cost = self.parse_number(Precise.string_mul(price, amount)) result = { 'info': trade, 'timestamp': timestamp, 'datetime': self.iso8601(timestamp), 'symbol': spotSymbol, 'id': id, 'order': orderId, 'type': None, 'takerOrMaker': None, 'side': side, 'price': self.parse_number(price), 'amount': self.parse_number(amount), 'cost': cost, 'fee': { 'cost': self.parse_number(feeCost), 'currency': feeCurrency, }, } return result else: return self.safe_trade({ 'info': trade, 'timestamp': timestamp, 'datetime': self.iso8601(timestamp), 'symbol': symbol, 'id': id, 'order': orderId, 'type': None, 'takerOrMaker': None, 'side': side, 'price': price, 'amount': amount, 'cost': None, 'fee': fee, }, marketResolved) def fetch_trades(self, symbol: str, since: Int = None, limit: Int = None, params: dict = {}) -> list[Trade]: """ |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |