crypto-com-sdk 0.0.13__py3-none-any.whl → 0.0.15__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {crypto_com_sdk-0.0.13.dist-info → crypto_com_sdk-0.0.15.dist-info}/METADATA +1 -1
- crypto_com_sdk-0.0.15.dist-info/RECORD +288 -0
- cryptocom/__init__.py +7 -0
- cryptocom/ccxt/__init__.py +101 -0
- cryptocom/ccxt/abstract/cryptocom.py +121 -0
- cryptocom/ccxt/async_support/__init__.py +80 -0
- cryptocom/ccxt/async_support/base/__init__.py +1 -0
- cryptocom/ccxt/async_support/base/exchange.py +2100 -0
- cryptocom/ccxt/async_support/base/throttler.py +50 -0
- cryptocom/ccxt/async_support/base/ws/__init__.py +38 -0
- cryptocom/ccxt/async_support/base/ws/aiohttp_client.py +147 -0
- cryptocom/ccxt/async_support/base/ws/cache.py +213 -0
- cryptocom/ccxt/async_support/base/ws/client.py +214 -0
- cryptocom/ccxt/async_support/base/ws/fast_client.py +97 -0
- cryptocom/ccxt/async_support/base/ws/functions.py +59 -0
- cryptocom/ccxt/async_support/base/ws/future.py +69 -0
- cryptocom/ccxt/async_support/base/ws/order_book.py +78 -0
- cryptocom/ccxt/async_support/base/ws/order_book_side.py +174 -0
- cryptocom/ccxt/async_support/cryptocom.py +3125 -0
- cryptocom/ccxt/base/__init__.py +27 -0
- cryptocom/ccxt/base/decimal_to_precision.py +174 -0
- cryptocom/ccxt/base/errors.py +267 -0
- cryptocom/ccxt/base/exchange.py +6769 -0
- cryptocom/ccxt/base/precise.py +297 -0
- cryptocom/ccxt/base/types.py +577 -0
- cryptocom/ccxt/cryptocom.py +3125 -0
- cryptocom/ccxt/pro/__init__.py +21 -0
- cryptocom/ccxt/pro/cryptocom.py +1326 -0
- cryptocom/ccxt/static_dependencies/README.md +1 -0
- cryptocom/ccxt/static_dependencies/__init__.py +1 -0
- cryptocom/ccxt/static_dependencies/ecdsa/__init__.py +14 -0
- cryptocom/ccxt/static_dependencies/ecdsa/_version.py +520 -0
- cryptocom/ccxt/static_dependencies/ecdsa/curves.py +56 -0
- cryptocom/ccxt/static_dependencies/ecdsa/der.py +221 -0
- cryptocom/ccxt/static_dependencies/ecdsa/ecdsa.py +310 -0
- cryptocom/ccxt/static_dependencies/ecdsa/ellipticcurve.py +197 -0
- cryptocom/ccxt/static_dependencies/ecdsa/keys.py +332 -0
- cryptocom/ccxt/static_dependencies/ecdsa/numbertheory.py +531 -0
- cryptocom/ccxt/static_dependencies/ecdsa/rfc6979.py +100 -0
- cryptocom/ccxt/static_dependencies/ecdsa/util.py +266 -0
- cryptocom/ccxt/static_dependencies/ethereum/__init__.py +7 -0
- cryptocom/ccxt/static_dependencies/ethereum/abi/__init__.py +16 -0
- cryptocom/ccxt/static_dependencies/ethereum/abi/abi.py +19 -0
- cryptocom/ccxt/static_dependencies/ethereum/abi/base.py +152 -0
- cryptocom/ccxt/static_dependencies/ethereum/abi/codec.py +217 -0
- cryptocom/ccxt/static_dependencies/ethereum/abi/constants.py +3 -0
- cryptocom/ccxt/static_dependencies/ethereum/abi/decoding.py +565 -0
- cryptocom/ccxt/static_dependencies/ethereum/abi/encoding.py +720 -0
- cryptocom/ccxt/static_dependencies/ethereum/abi/exceptions.py +139 -0
- cryptocom/ccxt/static_dependencies/ethereum/abi/grammar.py +443 -0
- cryptocom/ccxt/static_dependencies/ethereum/abi/packed.py +13 -0
- cryptocom/ccxt/static_dependencies/ethereum/abi/py.typed +0 -0
- cryptocom/ccxt/static_dependencies/ethereum/abi/registry.py +643 -0
- cryptocom/ccxt/static_dependencies/ethereum/abi/tools/__init__.py +3 -0
- cryptocom/ccxt/static_dependencies/ethereum/abi/tools/_strategies.py +230 -0
- cryptocom/ccxt/static_dependencies/ethereum/abi/utils/__init__.py +0 -0
- cryptocom/ccxt/static_dependencies/ethereum/abi/utils/numeric.py +83 -0
- cryptocom/ccxt/static_dependencies/ethereum/abi/utils/padding.py +27 -0
- cryptocom/ccxt/static_dependencies/ethereum/abi/utils/string.py +19 -0
- cryptocom/ccxt/static_dependencies/ethereum/account/__init__.py +3 -0
- cryptocom/ccxt/static_dependencies/ethereum/account/encode_typed_data/__init__.py +4 -0
- cryptocom/ccxt/static_dependencies/ethereum/account/encode_typed_data/encoding_and_hashing.py +239 -0
- cryptocom/ccxt/static_dependencies/ethereum/account/encode_typed_data/helpers.py +40 -0
- cryptocom/ccxt/static_dependencies/ethereum/account/messages.py +263 -0
- cryptocom/ccxt/static_dependencies/ethereum/account/py.typed +0 -0
- cryptocom/ccxt/static_dependencies/ethereum/hexbytes/__init__.py +5 -0
- cryptocom/ccxt/static_dependencies/ethereum/hexbytes/_utils.py +54 -0
- cryptocom/ccxt/static_dependencies/ethereum/hexbytes/main.py +65 -0
- cryptocom/ccxt/static_dependencies/ethereum/hexbytes/py.typed +0 -0
- cryptocom/ccxt/static_dependencies/ethereum/typing/__init__.py +63 -0
- cryptocom/ccxt/static_dependencies/ethereum/typing/abi.py +6 -0
- cryptocom/ccxt/static_dependencies/ethereum/typing/bls.py +7 -0
- cryptocom/ccxt/static_dependencies/ethereum/typing/discovery.py +5 -0
- cryptocom/ccxt/static_dependencies/ethereum/typing/encoding.py +7 -0
- cryptocom/ccxt/static_dependencies/ethereum/typing/enums.py +17 -0
- cryptocom/ccxt/static_dependencies/ethereum/typing/ethpm.py +9 -0
- cryptocom/ccxt/static_dependencies/ethereum/typing/evm.py +20 -0
- cryptocom/ccxt/static_dependencies/ethereum/typing/networks.py +1122 -0
- cryptocom/ccxt/static_dependencies/ethereum/typing/py.typed +0 -0
- cryptocom/ccxt/static_dependencies/ethereum/utils/__init__.py +115 -0
- cryptocom/ccxt/static_dependencies/ethereum/utils/abi.py +72 -0
- cryptocom/ccxt/static_dependencies/ethereum/utils/address.py +171 -0
- cryptocom/ccxt/static_dependencies/ethereum/utils/applicators.py +151 -0
- cryptocom/ccxt/static_dependencies/ethereum/utils/conversions.py +190 -0
- cryptocom/ccxt/static_dependencies/ethereum/utils/currency.py +107 -0
- cryptocom/ccxt/static_dependencies/ethereum/utils/curried/__init__.py +269 -0
- cryptocom/ccxt/static_dependencies/ethereum/utils/debug.py +20 -0
- cryptocom/ccxt/static_dependencies/ethereum/utils/decorators.py +132 -0
- cryptocom/ccxt/static_dependencies/ethereum/utils/encoding.py +6 -0
- cryptocom/ccxt/static_dependencies/ethereum/utils/exceptions.py +4 -0
- cryptocom/ccxt/static_dependencies/ethereum/utils/functional.py +75 -0
- cryptocom/ccxt/static_dependencies/ethereum/utils/hexadecimal.py +74 -0
- cryptocom/ccxt/static_dependencies/ethereum/utils/humanize.py +188 -0
- cryptocom/ccxt/static_dependencies/ethereum/utils/logging.py +159 -0
- cryptocom/ccxt/static_dependencies/ethereum/utils/module_loading.py +31 -0
- cryptocom/ccxt/static_dependencies/ethereum/utils/numeric.py +43 -0
- cryptocom/ccxt/static_dependencies/ethereum/utils/py.typed +0 -0
- cryptocom/ccxt/static_dependencies/ethereum/utils/toolz.py +76 -0
- cryptocom/ccxt/static_dependencies/ethereum/utils/types.py +54 -0
- cryptocom/ccxt/static_dependencies/ethereum/utils/typing/__init__.py +18 -0
- cryptocom/ccxt/static_dependencies/ethereum/utils/typing/misc.py +14 -0
- cryptocom/ccxt/static_dependencies/ethereum/utils/units.py +31 -0
- cryptocom/ccxt/static_dependencies/keccak/__init__.py +3 -0
- cryptocom/ccxt/static_dependencies/keccak/keccak.py +197 -0
- cryptocom/ccxt/static_dependencies/lark/__init__.py +38 -0
- cryptocom/ccxt/static_dependencies/lark/__pyinstaller/__init__.py +6 -0
- cryptocom/ccxt/static_dependencies/lark/__pyinstaller/hook-lark.py +14 -0
- cryptocom/ccxt/static_dependencies/lark/ast_utils.py +59 -0
- cryptocom/ccxt/static_dependencies/lark/common.py +86 -0
- cryptocom/ccxt/static_dependencies/lark/exceptions.py +292 -0
- cryptocom/ccxt/static_dependencies/lark/grammar.py +130 -0
- cryptocom/ccxt/static_dependencies/lark/grammars/__init__.py +0 -0
- cryptocom/ccxt/static_dependencies/lark/grammars/common.lark +59 -0
- cryptocom/ccxt/static_dependencies/lark/grammars/lark.lark +62 -0
- cryptocom/ccxt/static_dependencies/lark/grammars/python.lark +302 -0
- cryptocom/ccxt/static_dependencies/lark/grammars/unicode.lark +7 -0
- cryptocom/ccxt/static_dependencies/lark/indenter.py +143 -0
- cryptocom/ccxt/static_dependencies/lark/lark.py +658 -0
- cryptocom/ccxt/static_dependencies/lark/lexer.py +678 -0
- cryptocom/ccxt/static_dependencies/lark/load_grammar.py +1428 -0
- cryptocom/ccxt/static_dependencies/lark/parse_tree_builder.py +391 -0
- cryptocom/ccxt/static_dependencies/lark/parser_frontends.py +257 -0
- cryptocom/ccxt/static_dependencies/lark/parsers/__init__.py +0 -0
- cryptocom/ccxt/static_dependencies/lark/parsers/cyk.py +340 -0
- cryptocom/ccxt/static_dependencies/lark/parsers/earley.py +314 -0
- cryptocom/ccxt/static_dependencies/lark/parsers/earley_common.py +42 -0
- cryptocom/ccxt/static_dependencies/lark/parsers/earley_forest.py +801 -0
- cryptocom/ccxt/static_dependencies/lark/parsers/grammar_analysis.py +203 -0
- cryptocom/ccxt/static_dependencies/lark/parsers/lalr_analysis.py +332 -0
- cryptocom/ccxt/static_dependencies/lark/parsers/lalr_interactive_parser.py +158 -0
- cryptocom/ccxt/static_dependencies/lark/parsers/lalr_parser.py +122 -0
- cryptocom/ccxt/static_dependencies/lark/parsers/lalr_parser_state.py +110 -0
- cryptocom/ccxt/static_dependencies/lark/parsers/xearley.py +165 -0
- cryptocom/ccxt/static_dependencies/lark/py.typed +0 -0
- cryptocom/ccxt/static_dependencies/lark/reconstruct.py +107 -0
- cryptocom/ccxt/static_dependencies/lark/tools/__init__.py +70 -0
- cryptocom/ccxt/static_dependencies/lark/tools/nearley.py +202 -0
- cryptocom/ccxt/static_dependencies/lark/tools/serialize.py +32 -0
- cryptocom/ccxt/static_dependencies/lark/tools/standalone.py +196 -0
- cryptocom/ccxt/static_dependencies/lark/tree.py +267 -0
- cryptocom/ccxt/static_dependencies/lark/tree_matcher.py +186 -0
- cryptocom/ccxt/static_dependencies/lark/tree_templates.py +180 -0
- cryptocom/ccxt/static_dependencies/lark/utils.py +343 -0
- cryptocom/ccxt/static_dependencies/lark/visitors.py +596 -0
- cryptocom/ccxt/static_dependencies/marshmallow/__init__.py +81 -0
- cryptocom/ccxt/static_dependencies/marshmallow/base.py +65 -0
- cryptocom/ccxt/static_dependencies/marshmallow/class_registry.py +94 -0
- cryptocom/ccxt/static_dependencies/marshmallow/decorators.py +231 -0
- cryptocom/ccxt/static_dependencies/marshmallow/error_store.py +60 -0
- cryptocom/ccxt/static_dependencies/marshmallow/exceptions.py +71 -0
- cryptocom/ccxt/static_dependencies/marshmallow/fields.py +2114 -0
- cryptocom/ccxt/static_dependencies/marshmallow/orderedset.py +89 -0
- cryptocom/ccxt/static_dependencies/marshmallow/py.typed +0 -0
- cryptocom/ccxt/static_dependencies/marshmallow/schema.py +1228 -0
- cryptocom/ccxt/static_dependencies/marshmallow/types.py +12 -0
- cryptocom/ccxt/static_dependencies/marshmallow/utils.py +378 -0
- cryptocom/ccxt/static_dependencies/marshmallow/validate.py +678 -0
- cryptocom/ccxt/static_dependencies/marshmallow/warnings.py +2 -0
- cryptocom/ccxt/static_dependencies/marshmallow_dataclass/__init__.py +1047 -0
- cryptocom/ccxt/static_dependencies/marshmallow_dataclass/collection_field.py +51 -0
- cryptocom/ccxt/static_dependencies/marshmallow_dataclass/lazy_class_attribute.py +45 -0
- cryptocom/ccxt/static_dependencies/marshmallow_dataclass/mypy.py +71 -0
- cryptocom/ccxt/static_dependencies/marshmallow_dataclass/py.typed +0 -0
- cryptocom/ccxt/static_dependencies/marshmallow_dataclass/typing.py +14 -0
- cryptocom/ccxt/static_dependencies/marshmallow_dataclass/union_field.py +82 -0
- cryptocom/ccxt/static_dependencies/marshmallow_oneofschema/__init__.py +1 -0
- cryptocom/ccxt/static_dependencies/marshmallow_oneofschema/one_of_schema.py +193 -0
- cryptocom/ccxt/static_dependencies/marshmallow_oneofschema/py.typed +0 -0
- cryptocom/ccxt/static_dependencies/msgpack/__init__.py +55 -0
- cryptocom/ccxt/static_dependencies/msgpack/_cmsgpack.pyx +11 -0
- cryptocom/ccxt/static_dependencies/msgpack/_packer.pyx +374 -0
- cryptocom/ccxt/static_dependencies/msgpack/_unpacker.pyx +547 -0
- cryptocom/ccxt/static_dependencies/msgpack/buff_converter.h +8 -0
- cryptocom/ccxt/static_dependencies/msgpack/exceptions.py +48 -0
- cryptocom/ccxt/static_dependencies/msgpack/ext.py +168 -0
- cryptocom/ccxt/static_dependencies/msgpack/fallback.py +951 -0
- cryptocom/ccxt/static_dependencies/msgpack/pack.h +89 -0
- cryptocom/ccxt/static_dependencies/msgpack/pack_template.h +820 -0
- cryptocom/ccxt/static_dependencies/msgpack/sysdep.h +194 -0
- cryptocom/ccxt/static_dependencies/msgpack/unpack.h +391 -0
- cryptocom/ccxt/static_dependencies/msgpack/unpack_define.h +95 -0
- cryptocom/ccxt/static_dependencies/msgpack/unpack_template.h +464 -0
- cryptocom/ccxt/static_dependencies/parsimonious/__init__.py +10 -0
- cryptocom/ccxt/static_dependencies/parsimonious/exceptions.py +105 -0
- cryptocom/ccxt/static_dependencies/parsimonious/expressions.py +479 -0
- cryptocom/ccxt/static_dependencies/parsimonious/grammar.py +487 -0
- cryptocom/ccxt/static_dependencies/parsimonious/nodes.py +325 -0
- cryptocom/ccxt/static_dependencies/parsimonious/utils.py +40 -0
- cryptocom/ccxt/static_dependencies/starknet/__init__.py +0 -0
- cryptocom/ccxt/static_dependencies/starknet/abi/v0/__init__.py +2 -0
- cryptocom/ccxt/static_dependencies/starknet/abi/v0/model.py +44 -0
- cryptocom/ccxt/static_dependencies/starknet/abi/v0/parser.py +216 -0
- cryptocom/ccxt/static_dependencies/starknet/abi/v0/schemas.py +72 -0
- cryptocom/ccxt/static_dependencies/starknet/abi/v0/shape.py +63 -0
- cryptocom/ccxt/static_dependencies/starknet/abi/v1/__init__.py +2 -0
- cryptocom/ccxt/static_dependencies/starknet/abi/v1/core_structures.json +14 -0
- cryptocom/ccxt/static_dependencies/starknet/abi/v1/model.py +39 -0
- cryptocom/ccxt/static_dependencies/starknet/abi/v1/parser.py +220 -0
- cryptocom/ccxt/static_dependencies/starknet/abi/v1/parser_transformer.py +179 -0
- cryptocom/ccxt/static_dependencies/starknet/abi/v1/schemas.py +66 -0
- cryptocom/ccxt/static_dependencies/starknet/abi/v1/shape.py +47 -0
- cryptocom/ccxt/static_dependencies/starknet/abi/v2/__init__.py +2 -0
- cryptocom/ccxt/static_dependencies/starknet/abi/v2/model.py +89 -0
- cryptocom/ccxt/static_dependencies/starknet/abi/v2/parser.py +293 -0
- cryptocom/ccxt/static_dependencies/starknet/abi/v2/parser_transformer.py +192 -0
- cryptocom/ccxt/static_dependencies/starknet/abi/v2/schemas.py +132 -0
- cryptocom/ccxt/static_dependencies/starknet/abi/v2/shape.py +107 -0
- cryptocom/ccxt/static_dependencies/starknet/cairo/__init__.py +0 -0
- cryptocom/ccxt/static_dependencies/starknet/cairo/data_types.py +123 -0
- cryptocom/ccxt/static_dependencies/starknet/cairo/deprecated_parse/__init__.py +0 -0
- cryptocom/ccxt/static_dependencies/starknet/cairo/deprecated_parse/cairo_types.py +77 -0
- cryptocom/ccxt/static_dependencies/starknet/cairo/deprecated_parse/parser.py +46 -0
- cryptocom/ccxt/static_dependencies/starknet/cairo/deprecated_parse/parser_transformer.py +138 -0
- cryptocom/ccxt/static_dependencies/starknet/cairo/felt.py +64 -0
- cryptocom/ccxt/static_dependencies/starknet/cairo/type_parser.py +121 -0
- cryptocom/ccxt/static_dependencies/starknet/cairo/v1/__init__.py +0 -0
- cryptocom/ccxt/static_dependencies/starknet/cairo/v1/type_parser.py +59 -0
- cryptocom/ccxt/static_dependencies/starknet/cairo/v2/__init__.py +0 -0
- cryptocom/ccxt/static_dependencies/starknet/cairo/v2/type_parser.py +77 -0
- cryptocom/ccxt/static_dependencies/starknet/ccxt_utils.py +7 -0
- cryptocom/ccxt/static_dependencies/starknet/common.py +15 -0
- cryptocom/ccxt/static_dependencies/starknet/constants.py +39 -0
- cryptocom/ccxt/static_dependencies/starknet/hash/__init__.py +0 -0
- cryptocom/ccxt/static_dependencies/starknet/hash/address.py +79 -0
- cryptocom/ccxt/static_dependencies/starknet/hash/compiled_class_hash_objects.py +111 -0
- cryptocom/ccxt/static_dependencies/starknet/hash/selector.py +16 -0
- cryptocom/ccxt/static_dependencies/starknet/hash/storage.py +12 -0
- cryptocom/ccxt/static_dependencies/starknet/hash/utils.py +78 -0
- cryptocom/ccxt/static_dependencies/starknet/models/__init__.py +0 -0
- cryptocom/ccxt/static_dependencies/starknet/models/typed_data.py +45 -0
- cryptocom/ccxt/static_dependencies/starknet/serialization/__init__.py +24 -0
- cryptocom/ccxt/static_dependencies/starknet/serialization/_calldata_reader.py +40 -0
- cryptocom/ccxt/static_dependencies/starknet/serialization/_context.py +142 -0
- cryptocom/ccxt/static_dependencies/starknet/serialization/data_serializers/__init__.py +10 -0
- cryptocom/ccxt/static_dependencies/starknet/serialization/data_serializers/_common.py +82 -0
- cryptocom/ccxt/static_dependencies/starknet/serialization/data_serializers/array_serializer.py +43 -0
- cryptocom/ccxt/static_dependencies/starknet/serialization/data_serializers/bool_serializer.py +37 -0
- cryptocom/ccxt/static_dependencies/starknet/serialization/data_serializers/byte_array_serializer.py +66 -0
- cryptocom/ccxt/static_dependencies/starknet/serialization/data_serializers/cairo_data_serializer.py +71 -0
- cryptocom/ccxt/static_dependencies/starknet/serialization/data_serializers/enum_serializer.py +71 -0
- cryptocom/ccxt/static_dependencies/starknet/serialization/data_serializers/felt_serializer.py +50 -0
- cryptocom/ccxt/static_dependencies/starknet/serialization/data_serializers/named_tuple_serializer.py +58 -0
- cryptocom/ccxt/static_dependencies/starknet/serialization/data_serializers/option_serializer.py +43 -0
- cryptocom/ccxt/static_dependencies/starknet/serialization/data_serializers/output_serializer.py +40 -0
- cryptocom/ccxt/static_dependencies/starknet/serialization/data_serializers/payload_serializer.py +72 -0
- cryptocom/ccxt/static_dependencies/starknet/serialization/data_serializers/struct_serializer.py +36 -0
- cryptocom/ccxt/static_dependencies/starknet/serialization/data_serializers/tuple_serializer.py +36 -0
- cryptocom/ccxt/static_dependencies/starknet/serialization/data_serializers/uint256_serializer.py +76 -0
- cryptocom/ccxt/static_dependencies/starknet/serialization/data_serializers/uint_serializer.py +100 -0
- cryptocom/ccxt/static_dependencies/starknet/serialization/data_serializers/unit_serializer.py +32 -0
- cryptocom/ccxt/static_dependencies/starknet/serialization/errors.py +10 -0
- cryptocom/ccxt/static_dependencies/starknet/serialization/factory.py +229 -0
- cryptocom/ccxt/static_dependencies/starknet/serialization/function_serialization_adapter.py +110 -0
- cryptocom/ccxt/static_dependencies/starknet/serialization/tuple_dataclass.py +59 -0
- cryptocom/ccxt/static_dependencies/starknet/utils/__init__.py +0 -0
- cryptocom/ccxt/static_dependencies/starknet/utils/constructor_args_translator.py +86 -0
- cryptocom/ccxt/static_dependencies/starknet/utils/iterable.py +13 -0
- cryptocom/ccxt/static_dependencies/starknet/utils/schema.py +13 -0
- cryptocom/ccxt/static_dependencies/starknet/utils/typed_data.py +182 -0
- cryptocom/ccxt/static_dependencies/starkware/__init__.py +0 -0
- cryptocom/ccxt/static_dependencies/starkware/crypto/__init__.py +0 -0
- cryptocom/ccxt/static_dependencies/starkware/crypto/fast_pedersen_hash.py +50 -0
- cryptocom/ccxt/static_dependencies/starkware/crypto/math_utils.py +78 -0
- cryptocom/ccxt/static_dependencies/starkware/crypto/signature.py +2344 -0
- cryptocom/ccxt/static_dependencies/starkware/crypto/utils.py +63 -0
- cryptocom/ccxt/static_dependencies/sympy/__init__.py +0 -0
- cryptocom/ccxt/static_dependencies/sympy/core/__init__.py +0 -0
- cryptocom/ccxt/static_dependencies/sympy/core/intfunc.py +35 -0
- cryptocom/ccxt/static_dependencies/sympy/external/__init__.py +0 -0
- cryptocom/ccxt/static_dependencies/sympy/external/gmpy.py +345 -0
- cryptocom/ccxt/static_dependencies/sympy/external/importtools.py +187 -0
- cryptocom/ccxt/static_dependencies/sympy/external/ntheory.py +637 -0
- cryptocom/ccxt/static_dependencies/sympy/external/pythonmpq.py +341 -0
- cryptocom/ccxt/static_dependencies/toolz/__init__.py +26 -0
- cryptocom/ccxt/static_dependencies/toolz/_signatures.py +784 -0
- cryptocom/ccxt/static_dependencies/toolz/_version.py +520 -0
- cryptocom/ccxt/static_dependencies/toolz/compatibility.py +30 -0
- cryptocom/ccxt/static_dependencies/toolz/curried/__init__.py +101 -0
- cryptocom/ccxt/static_dependencies/toolz/curried/exceptions.py +22 -0
- cryptocom/ccxt/static_dependencies/toolz/curried/operator.py +22 -0
- cryptocom/ccxt/static_dependencies/toolz/dicttoolz.py +339 -0
- cryptocom/ccxt/static_dependencies/toolz/functoolz.py +1049 -0
- cryptocom/ccxt/static_dependencies/toolz/itertoolz.py +1057 -0
- cryptocom/ccxt/static_dependencies/toolz/recipes.py +46 -0
- cryptocom/ccxt/static_dependencies/toolz/utils.py +9 -0
- cryptocom/ccxt/static_dependencies/typing_inspect/__init__.py +0 -0
- cryptocom/ccxt/static_dependencies/typing_inspect/typing_inspect.py +851 -0
- crypto_com_sdk-0.0.13.dist-info/RECORD +0 -3
- {crypto_com_sdk-0.0.13.dist-info → crypto_com_sdk-0.0.15.dist-info}/WHEEL +0 -0
@@ -0,0 +1,3125 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
# PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
|
4
|
+
# https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
|
5
|
+
|
6
|
+
from ccxt.base.exchange import Exchange
|
7
|
+
from ccxt.abstract.cryptocom import ImplicitAPI
|
8
|
+
import hashlib
|
9
|
+
from ccxt.base.types import Account, Any, Balances, Currency, DepositAddress, Int, LedgerEntry, Market, Num, Order, OrderBook, OrderRequest, CancellationRequest, OrderSide, OrderType, Str, Strings, Ticker, Tickers, Trade, TradingFeeInterface, TradingFees, Transaction
|
10
|
+
from typing import List
|
11
|
+
from ccxt.base.errors import ExchangeError
|
12
|
+
from ccxt.base.errors import AuthenticationError
|
13
|
+
from ccxt.base.errors import PermissionDenied
|
14
|
+
from ccxt.base.errors import AccountNotEnabled
|
15
|
+
from ccxt.base.errors import ArgumentsRequired
|
16
|
+
from ccxt.base.errors import BadRequest
|
17
|
+
from ccxt.base.errors import BadSymbol
|
18
|
+
from ccxt.base.errors import InsufficientFunds
|
19
|
+
from ccxt.base.errors import InvalidOrder
|
20
|
+
from ccxt.base.errors import OrderNotFound
|
21
|
+
from ccxt.base.errors import NotSupported
|
22
|
+
from ccxt.base.errors import DDoSProtection
|
23
|
+
from ccxt.base.errors import RateLimitExceeded
|
24
|
+
from ccxt.base.errors import OnMaintenance
|
25
|
+
from ccxt.base.errors import InvalidNonce
|
26
|
+
from ccxt.base.errors import RequestTimeout
|
27
|
+
from ccxt.base.decimal_to_precision import TICK_SIZE
|
28
|
+
from ccxt.base.precise import Precise
|
29
|
+
|
30
|
+
|
31
|
+
class cryptocom(Exchange, ImplicitAPI):
|
32
|
+
|
33
|
+
def describe(self) -> Any:
|
34
|
+
return self.deep_extend(super(cryptocom, self).describe(), {
|
35
|
+
'id': 'cryptocom',
|
36
|
+
'name': 'Crypto.com',
|
37
|
+
'countries': ['MT'],
|
38
|
+
'version': 'v2',
|
39
|
+
'rateLimit': 10, # 100 requests per second
|
40
|
+
'certified': True,
|
41
|
+
'pro': True,
|
42
|
+
'has': {
|
43
|
+
'CORS': False,
|
44
|
+
'spot': True,
|
45
|
+
'margin': True,
|
46
|
+
'swap': True,
|
47
|
+
'future': True,
|
48
|
+
'option': True,
|
49
|
+
'addMargin': False,
|
50
|
+
'cancelAllOrders': True,
|
51
|
+
'cancelOrder': True,
|
52
|
+
'cancelOrders': True,
|
53
|
+
'cancelOrdersForSymbols': True,
|
54
|
+
'closeAllPositions': False,
|
55
|
+
'closePosition': True,
|
56
|
+
'createMarketBuyOrderWithCost': False,
|
57
|
+
'createMarketOrderWithCost': False,
|
58
|
+
'createMarketSellOrderWithCost': False,
|
59
|
+
'createOrder': True,
|
60
|
+
'createOrders': True,
|
61
|
+
'createStopOrder': True,
|
62
|
+
'createTriggerOrder': True,
|
63
|
+
'fetchAccounts': True,
|
64
|
+
'fetchBalance': True,
|
65
|
+
'fetchBidsAsks': False,
|
66
|
+
'fetchBorrowInterest': False,
|
67
|
+
'fetchBorrowRateHistories': False,
|
68
|
+
'fetchBorrowRateHistory': False,
|
69
|
+
'fetchClosedOrders': 'emulated',
|
70
|
+
'fetchCrossBorrowRate': False,
|
71
|
+
'fetchCrossBorrowRates': False,
|
72
|
+
'fetchCurrencies': False,
|
73
|
+
'fetchDepositAddress': True,
|
74
|
+
'fetchDepositAddresses': False,
|
75
|
+
'fetchDepositAddressesByNetwork': True,
|
76
|
+
'fetchDeposits': True,
|
77
|
+
'fetchDepositsWithdrawals': False,
|
78
|
+
'fetchDepositWithdrawFee': 'emulated',
|
79
|
+
'fetchDepositWithdrawFees': True,
|
80
|
+
'fetchFundingHistory': False,
|
81
|
+
'fetchFundingRate': False,
|
82
|
+
'fetchFundingRateHistory': True,
|
83
|
+
'fetchFundingRates': False,
|
84
|
+
'fetchGreeks': False,
|
85
|
+
'fetchIndexOHLCV': False,
|
86
|
+
'fetchIsolatedBorrowRate': False,
|
87
|
+
'fetchIsolatedBorrowRates': False,
|
88
|
+
'fetchLedger': True,
|
89
|
+
'fetchLeverage': False,
|
90
|
+
'fetchLeverageTiers': False,
|
91
|
+
'fetchMarginAdjustmentHistory': False,
|
92
|
+
'fetchMarginMode': False,
|
93
|
+
'fetchMarketLeverageTiers': False,
|
94
|
+
'fetchMarkets': True,
|
95
|
+
'fetchMarkOHLCV': False,
|
96
|
+
'fetchMySettlementHistory': False,
|
97
|
+
'fetchMyTrades': True,
|
98
|
+
'fetchOHLCV': True,
|
99
|
+
'fetchOpenOrders': True,
|
100
|
+
'fetchOrder': True,
|
101
|
+
'fetchOrderBook': True,
|
102
|
+
'fetchOrders': True,
|
103
|
+
'fetchPosition': True,
|
104
|
+
'fetchPositionHistory': False,
|
105
|
+
'fetchPositionMode': False,
|
106
|
+
'fetchPositions': True,
|
107
|
+
'fetchPositionsHistory': False,
|
108
|
+
'fetchPremiumIndexOHLCV': False,
|
109
|
+
'fetchSettlementHistory': True,
|
110
|
+
'fetchStatus': False,
|
111
|
+
'fetchTicker': True,
|
112
|
+
'fetchTickers': True,
|
113
|
+
'fetchTime': False,
|
114
|
+
'fetchTrades': True,
|
115
|
+
'fetchTradingFee': True,
|
116
|
+
'fetchTradingFees': True,
|
117
|
+
'fetchTransactionFees': False,
|
118
|
+
'fetchTransactions': False,
|
119
|
+
'fetchTransfers': False,
|
120
|
+
'fetchUnderlyingAssets': False,
|
121
|
+
'fetchVolatilityHistory': False,
|
122
|
+
'fetchWithdrawals': True,
|
123
|
+
'reduceMargin': False,
|
124
|
+
'repayCrossMargin': False,
|
125
|
+
'repayIsolatedMargin': False,
|
126
|
+
'sandbox': True,
|
127
|
+
'setLeverage': False,
|
128
|
+
'setMarginMode': False,
|
129
|
+
'setPositionMode': False,
|
130
|
+
'transfer': False,
|
131
|
+
'withdraw': True,
|
132
|
+
},
|
133
|
+
'timeframes': {
|
134
|
+
'1m': '1m',
|
135
|
+
'5m': '5m',
|
136
|
+
'15m': '15m',
|
137
|
+
'30m': '30m',
|
138
|
+
'1h': '1h',
|
139
|
+
'4h': '4h',
|
140
|
+
'6h': '6h',
|
141
|
+
'12h': '12h',
|
142
|
+
'1d': '1D',
|
143
|
+
'1w': '7D',
|
144
|
+
'2w': '14D',
|
145
|
+
'1M': '1M',
|
146
|
+
},
|
147
|
+
'urls': {
|
148
|
+
'logo': 'https://user-images.githubusercontent.com/1294454/147792121-38ed5e36-c229-48d6-b49a-48d05fc19ed4.jpeg',
|
149
|
+
'test': {
|
150
|
+
'v1': 'https://uat-api.3ona.co/exchange/v1',
|
151
|
+
'v2': 'https://uat-api.3ona.co/v2',
|
152
|
+
'derivatives': 'https://uat-api.3ona.co/v2',
|
153
|
+
},
|
154
|
+
'api': {
|
155
|
+
'v1': 'https://api.crypto.com/exchange/v1',
|
156
|
+
'v2': 'https://api.crypto.com/v2',
|
157
|
+
'derivatives': 'https://deriv-api.crypto.com/v1',
|
158
|
+
},
|
159
|
+
'www': 'https://crypto.com/',
|
160
|
+
'referral': {
|
161
|
+
'url': 'https://crypto.com/exch/kdacthrnxt',
|
162
|
+
'discount': 0.75,
|
163
|
+
},
|
164
|
+
'doc': [
|
165
|
+
'https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html',
|
166
|
+
'https://exchange-docs.crypto.com/spot/index.html',
|
167
|
+
'https://exchange-docs.crypto.com/derivatives/index.html',
|
168
|
+
],
|
169
|
+
'fees': 'https://crypto.com/exchange/document/fees-limits',
|
170
|
+
},
|
171
|
+
'api': {
|
172
|
+
'v1': {
|
173
|
+
'public': {
|
174
|
+
'get': {
|
175
|
+
'public/auth': 10 / 3,
|
176
|
+
'public/get-instruments': 10 / 3,
|
177
|
+
'public/get-book': 1,
|
178
|
+
'public/get-candlestick': 1,
|
179
|
+
'public/get-trades': 1,
|
180
|
+
'public/get-tickers': 1,
|
181
|
+
'public/get-valuations': 1,
|
182
|
+
'public/get-expired-settlement-price': 10 / 3,
|
183
|
+
'public/get-insurance': 1,
|
184
|
+
'public/get-risk-parameters': 1,
|
185
|
+
},
|
186
|
+
'post': {
|
187
|
+
'public/staking/get-conversion-rate': 2,
|
188
|
+
},
|
189
|
+
},
|
190
|
+
'private': {
|
191
|
+
'post': {
|
192
|
+
'private/set-cancel-on-disconnect': 10 / 3,
|
193
|
+
'private/get-cancel-on-disconnect': 10 / 3,
|
194
|
+
'private/user-balance': 10 / 3,
|
195
|
+
'private/user-balance-history': 10 / 3,
|
196
|
+
'private/get-positions': 10 / 3,
|
197
|
+
'private/create-order': 2 / 3,
|
198
|
+
'private/create-order-list': 10 / 3,
|
199
|
+
'private/cancel-order': 2 / 3,
|
200
|
+
'private/cancel-order-list': 10 / 3,
|
201
|
+
'private/cancel-all-orders': 2 / 3,
|
202
|
+
'private/close-position': 10 / 3,
|
203
|
+
'private/get-order-history': 100,
|
204
|
+
'private/get-open-orders': 10 / 3,
|
205
|
+
'private/get-order-detail': 1 / 3,
|
206
|
+
'private/get-trades': 100,
|
207
|
+
'private/change-account-leverage': 10 / 3,
|
208
|
+
'private/get-transactions': 10 / 3,
|
209
|
+
'private/create-subaccount-transfer': 10 / 3,
|
210
|
+
'private/get-subaccount-balances': 10 / 3,
|
211
|
+
'private/get-order-list': 10 / 3,
|
212
|
+
'private/create-withdrawal': 10 / 3,
|
213
|
+
'private/get-currency-networks': 10 / 3,
|
214
|
+
'private/get-deposit-address': 10 / 3,
|
215
|
+
'private/get-accounts': 10 / 3,
|
216
|
+
'private/get-withdrawal-history': 10 / 3,
|
217
|
+
'private/get-deposit-history': 10 / 3,
|
218
|
+
'private/get-fee-rate': 2,
|
219
|
+
'private/get-instrument-fee-rate': 2,
|
220
|
+
'private/staking/stake': 2,
|
221
|
+
'private/staking/unstake': 2,
|
222
|
+
'private/staking/get-staking-position': 2,
|
223
|
+
'private/staking/get-staking-instruments': 2,
|
224
|
+
'private/staking/get-open-stake': 2,
|
225
|
+
'private/staking/get-stake-history': 2,
|
226
|
+
'private/staking/get-reward-history': 2,
|
227
|
+
'private/staking/convert': 2,
|
228
|
+
'private/staking/get-open-convert': 2,
|
229
|
+
'private/staking/get-convert-history': 2,
|
230
|
+
},
|
231
|
+
},
|
232
|
+
},
|
233
|
+
'v2': {
|
234
|
+
'public': {
|
235
|
+
'get': {
|
236
|
+
'public/auth': 1,
|
237
|
+
'public/get-instruments': 1,
|
238
|
+
'public/get-book': 1,
|
239
|
+
'public/get-candlestick': 1,
|
240
|
+
'public/get-ticker': 1,
|
241
|
+
'public/get-trades': 1,
|
242
|
+
'public/margin/get-transfer-currencies': 1,
|
243
|
+
'public/margin/get-load-currenices': 1,
|
244
|
+
'public/respond-heartbeat': 1,
|
245
|
+
},
|
246
|
+
},
|
247
|
+
'private': {
|
248
|
+
'post': {
|
249
|
+
'private/set-cancel-on-disconnect': 10 / 3,
|
250
|
+
'private/get-cancel-on-disconnect': 10 / 3,
|
251
|
+
'private/create-withdrawal': 10 / 3,
|
252
|
+
'private/get-withdrawal-history': 10 / 3,
|
253
|
+
'private/get-currency-networks': 10 / 3,
|
254
|
+
'private/get-deposit-history': 10 / 3,
|
255
|
+
'private/get-deposit-address': 10 / 3,
|
256
|
+
'private/export/create-export-request': 10 / 3,
|
257
|
+
'private/export/get-export-requests': 10 / 3,
|
258
|
+
'private/export/download-export-output': 10 / 3,
|
259
|
+
'private/get-account-summary': 10 / 3,
|
260
|
+
'private/create-order': 2 / 3,
|
261
|
+
'private/cancel-order': 2 / 3,
|
262
|
+
'private/cancel-all-orders': 2 / 3,
|
263
|
+
'private/create-order-list': 10 / 3,
|
264
|
+
'private/get-order-history': 10 / 3,
|
265
|
+
'private/get-open-orders': 10 / 3,
|
266
|
+
'private/get-order-detail': 1 / 3,
|
267
|
+
'private/get-trades': 100,
|
268
|
+
'private/get-accounts': 10 / 3,
|
269
|
+
'private/get-subaccount-balances': 10 / 3,
|
270
|
+
'private/create-subaccount-transfer': 10 / 3,
|
271
|
+
'private/otc/get-otc-user': 10 / 3,
|
272
|
+
'private/otc/get-instruments': 10 / 3,
|
273
|
+
'private/otc/request-quote': 100,
|
274
|
+
'private/otc/accept-quote': 100,
|
275
|
+
'private/otc/get-quote-history': 10 / 3,
|
276
|
+
'private/otc/get-trade-history': 10 / 3,
|
277
|
+
'private/otc/create-order': 10 / 3,
|
278
|
+
},
|
279
|
+
},
|
280
|
+
},
|
281
|
+
'derivatives': {
|
282
|
+
'public': {
|
283
|
+
'get': {
|
284
|
+
'public/auth': 10 / 3,
|
285
|
+
'public/get-instruments': 10 / 3,
|
286
|
+
'public/get-book': 1,
|
287
|
+
'public/get-candlestick': 1,
|
288
|
+
'public/get-trades': 1,
|
289
|
+
'public/get-tickers': 1,
|
290
|
+
'public/get-valuations': 1,
|
291
|
+
'public/get-expired-settlement-price': 10 / 3,
|
292
|
+
'public/get-insurance': 1,
|
293
|
+
},
|
294
|
+
},
|
295
|
+
'private': {
|
296
|
+
'post': {
|
297
|
+
'private/set-cancel-on-disconnect': 10 / 3,
|
298
|
+
'private/get-cancel-on-disconnect': 10 / 3,
|
299
|
+
'private/user-balance': 10 / 3,
|
300
|
+
'private/user-balance-history': 10 / 3,
|
301
|
+
'private/get-positions': 10 / 3,
|
302
|
+
'private/create-order': 2 / 3,
|
303
|
+
'private/create-order-list': 10 / 3,
|
304
|
+
'private/cancel-order': 2 / 3,
|
305
|
+
'private/cancel-order-list': 10 / 3,
|
306
|
+
'private/cancel-all-orders': 2 / 3,
|
307
|
+
'private/close-position': 10 / 3,
|
308
|
+
'private/convert-collateral': 10 / 3,
|
309
|
+
'private/get-order-history': 100,
|
310
|
+
'private/get-open-orders': 10 / 3,
|
311
|
+
'private/get-order-detail': 1 / 3,
|
312
|
+
'private/get-trades': 100,
|
313
|
+
'private/change-account-leverage': 10 / 3,
|
314
|
+
'private/get-transactions': 10 / 3,
|
315
|
+
'private/create-subaccount-transfer': 10 / 3,
|
316
|
+
'private/get-subaccount-balances': 10 / 3,
|
317
|
+
'private/get-order-list': 10 / 3,
|
318
|
+
},
|
319
|
+
},
|
320
|
+
},
|
321
|
+
},
|
322
|
+
'fees': {
|
323
|
+
'trading': {
|
324
|
+
'maker': self.parse_number('0.004'),
|
325
|
+
'taker': self.parse_number('0.004'),
|
326
|
+
'tiers': {
|
327
|
+
'maker': [
|
328
|
+
[self.parse_number('0'), self.parse_number('0.004')],
|
329
|
+
[self.parse_number('25000'), self.parse_number('0.0035')],
|
330
|
+
[self.parse_number('50000'), self.parse_number('0.0015')],
|
331
|
+
[self.parse_number('100000'), self.parse_number('0.001')],
|
332
|
+
[self.parse_number('250000'), self.parse_number('0.0009')],
|
333
|
+
[self.parse_number('1000000'), self.parse_number('0.0008')],
|
334
|
+
[self.parse_number('20000000'), self.parse_number('0.0007')],
|
335
|
+
[self.parse_number('100000000'), self.parse_number('0.0006')],
|
336
|
+
[self.parse_number('200000000'), self.parse_number('0.0004')],
|
337
|
+
],
|
338
|
+
'taker': [
|
339
|
+
[self.parse_number('0'), self.parse_number('0.004')],
|
340
|
+
[self.parse_number('25000'), self.parse_number('0.0035')],
|
341
|
+
[self.parse_number('50000'), self.parse_number('0.0025')],
|
342
|
+
[self.parse_number('100000'), self.parse_number('0.0016')],
|
343
|
+
[self.parse_number('250000'), self.parse_number('0.00015')],
|
344
|
+
[self.parse_number('1000000'), self.parse_number('0.00014')],
|
345
|
+
[self.parse_number('20000000'), self.parse_number('0.00013')],
|
346
|
+
[self.parse_number('100000000'), self.parse_number('0.00012')],
|
347
|
+
[self.parse_number('200000000'), self.parse_number('0.0001')],
|
348
|
+
],
|
349
|
+
},
|
350
|
+
},
|
351
|
+
},
|
352
|
+
'options': {
|
353
|
+
'defaultType': 'spot',
|
354
|
+
'accountsById': {
|
355
|
+
'funding': 'SPOT',
|
356
|
+
'spot': 'SPOT',
|
357
|
+
'margin': 'MARGIN',
|
358
|
+
'derivatives': 'DERIVATIVES',
|
359
|
+
'swap': 'DERIVATIVES',
|
360
|
+
'future': 'DERIVATIVES',
|
361
|
+
},
|
362
|
+
'networks': {
|
363
|
+
'BEP20': 'BSC',
|
364
|
+
'ERC20': 'ETH',
|
365
|
+
'TRC20': 'TRON',
|
366
|
+
},
|
367
|
+
'broker': 'CCXT',
|
368
|
+
},
|
369
|
+
'features': {
|
370
|
+
'default': {
|
371
|
+
'sandbox': True,
|
372
|
+
'createOrder': {
|
373
|
+
'marginMode': True,
|
374
|
+
'triggerPrice': True,
|
375
|
+
# todo: implementation fix
|
376
|
+
'triggerPriceType': {
|
377
|
+
'last': True,
|
378
|
+
'mark': True,
|
379
|
+
'index': True,
|
380
|
+
},
|
381
|
+
'triggerDirection': False,
|
382
|
+
'stopLossPrice': True,
|
383
|
+
'takeProfitPrice': True,
|
384
|
+
'attachedStopLossTakeProfit': None,
|
385
|
+
'timeInForce': {
|
386
|
+
'IOC': True,
|
387
|
+
'FOK': True,
|
388
|
+
'PO': True,
|
389
|
+
'GTD': False,
|
390
|
+
},
|
391
|
+
'hedged': False,
|
392
|
+
'selfTradePrevention': True, # todo: implement
|
393
|
+
'trailing': False,
|
394
|
+
'iceberg': False,
|
395
|
+
'leverage': False,
|
396
|
+
'marketBuyByCost': True,
|
397
|
+
'marketBuyRequiresPrice': True,
|
398
|
+
},
|
399
|
+
'createOrders': {
|
400
|
+
'max': 10,
|
401
|
+
},
|
402
|
+
'fetchMyTrades': {
|
403
|
+
'marginMode': False,
|
404
|
+
'limit': 100,
|
405
|
+
'daysBack': None,
|
406
|
+
'untilDays': 1,
|
407
|
+
'symbolRequired': False,
|
408
|
+
},
|
409
|
+
'fetchOrder': {
|
410
|
+
'marginMode': False,
|
411
|
+
'trigger': False,
|
412
|
+
'trailing': False,
|
413
|
+
'symbolRequired': False,
|
414
|
+
},
|
415
|
+
'fetchOpenOrders': {
|
416
|
+
'marginMode': True,
|
417
|
+
'limit': 100,
|
418
|
+
'trigger': False,
|
419
|
+
'trailing': False,
|
420
|
+
'symbolRequired': False,
|
421
|
+
},
|
422
|
+
'fetchOrders': {
|
423
|
+
'marginMode': False,
|
424
|
+
'limit': 100,
|
425
|
+
'daysBack': None,
|
426
|
+
'untilDays': 1,
|
427
|
+
'trigger': False,
|
428
|
+
'trailing': False,
|
429
|
+
'symbolRequired': False,
|
430
|
+
},
|
431
|
+
'fetchClosedOrders': {
|
432
|
+
'marginMode': False,
|
433
|
+
'limit': 100,
|
434
|
+
'daysBack': None,
|
435
|
+
'daysBackCanceled': None,
|
436
|
+
'untilDays': 1,
|
437
|
+
'trigger': False,
|
438
|
+
'trailing': False,
|
439
|
+
'symbolRequired': False,
|
440
|
+
},
|
441
|
+
'fetchOHLCV': {
|
442
|
+
'limit': 300,
|
443
|
+
},
|
444
|
+
},
|
445
|
+
'spot': {
|
446
|
+
'extends': 'default',
|
447
|
+
},
|
448
|
+
'swap': {
|
449
|
+
'linear': {
|
450
|
+
'extends': 'default',
|
451
|
+
},
|
452
|
+
'inverse': {
|
453
|
+
'extends': 'default',
|
454
|
+
},
|
455
|
+
},
|
456
|
+
'future': {
|
457
|
+
'linear': {
|
458
|
+
'extends': 'default',
|
459
|
+
},
|
460
|
+
'inverse': {
|
461
|
+
'extends': 'default',
|
462
|
+
},
|
463
|
+
},
|
464
|
+
},
|
465
|
+
# https://exchange-docs.crypto.com/spot/index.html#response-and-reason-codes
|
466
|
+
'commonCurrencies': {
|
467
|
+
'USD_STABLE_COIN': 'USDC',
|
468
|
+
},
|
469
|
+
'precisionMode': TICK_SIZE,
|
470
|
+
'exceptions': {
|
471
|
+
'exact': {
|
472
|
+
'219': InvalidOrder,
|
473
|
+
'314': InvalidOrder, # {"id" : 1700xxx, "method" : "private/create-order", "code" : 314, "message" : "EXCEEDS_MAX_ORDER_SIZE", "result" : {"client_oid" : "1700xxx", "order_id" : "6530xxx"}}
|
474
|
+
'325': InvalidOrder, # {"id" : 1741xxx, "method" : "private/create-order", "code" : 325, "message" : "EXCEED_DAILY_VOL_LIMIT", "result" : {"client_oid" : "1741xxx", "order_id" : "6530xxx"}}
|
475
|
+
'415': InvalidOrder, # {"id" : 1741xxx, "method" : "private/create-order", "code" : 415, "message" : "BELOW_MIN_ORDER_SIZE", "result" : {"client_oid" : "1741xxx", "order_id" : "6530xxx"}}
|
476
|
+
'10001': ExchangeError,
|
477
|
+
'10002': PermissionDenied,
|
478
|
+
'10003': PermissionDenied,
|
479
|
+
'10004': BadRequest,
|
480
|
+
'10005': PermissionDenied,
|
481
|
+
'10006': DDoSProtection,
|
482
|
+
'10007': InvalidNonce,
|
483
|
+
'10008': BadRequest,
|
484
|
+
'10009': BadRequest,
|
485
|
+
'20001': BadRequest,
|
486
|
+
'20002': InsufficientFunds,
|
487
|
+
'20005': AccountNotEnabled, # {"id":"123xxx","method":"private/margin/xxx","code":"20005","message":"ACCOUNT_NOT_FOUND"}
|
488
|
+
'30003': BadSymbol,
|
489
|
+
'30004': BadRequest,
|
490
|
+
'30005': BadRequest,
|
491
|
+
'30006': InvalidOrder,
|
492
|
+
'30007': InvalidOrder,
|
493
|
+
'30008': InvalidOrder,
|
494
|
+
'30009': InvalidOrder,
|
495
|
+
'30010': BadRequest,
|
496
|
+
'30013': InvalidOrder,
|
497
|
+
'30014': InvalidOrder,
|
498
|
+
'30016': InvalidOrder,
|
499
|
+
'30017': InvalidOrder,
|
500
|
+
'30023': InvalidOrder,
|
501
|
+
'30024': InvalidOrder,
|
502
|
+
'30025': InvalidOrder,
|
503
|
+
'40001': BadRequest,
|
504
|
+
'40002': BadRequest,
|
505
|
+
'40003': BadRequest,
|
506
|
+
'40004': BadRequest,
|
507
|
+
'40005': BadRequest,
|
508
|
+
'40006': BadRequest,
|
509
|
+
'40007': BadRequest,
|
510
|
+
'40101': AuthenticationError,
|
511
|
+
'40102': InvalidNonce, # Nonce value differs by more than 60 seconds from server
|
512
|
+
'40103': AuthenticationError, # IP address not whitelisted
|
513
|
+
'40104': AuthenticationError, # Disallowed based on user tier
|
514
|
+
'40107': BadRequest, # Session subscription limit has been exceeded
|
515
|
+
'40401': OrderNotFound,
|
516
|
+
'40801': RequestTimeout,
|
517
|
+
'42901': RateLimitExceeded,
|
518
|
+
'43005': InvalidOrder, # Rejected POST_ONLY create-order request(normally happened when exec_inst contains POST_ONLY but time_in_force is NOT GOOD_TILL_CANCEL)
|
519
|
+
'43003': InvalidOrder, # FOK order has not been filled and cancelled
|
520
|
+
'43004': InvalidOrder, # IOC order has not been filled and cancelled
|
521
|
+
'43012': BadRequest, # Canceled due to Self Trade Prevention
|
522
|
+
'50001': ExchangeError,
|
523
|
+
'9010001': OnMaintenance, # {"code":9010001,"message":"SYSTEM_MAINTENANCE","details":"Crypto.com Exchange is currently under maintenance. Please refer to https://status.crypto.com for more details."}
|
524
|
+
},
|
525
|
+
'broad': {},
|
526
|
+
},
|
527
|
+
})
|
528
|
+
|
529
|
+
def fetch_markets(self, params={}) -> List[Market]:
|
530
|
+
"""
|
531
|
+
|
532
|
+
https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#public-get-instruments
|
533
|
+
|
534
|
+
retrieves data on all markets for cryptocom
|
535
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
536
|
+
:returns dict[]: an array of objects representing market data
|
537
|
+
"""
|
538
|
+
response = self.v1PublicGetPublicGetInstruments(params)
|
539
|
+
#
|
540
|
+
# {
|
541
|
+
# "id": 1,
|
542
|
+
# "method": "public/get-instruments",
|
543
|
+
# "code": 0,
|
544
|
+
# "result": {
|
545
|
+
# "data": [
|
546
|
+
# {
|
547
|
+
# "symbol": "BTC_USDT",
|
548
|
+
# "inst_type": "CCY_PAIR",
|
549
|
+
# "display_name": "BTC/USDT",
|
550
|
+
# "base_ccy": "BTC",
|
551
|
+
# "quote_ccy": "USDT",
|
552
|
+
# "quote_decimals": 2,
|
553
|
+
# "quantity_decimals": 5,
|
554
|
+
# "price_tick_size": "0.01",
|
555
|
+
# "qty_tick_size": "0.00001",
|
556
|
+
# "max_leverage": "50",
|
557
|
+
# "tradable": True,
|
558
|
+
# "expiry_timestamp_ms": 0,
|
559
|
+
# "beta_product": False,
|
560
|
+
# "margin_buy_enabled": False,
|
561
|
+
# "margin_sell_enabled": True
|
562
|
+
# },
|
563
|
+
# {
|
564
|
+
# "symbol": "RUNEUSD-PERP",
|
565
|
+
# "inst_type": "PERPETUAL_SWAP",
|
566
|
+
# "display_name": "RUNEUSD Perpetual",
|
567
|
+
# "base_ccy": "RUNE",
|
568
|
+
# "quote_ccy": "USD",
|
569
|
+
# "quote_decimals": 3,
|
570
|
+
# "quantity_decimals": 1,
|
571
|
+
# "price_tick_size": "0.001",
|
572
|
+
# "qty_tick_size": "0.1",
|
573
|
+
# "max_leverage": "50",
|
574
|
+
# "tradable": True,
|
575
|
+
# "expiry_timestamp_ms": 0,
|
576
|
+
# "beta_product": False,
|
577
|
+
# "underlying_symbol": "RUNEUSD-INDEX",
|
578
|
+
# "contract_size": "1",
|
579
|
+
# "margin_buy_enabled": False,
|
580
|
+
# "margin_sell_enabled": False
|
581
|
+
# },
|
582
|
+
# {
|
583
|
+
# "symbol": "ETHUSD-230825",
|
584
|
+
# "inst_type": "FUTURE",
|
585
|
+
# "display_name": "ETHUSD Futures 20230825",
|
586
|
+
# "base_ccy": "ETH",
|
587
|
+
# "quote_ccy": "USD",
|
588
|
+
# "quote_decimals": 2,
|
589
|
+
# "quantity_decimals": 4,
|
590
|
+
# "price_tick_size": "0.01",
|
591
|
+
# "qty_tick_size": "0.0001",
|
592
|
+
# "max_leverage": "100",
|
593
|
+
# "tradable": True,
|
594
|
+
# "expiry_timestamp_ms": 1692950400000,
|
595
|
+
# "beta_product": False,
|
596
|
+
# "underlying_symbol": "ETHUSD-INDEX",
|
597
|
+
# "contract_size": "1",
|
598
|
+
# "margin_buy_enabled": False,
|
599
|
+
# "margin_sell_enabled": False
|
600
|
+
# },
|
601
|
+
# {
|
602
|
+
# "symbol": "BTCUSD-230630-CW30000",
|
603
|
+
# "inst_type": "WARRANT",
|
604
|
+
# "display_name": "BTCUSD-230630-CW30000",
|
605
|
+
# "base_ccy": "BTC",
|
606
|
+
# "quote_ccy": "USD",
|
607
|
+
# "quote_decimals": 3,
|
608
|
+
# "quantity_decimals": 0,
|
609
|
+
# "price_tick_size": "0.001",
|
610
|
+
# "qty_tick_size": "10",
|
611
|
+
# "max_leverage": "50",
|
612
|
+
# "tradable": True,
|
613
|
+
# "expiry_timestamp_ms": 1688112000000,
|
614
|
+
# "beta_product": False,
|
615
|
+
# "underlying_symbol": "BTCUSD-INDEX",
|
616
|
+
# "put_call": "CALL",
|
617
|
+
# "strike": "30000",
|
618
|
+
# "contract_size": "0.0001",
|
619
|
+
# "margin_buy_enabled": False,
|
620
|
+
# "margin_sell_enabled": False
|
621
|
+
# },
|
622
|
+
# ]
|
623
|
+
# }
|
624
|
+
# }
|
625
|
+
#
|
626
|
+
resultResponse = self.safe_dict(response, 'result', {})
|
627
|
+
data = self.safe_list(resultResponse, 'data', [])
|
628
|
+
result = []
|
629
|
+
for i in range(0, len(data)):
|
630
|
+
market = data[i]
|
631
|
+
inst_type = self.safe_string(market, 'inst_type')
|
632
|
+
spot = inst_type == 'CCY_PAIR'
|
633
|
+
swap = inst_type == 'PERPETUAL_SWAP'
|
634
|
+
future = inst_type == 'FUTURE'
|
635
|
+
option = inst_type == 'WARRANT'
|
636
|
+
baseId = self.safe_string(market, 'base_ccy')
|
637
|
+
quoteId = self.safe_string(market, 'quote_ccy')
|
638
|
+
settleId = None if spot else quoteId
|
639
|
+
base = self.safe_currency_code(baseId)
|
640
|
+
quote = self.safe_currency_code(quoteId)
|
641
|
+
settle = None if spot else self.safe_currency_code(settleId)
|
642
|
+
optionType = self.safe_string_lower(market, 'put_call')
|
643
|
+
strike = self.safe_string(market, 'strike')
|
644
|
+
marginBuyEnabled = self.safe_bool(market, 'margin_buy_enabled')
|
645
|
+
marginSellEnabled = self.safe_bool(market, 'margin_sell_enabled')
|
646
|
+
expiryString = self.omit_zero(self.safe_string(market, 'expiry_timestamp_ms'))
|
647
|
+
expiry = int(expiryString) if (expiryString is not None) else None
|
648
|
+
symbol = base + '/' + quote
|
649
|
+
type = None
|
650
|
+
contract = None
|
651
|
+
if inst_type == 'CCY_PAIR':
|
652
|
+
type = 'spot'
|
653
|
+
contract = False
|
654
|
+
elif inst_type == 'PERPETUAL_SWAP':
|
655
|
+
type = 'swap'
|
656
|
+
symbol = symbol + ':' + quote
|
657
|
+
contract = True
|
658
|
+
elif inst_type == 'FUTURE':
|
659
|
+
type = 'future'
|
660
|
+
symbol = symbol + ':' + quote + '-' + self.yymmdd(expiry)
|
661
|
+
contract = True
|
662
|
+
elif inst_type == 'WARRANT':
|
663
|
+
type = 'option'
|
664
|
+
symbolOptionType = 'C' if (optionType == 'call') else 'P'
|
665
|
+
symbol = symbol + ':' + quote + '-' + self.yymmdd(expiry) + '-' + strike + '-' + symbolOptionType
|
666
|
+
contract = True
|
667
|
+
result.append({
|
668
|
+
'id': self.safe_string(market, 'symbol'),
|
669
|
+
'symbol': symbol,
|
670
|
+
'base': base,
|
671
|
+
'quote': quote,
|
672
|
+
'settle': settle,
|
673
|
+
'baseId': baseId,
|
674
|
+
'quoteId': quoteId,
|
675
|
+
'settleId': settleId,
|
676
|
+
'type': type,
|
677
|
+
'spot': spot,
|
678
|
+
'margin': ((marginBuyEnabled) or (marginSellEnabled)),
|
679
|
+
'swap': swap,
|
680
|
+
'future': future,
|
681
|
+
'option': option,
|
682
|
+
'active': self.safe_bool(market, 'tradable'),
|
683
|
+
'contract': contract,
|
684
|
+
'linear': True if (contract) else None,
|
685
|
+
'inverse': False if (contract) else None,
|
686
|
+
'contractSize': self.safe_number(market, 'contract_size'),
|
687
|
+
'expiry': expiry,
|
688
|
+
'expiryDatetime': self.iso8601(expiry),
|
689
|
+
'strike': self.parse_number(strike),
|
690
|
+
'optionType': optionType,
|
691
|
+
'precision': {
|
692
|
+
'price': self.parse_number(self.safe_string(market, 'price_tick_size')),
|
693
|
+
'amount': self.parse_number(self.safe_string(market, 'qty_tick_size')),
|
694
|
+
},
|
695
|
+
'limits': {
|
696
|
+
'leverage': {
|
697
|
+
'min': self.parse_number('1'),
|
698
|
+
'max': self.safe_number(market, 'max_leverage'),
|
699
|
+
},
|
700
|
+
'amount': {
|
701
|
+
'min': None,
|
702
|
+
'max': None,
|
703
|
+
},
|
704
|
+
'price': {
|
705
|
+
'min': None,
|
706
|
+
'max': None,
|
707
|
+
},
|
708
|
+
'cost': {
|
709
|
+
'min': None,
|
710
|
+
'max': None,
|
711
|
+
},
|
712
|
+
},
|
713
|
+
'created': None,
|
714
|
+
'info': market,
|
715
|
+
})
|
716
|
+
return result
|
717
|
+
|
718
|
+
def fetch_tickers(self, symbols: Strings = None, params={}) -> Tickers:
|
719
|
+
"""
|
720
|
+
fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
|
721
|
+
|
722
|
+
https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#public-get-tickers
|
723
|
+
https://exchange-docs.crypto.com/derivatives/index.html#public-get-tickers
|
724
|
+
|
725
|
+
:param str[]|None symbols: unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
|
726
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
727
|
+
:returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
|
728
|
+
"""
|
729
|
+
self.load_markets()
|
730
|
+
market = None
|
731
|
+
request: dict = {}
|
732
|
+
if symbols is not None:
|
733
|
+
symbol = None
|
734
|
+
if isinstance(symbols, list):
|
735
|
+
symbolsLength = len(symbols)
|
736
|
+
if symbolsLength > 1:
|
737
|
+
raise BadRequest(self.id + ' fetchTickers() symbols argument cannot contain more than 1 symbol')
|
738
|
+
symbol = symbols[0]
|
739
|
+
else:
|
740
|
+
symbol = symbols
|
741
|
+
market = self.market(symbol)
|
742
|
+
request['instrument_name'] = market['id']
|
743
|
+
response = self.v1PublicGetPublicGetTickers(self.extend(request, params))
|
744
|
+
#
|
745
|
+
# {
|
746
|
+
# "id": -1,
|
747
|
+
# "method": "public/get-tickers",
|
748
|
+
# "code": 0,
|
749
|
+
# "result": {
|
750
|
+
# "data": [
|
751
|
+
# {
|
752
|
+
# "i": "AVAXUSD-PERP",
|
753
|
+
# "h": "13.209",
|
754
|
+
# "l": "12.148",
|
755
|
+
# "a": "13.209",
|
756
|
+
# "v": "1109.8",
|
757
|
+
# "vv": "14017.33",
|
758
|
+
# "c": "0.0732",
|
759
|
+
# "b": "13.210",
|
760
|
+
# "k": "13.230",
|
761
|
+
# "oi": "10888.9",
|
762
|
+
# "t": 1687402657575
|
763
|
+
# },
|
764
|
+
# ]
|
765
|
+
# }
|
766
|
+
# }
|
767
|
+
#
|
768
|
+
result = self.safe_dict(response, 'result', {})
|
769
|
+
data = self.safe_list(result, 'data', [])
|
770
|
+
return self.parse_tickers(data, symbols)
|
771
|
+
|
772
|
+
def fetch_ticker(self, symbol: str, params={}) -> Ticker:
|
773
|
+
"""
|
774
|
+
|
775
|
+
https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#public-get-tickers
|
776
|
+
|
777
|
+
fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
|
778
|
+
:param str symbol: unified symbol of the market to fetch the ticker for
|
779
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
780
|
+
:returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
|
781
|
+
"""
|
782
|
+
self.load_markets()
|
783
|
+
symbol = self.symbol(symbol)
|
784
|
+
tickers = self.fetch_tickers([symbol], params)
|
785
|
+
return self.safe_value(tickers, symbol)
|
786
|
+
|
787
|
+
def fetch_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Order]:
|
788
|
+
"""
|
789
|
+
fetches information on multiple orders made by the user
|
790
|
+
|
791
|
+
https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-get-order-history
|
792
|
+
|
793
|
+
:param str symbol: unified market symbol of the market the orders were made in
|
794
|
+
:param int [since]: the earliest time in ms to fetch orders for, max date range is one day
|
795
|
+
:param int [limit]: the maximum number of order structures to retrieve, default 100 max 100
|
796
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
797
|
+
:param int [params.until]: timestamp in ms for the ending date filter, default is the current time
|
798
|
+
:param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
|
799
|
+
:returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
|
800
|
+
"""
|
801
|
+
self.load_markets()
|
802
|
+
paginate = False
|
803
|
+
paginate, params = self.handle_option_and_params(params, 'fetchOrders', 'paginate')
|
804
|
+
if paginate:
|
805
|
+
return self.fetch_paginated_call_dynamic('fetchOrders', symbol, since, limit, params)
|
806
|
+
market = None
|
807
|
+
request: dict = {}
|
808
|
+
if symbol is not None:
|
809
|
+
market = self.market(symbol)
|
810
|
+
request['instrument_name'] = market['id']
|
811
|
+
if since is not None:
|
812
|
+
request['start_time'] = since
|
813
|
+
if limit is not None:
|
814
|
+
request['limit'] = limit
|
815
|
+
until = self.safe_integer(params, 'until')
|
816
|
+
params = self.omit(params, ['until'])
|
817
|
+
if until is not None:
|
818
|
+
request['end_time'] = until
|
819
|
+
response = self.v1PrivatePostPrivateGetOrderHistory(self.extend(request, params))
|
820
|
+
#
|
821
|
+
# {
|
822
|
+
# "id": 1686881486183,
|
823
|
+
# "method": "private/get-order-history",
|
824
|
+
# "code": 0,
|
825
|
+
# "result": {
|
826
|
+
# "data": [
|
827
|
+
# {
|
828
|
+
# "account_id": "ce075bef-1234-4321-bd6g-ff9007252e63",
|
829
|
+
# "order_id": "6142909895014042762",
|
830
|
+
# "client_oid": "4e918597-1234-4321-8201-a7577e1e1d91",
|
831
|
+
# "order_type": "MARKET",
|
832
|
+
# "time_in_force": "GOOD_TILL_CANCEL",
|
833
|
+
# "side": "SELL",
|
834
|
+
# "exec_inst": [],
|
835
|
+
# "quantity": "0.00024",
|
836
|
+
# "order_value": "5.7054672",
|
837
|
+
# "maker_fee_rate": "0",
|
838
|
+
# "taker_fee_rate": "0",
|
839
|
+
# "avg_price": "25023.97",
|
840
|
+
# "trigger_price": "0",
|
841
|
+
# "ref_price": "0",
|
842
|
+
# "ref_price_type": "NULL_VAL",
|
843
|
+
# "cumulative_quantity": "0.00024",
|
844
|
+
# "cumulative_value": "6.0057528",
|
845
|
+
# "cumulative_fee": "0.001501438200",
|
846
|
+
# "status": "FILLED",
|
847
|
+
# "update_user_id": "ce075bef-1234-4321-bd6g-ff9007252e63",
|
848
|
+
# "order_date": "2023-06-15",
|
849
|
+
# "instrument_name": "BTC_USD",
|
850
|
+
# "fee_instrument_name": "USD",
|
851
|
+
# "create_time": 1686805465891,
|
852
|
+
# "create_time_ns": "1686805465891812578",
|
853
|
+
# "update_time": 1686805465891
|
854
|
+
# }
|
855
|
+
# ]
|
856
|
+
# }
|
857
|
+
# }
|
858
|
+
#
|
859
|
+
data = self.safe_dict(response, 'result', {})
|
860
|
+
orders = self.safe_list(data, 'data', [])
|
861
|
+
return self.parse_orders(orders, market, since, limit)
|
862
|
+
|
863
|
+
def fetch_trades(self, symbol: str, since: Int = None, limit: Int = None, params={}) -> List[Trade]:
|
864
|
+
"""
|
865
|
+
get a list of the most recent trades for a particular symbol
|
866
|
+
|
867
|
+
https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#public-get-trades
|
868
|
+
|
869
|
+
:param str symbol: unified symbol of the market to fetch trades for
|
870
|
+
:param int [since]: timestamp in ms of the earliest trade to fetch, maximum date range is one day
|
871
|
+
:param int [limit]: the maximum number of trades to fetch
|
872
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
873
|
+
:param int [params.until]: timestamp in ms for the ending date filter, default is the current time
|
874
|
+
:param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
|
875
|
+
:returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
|
876
|
+
"""
|
877
|
+
self.load_markets()
|
878
|
+
paginate = False
|
879
|
+
paginate, params = self.handle_option_and_params(params, 'fetchTrades', 'paginate')
|
880
|
+
if paginate:
|
881
|
+
return self.fetch_paginated_call_dynamic('fetchTrades', symbol, since, limit, params)
|
882
|
+
market = self.market(symbol)
|
883
|
+
request: dict = {
|
884
|
+
'instrument_name': market['id'],
|
885
|
+
}
|
886
|
+
if since is not None:
|
887
|
+
request['start_ts'] = since
|
888
|
+
if limit is not None:
|
889
|
+
request['count'] = limit
|
890
|
+
until = self.safe_integer(params, 'until')
|
891
|
+
params = self.omit(params, ['until'])
|
892
|
+
if until is not None:
|
893
|
+
request['end_ts'] = until
|
894
|
+
response = self.v1PublicGetPublicGetTrades(self.extend(request, params))
|
895
|
+
#
|
896
|
+
# {
|
897
|
+
# "id": -1,
|
898
|
+
# "method": "public/get-trades",
|
899
|
+
# "code": 0,
|
900
|
+
# "result": {
|
901
|
+
# "data": [
|
902
|
+
# {
|
903
|
+
# "s": "sell",
|
904
|
+
# "p": "26386.00",
|
905
|
+
# "q": "0.00453",
|
906
|
+
# "t": 1686944282062,
|
907
|
+
# "tn" : 1704476468851524373,
|
908
|
+
# "d": "4611686018455979970",
|
909
|
+
# "i": "BTC_USD"
|
910
|
+
# },
|
911
|
+
# ]
|
912
|
+
# }
|
913
|
+
# }
|
914
|
+
#
|
915
|
+
result = self.safe_dict(response, 'result', {})
|
916
|
+
trades = self.safe_list(result, 'data', [])
|
917
|
+
return self.parse_trades(trades, market, since, limit)
|
918
|
+
|
919
|
+
def fetch_ohlcv(self, symbol: str, timeframe='1m', since: Int = None, limit: Int = None, params={}) -> List[list]:
|
920
|
+
"""
|
921
|
+
fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
|
922
|
+
|
923
|
+
https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#public-get-candlestick
|
924
|
+
|
925
|
+
:param str symbol: unified symbol of the market to fetch OHLCV data for
|
926
|
+
:param str timeframe: the length of time each candle represents
|
927
|
+
:param int [since]: timestamp in ms of the earliest candle to fetch
|
928
|
+
:param int [limit]: the maximum amount of candles to fetch
|
929
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
930
|
+
:param int [params.until]: timestamp in ms for the ending date filter, default is the current time
|
931
|
+
:param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
|
932
|
+
:returns int[][]: A list of candles ordered, open, high, low, close, volume
|
933
|
+
"""
|
934
|
+
self.load_markets()
|
935
|
+
paginate = False
|
936
|
+
paginate, params = self.handle_option_and_params(params, 'fetchOHLCV', 'paginate', False)
|
937
|
+
if paginate:
|
938
|
+
return self.fetch_paginated_call_deterministic('fetchOHLCV', symbol, since, limit, timeframe, params, 300)
|
939
|
+
market = self.market(symbol)
|
940
|
+
request: dict = {
|
941
|
+
'instrument_name': market['id'],
|
942
|
+
'timeframe': self.safe_string(self.timeframes, timeframe, timeframe),
|
943
|
+
}
|
944
|
+
if limit is not None:
|
945
|
+
if limit > 300:
|
946
|
+
limit = 300
|
947
|
+
request['count'] = limit
|
948
|
+
now = self.microseconds()
|
949
|
+
duration = self.parse_timeframe(timeframe)
|
950
|
+
until = self.safe_integer(params, 'until', now)
|
951
|
+
params = self.omit(params, ['until'])
|
952
|
+
if since is not None:
|
953
|
+
request['start_ts'] = since - duration * 1000
|
954
|
+
if limit is not None:
|
955
|
+
request['end_ts'] = self.sum(since, duration * limit * 1000)
|
956
|
+
else:
|
957
|
+
request['end_ts'] = until
|
958
|
+
else:
|
959
|
+
request['end_ts'] = until
|
960
|
+
response = self.v1PublicGetPublicGetCandlestick(self.extend(request, params))
|
961
|
+
#
|
962
|
+
# {
|
963
|
+
# "id": -1,
|
964
|
+
# "method": "public/get-candlestick",
|
965
|
+
# "code": 0,
|
966
|
+
# "result": {
|
967
|
+
# "interval": "1m",
|
968
|
+
# "data": [
|
969
|
+
# {
|
970
|
+
# "o": "26949.89",
|
971
|
+
# "h": "26957.64",
|
972
|
+
# "l": "26948.24",
|
973
|
+
# "c": "26950.00",
|
974
|
+
# "v": "0.0670",
|
975
|
+
# "t": 1687237080000
|
976
|
+
# },
|
977
|
+
# ],
|
978
|
+
# "instrument_name": "BTC_USD"
|
979
|
+
# }
|
980
|
+
# }
|
981
|
+
#
|
982
|
+
result = self.safe_dict(response, 'result', {})
|
983
|
+
data = self.safe_list(result, 'data', [])
|
984
|
+
return self.parse_ohlcvs(data, market, timeframe, since, limit)
|
985
|
+
|
986
|
+
def fetch_order_book(self, symbol: str, limit: Int = None, params={}) -> OrderBook:
|
987
|
+
"""
|
988
|
+
fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
|
989
|
+
|
990
|
+
https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#public-get-book
|
991
|
+
|
992
|
+
:param str symbol: unified symbol of the market to fetch the order book for
|
993
|
+
:param int [limit]: the number of order book entries to return, max 50
|
994
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
995
|
+
:returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
|
996
|
+
"""
|
997
|
+
self.load_markets()
|
998
|
+
market = self.market(symbol)
|
999
|
+
request: dict = {
|
1000
|
+
'instrument_name': market['id'],
|
1001
|
+
}
|
1002
|
+
if limit:
|
1003
|
+
request['depth'] = limit
|
1004
|
+
response = self.v1PublicGetPublicGetBook(self.extend(request, params))
|
1005
|
+
#
|
1006
|
+
# {
|
1007
|
+
# "id": -1,
|
1008
|
+
# "method": "public/get-book",
|
1009
|
+
# "code": 0,
|
1010
|
+
# "result": {
|
1011
|
+
# "depth": 3,
|
1012
|
+
# "data": [
|
1013
|
+
# {
|
1014
|
+
# "bids": [["30025.00", "0.00004", "1"], ["30020.15", "0.02498", "1"], ["30020.00", "0.00004", "1"]],
|
1015
|
+
# "asks": [["30025.01", "0.04090", "1"], ["30025.70", "0.01000", "1"], ["30026.94", "0.02681", "1"]],
|
1016
|
+
# "t": 1687491287380
|
1017
|
+
# }
|
1018
|
+
# ],
|
1019
|
+
# "instrument_name": "BTC_USD"
|
1020
|
+
# }
|
1021
|
+
# }
|
1022
|
+
#
|
1023
|
+
result = self.safe_dict(response, 'result', {})
|
1024
|
+
data = self.safe_list(result, 'data', [])
|
1025
|
+
orderBook = self.safe_value(data, 0)
|
1026
|
+
timestamp = self.safe_integer(orderBook, 't')
|
1027
|
+
return self.parse_order_book(orderBook, symbol, timestamp)
|
1028
|
+
|
1029
|
+
def parse_balance(self, response) -> Balances:
|
1030
|
+
responseResult = self.safe_dict(response, 'result', {})
|
1031
|
+
data = self.safe_list(responseResult, 'data', [])
|
1032
|
+
positionBalances = self.safe_value(data[0], 'position_balances', [])
|
1033
|
+
result: dict = {'info': response}
|
1034
|
+
for i in range(0, len(positionBalances)):
|
1035
|
+
balance = positionBalances[i]
|
1036
|
+
currencyId = self.safe_string(balance, 'instrument_name')
|
1037
|
+
code = self.safe_currency_code(currencyId)
|
1038
|
+
account = self.account()
|
1039
|
+
account['total'] = self.safe_string(balance, 'quantity')
|
1040
|
+
account['used'] = self.safe_string(balance, 'reserved_qty')
|
1041
|
+
result[code] = account
|
1042
|
+
return self.safe_balance(result)
|
1043
|
+
|
1044
|
+
def fetch_balance(self, params={}) -> Balances:
|
1045
|
+
"""
|
1046
|
+
query for balance and get the amount of funds available for trading or funds locked in orders
|
1047
|
+
|
1048
|
+
https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-user-balance
|
1049
|
+
|
1050
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
1051
|
+
:returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
|
1052
|
+
"""
|
1053
|
+
self.load_markets()
|
1054
|
+
response = self.v1PrivatePostPrivateUserBalance(params)
|
1055
|
+
#
|
1056
|
+
# {
|
1057
|
+
# "id": 1687300499018,
|
1058
|
+
# "method": "private/user-balance",
|
1059
|
+
# "code": 0,
|
1060
|
+
# "result": {
|
1061
|
+
# "data": [
|
1062
|
+
# {
|
1063
|
+
# "total_available_balance": "5.84684368",
|
1064
|
+
# "total_margin_balance": "5.84684368",
|
1065
|
+
# "total_initial_margin": "0",
|
1066
|
+
# "total_maintenance_margin": "0",
|
1067
|
+
# "total_position_cost": "0",
|
1068
|
+
# "total_cash_balance": "6.44412101",
|
1069
|
+
# "total_collateral_value": "5.846843685",
|
1070
|
+
# "total_session_unrealized_pnl": "0",
|
1071
|
+
# "instrument_name": "USD",
|
1072
|
+
# "total_session_realized_pnl": "0",
|
1073
|
+
# "position_balances": [
|
1074
|
+
# {
|
1075
|
+
# "quantity": "0.0002119875",
|
1076
|
+
# "reserved_qty": "0",
|
1077
|
+
# "collateral_weight": "0.9",
|
1078
|
+
# "collateral_amount": "5.37549592",
|
1079
|
+
# "market_value": "5.97277325",
|
1080
|
+
# "max_withdrawal_balance": "0.00021198",
|
1081
|
+
# "instrument_name": "BTC",
|
1082
|
+
# "hourly_interest_rate": "0"
|
1083
|
+
# },
|
1084
|
+
# ],
|
1085
|
+
# "total_effective_leverage": "0",
|
1086
|
+
# "position_limit": "3000000",
|
1087
|
+
# "used_position_limit": "0",
|
1088
|
+
# "total_borrow": "0",
|
1089
|
+
# "margin_score": "0",
|
1090
|
+
# "is_liquidating": False,
|
1091
|
+
# "has_risk": False,
|
1092
|
+
# "terminatable": True
|
1093
|
+
# }
|
1094
|
+
# ]
|
1095
|
+
# }
|
1096
|
+
# }
|
1097
|
+
#
|
1098
|
+
return self.parse_balance(response)
|
1099
|
+
|
1100
|
+
def fetch_order(self, id: str, symbol: Str = None, params={}):
|
1101
|
+
"""
|
1102
|
+
fetches information on an order made by the user
|
1103
|
+
|
1104
|
+
https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-get-order-detail
|
1105
|
+
|
1106
|
+
:param str id: order id
|
1107
|
+
:param str symbol: unified symbol of the market the order was made in
|
1108
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
1109
|
+
:returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
|
1110
|
+
"""
|
1111
|
+
self.load_markets()
|
1112
|
+
market = None
|
1113
|
+
if symbol is not None:
|
1114
|
+
market = self.market(symbol)
|
1115
|
+
request: dict = {
|
1116
|
+
'order_id': id,
|
1117
|
+
}
|
1118
|
+
response = self.v1PrivatePostPrivateGetOrderDetail(self.extend(request, params))
|
1119
|
+
#
|
1120
|
+
# {
|
1121
|
+
# "id": 1686872583882,
|
1122
|
+
# "method": "private/get-order-detail",
|
1123
|
+
# "code": 0,
|
1124
|
+
# "result": {
|
1125
|
+
# "account_id": "ae075bef-1234-4321-bd6g-bb9007252a63",
|
1126
|
+
# "order_id": "6142909895025252686",
|
1127
|
+
# "client_oid": "CCXT_c2d2152cc32d40a3ae7fbf",
|
1128
|
+
# "order_type": "LIMIT",
|
1129
|
+
# "time_in_force": "GOOD_TILL_CANCEL",
|
1130
|
+
# "side": "BUY",
|
1131
|
+
# "exec_inst": [],
|
1132
|
+
# "quantity": "0.00020",
|
1133
|
+
# "limit_price": "20000.00",
|
1134
|
+
# "order_value": "4",
|
1135
|
+
# "avg_price": "0",
|
1136
|
+
# "trigger_price": "0",
|
1137
|
+
# "ref_price": "0",
|
1138
|
+
# "cumulative_quantity": "0",
|
1139
|
+
# "cumulative_value": "0",
|
1140
|
+
# "cumulative_fee": "0",
|
1141
|
+
# "status": "ACTIVE",
|
1142
|
+
# "update_user_id": "ae075bef-1234-4321-bd6g-bb9007252a63",
|
1143
|
+
# "order_date": "2023-06-15",
|
1144
|
+
# "instrument_name": "BTC_USD",
|
1145
|
+
# "fee_instrument_name": "BTC",
|
1146
|
+
# "create_time": 1686870220684,
|
1147
|
+
# "create_time_ns": "1686870220684239675",
|
1148
|
+
# "update_time": 1686870220684
|
1149
|
+
# }
|
1150
|
+
# }
|
1151
|
+
#
|
1152
|
+
order = self.safe_dict(response, 'result', {})
|
1153
|
+
return self.parse_order(order, market)
|
1154
|
+
|
1155
|
+
def create_order_request(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, params={}):
|
1156
|
+
market = self.market(symbol)
|
1157
|
+
uppercaseType = type.upper()
|
1158
|
+
request: dict = {
|
1159
|
+
'instrument_name': market['id'],
|
1160
|
+
'side': side.upper(),
|
1161
|
+
'quantity': self.amount_to_precision(symbol, amount),
|
1162
|
+
}
|
1163
|
+
if (uppercaseType == 'LIMIT') or (uppercaseType == 'STOP_LIMIT') or (uppercaseType == 'TAKE_PROFIT_LIMIT'):
|
1164
|
+
request['price'] = self.price_to_precision(symbol, price)
|
1165
|
+
broker = self.safe_string(self.options, 'broker', 'CCXT')
|
1166
|
+
request['broker_id'] = broker
|
1167
|
+
marketType = None
|
1168
|
+
marginMode = None
|
1169
|
+
marketType, params = self.handle_market_type_and_params('createOrder', market, params)
|
1170
|
+
marginMode, params = self.custom_handle_margin_mode_and_params('createOrder', params)
|
1171
|
+
if (marketType == 'margin') or (marginMode is not None):
|
1172
|
+
request['spot_margin'] = 'MARGIN'
|
1173
|
+
elif marketType == 'spot':
|
1174
|
+
request['spot_margin'] = 'SPOT'
|
1175
|
+
timeInForce = self.safe_string_upper_2(params, 'timeInForce', 'time_in_force')
|
1176
|
+
if timeInForce is not None:
|
1177
|
+
if timeInForce == 'GTC':
|
1178
|
+
request['time_in_force'] = 'GOOD_TILL_CANCEL'
|
1179
|
+
elif timeInForce == 'IOC':
|
1180
|
+
request['time_in_force'] = 'IMMEDIATE_OR_CANCEL'
|
1181
|
+
elif timeInForce == 'FOK':
|
1182
|
+
request['time_in_force'] = 'FILL_OR_KILL'
|
1183
|
+
else:
|
1184
|
+
request['time_in_force'] = timeInForce
|
1185
|
+
postOnly = self.safe_bool(params, 'postOnly', False)
|
1186
|
+
if (postOnly) or (timeInForce == 'PO'):
|
1187
|
+
request['exec_inst'] = ['POST_ONLY']
|
1188
|
+
request['time_in_force'] = 'GOOD_TILL_CANCEL'
|
1189
|
+
triggerPrice = self.safe_string_n(params, ['stopPrice', 'triggerPrice', 'ref_price'])
|
1190
|
+
stopLossPrice = self.safe_number(params, 'stopLossPrice')
|
1191
|
+
takeProfitPrice = self.safe_number(params, 'takeProfitPrice')
|
1192
|
+
isTrigger = (triggerPrice is not None)
|
1193
|
+
isStopLossTrigger = (stopLossPrice is not None)
|
1194
|
+
isTakeProfitTrigger = (takeProfitPrice is not None)
|
1195
|
+
if isTrigger:
|
1196
|
+
request['ref_price'] = self.price_to_precision(symbol, triggerPrice)
|
1197
|
+
priceString = self.number_to_string(price)
|
1198
|
+
if (uppercaseType == 'LIMIT') or (uppercaseType == 'STOP_LIMIT') or (uppercaseType == 'TAKE_PROFIT_LIMIT'):
|
1199
|
+
if side == 'buy':
|
1200
|
+
if Precise.string_lt(priceString, triggerPrice):
|
1201
|
+
request['type'] = 'TAKE_PROFIT_LIMIT'
|
1202
|
+
else:
|
1203
|
+
request['type'] = 'STOP_LIMIT'
|
1204
|
+
else:
|
1205
|
+
if Precise.string_lt(priceString, triggerPrice):
|
1206
|
+
request['type'] = 'STOP_LIMIT'
|
1207
|
+
else:
|
1208
|
+
request['type'] = 'TAKE_PROFIT_LIMIT'
|
1209
|
+
else:
|
1210
|
+
if side == 'buy':
|
1211
|
+
if Precise.string_lt(priceString, triggerPrice):
|
1212
|
+
request['type'] = 'TAKE_PROFIT'
|
1213
|
+
else:
|
1214
|
+
request['type'] = 'STOP_LOSS'
|
1215
|
+
else:
|
1216
|
+
if Precise.string_lt(priceString, triggerPrice):
|
1217
|
+
request['type'] = 'STOP_LOSS'
|
1218
|
+
else:
|
1219
|
+
request['type'] = 'TAKE_PROFIT'
|
1220
|
+
elif isStopLossTrigger:
|
1221
|
+
if (uppercaseType == 'LIMIT') or (uppercaseType == 'STOP_LIMIT'):
|
1222
|
+
request['type'] = 'STOP_LIMIT'
|
1223
|
+
else:
|
1224
|
+
request['type'] = 'STOP_LOSS'
|
1225
|
+
request['ref_price'] = self.price_to_precision(symbol, stopLossPrice)
|
1226
|
+
elif isTakeProfitTrigger:
|
1227
|
+
if (uppercaseType == 'LIMIT') or (uppercaseType == 'TAKE_PROFIT_LIMIT'):
|
1228
|
+
request['type'] = 'TAKE_PROFIT_LIMIT'
|
1229
|
+
else:
|
1230
|
+
request['type'] = 'TAKE_PROFIT'
|
1231
|
+
request['ref_price'] = self.price_to_precision(symbol, takeProfitPrice)
|
1232
|
+
else:
|
1233
|
+
request['type'] = uppercaseType
|
1234
|
+
params = self.omit(params, ['postOnly', 'clientOrderId', 'timeInForce', 'stopPrice', 'triggerPrice', 'stopLossPrice', 'takeProfitPrice'])
|
1235
|
+
return self.extend(request, params)
|
1236
|
+
|
1237
|
+
def create_order(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, params={}):
|
1238
|
+
"""
|
1239
|
+
create a trade order
|
1240
|
+
|
1241
|
+
https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-create-order
|
1242
|
+
|
1243
|
+
:param str symbol: unified symbol of the market to create an order in
|
1244
|
+
:param str type: 'market', 'limit', 'stop_loss', 'stop_limit', 'take_profit', 'take_profit_limit'
|
1245
|
+
:param str side: 'buy' or 'sell'
|
1246
|
+
:param float amount: how much you want to trade in units of base currency
|
1247
|
+
:param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
|
1248
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
1249
|
+
:param str [params.timeInForce]: 'GTC', 'IOC', 'FOK' or 'PO'
|
1250
|
+
:param str [params.ref_price_type]: 'MARK_PRICE', 'INDEX_PRICE', 'LAST_PRICE' which trigger price type to use, default is MARK_PRICE
|
1251
|
+
:param float [params.triggerPrice]: price to trigger a trigger order
|
1252
|
+
:param float [params.stopLossPrice]: price to trigger a stop-loss trigger order
|
1253
|
+
:param float [params.takeProfitPrice]: price to trigger a take-profit trigger order
|
1254
|
+
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
|
1255
|
+
"""
|
1256
|
+
self.load_markets()
|
1257
|
+
market = self.market(symbol)
|
1258
|
+
request = self.create_order_request(symbol, type, side, amount, price, params)
|
1259
|
+
response = self.v1PrivatePostPrivateCreateOrder(request)
|
1260
|
+
#
|
1261
|
+
# {
|
1262
|
+
# "id": 1686804664362,
|
1263
|
+
# "method": "private/create-order",
|
1264
|
+
# "code" : 0,
|
1265
|
+
# "result": {
|
1266
|
+
# "order_id": "6540219377766741832",
|
1267
|
+
# "client_oid": "CCXT_d6ef7c3db6c1495aa8b757"
|
1268
|
+
# }
|
1269
|
+
# }
|
1270
|
+
#
|
1271
|
+
result = self.safe_dict(response, 'result', {})
|
1272
|
+
return self.parse_order(result, market)
|
1273
|
+
|
1274
|
+
def create_orders(self, orders: List[OrderRequest], params={}):
|
1275
|
+
"""
|
1276
|
+
create a list of trade orders
|
1277
|
+
|
1278
|
+
https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-create-order-list-list
|
1279
|
+
https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-create-order-list-oco
|
1280
|
+
|
1281
|
+
:param Array orders: list of orders to create, each object should contain the parameters required by createOrder, namely symbol, type, side, amount, price and params
|
1282
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
1283
|
+
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
|
1284
|
+
"""
|
1285
|
+
self.load_markets()
|
1286
|
+
ordersRequests = []
|
1287
|
+
for i in range(0, len(orders)):
|
1288
|
+
rawOrder = orders[i]
|
1289
|
+
marketId = self.safe_string(rawOrder, 'symbol')
|
1290
|
+
type = self.safe_string(rawOrder, 'type')
|
1291
|
+
side = self.safe_string(rawOrder, 'side')
|
1292
|
+
amount = self.safe_value(rawOrder, 'amount')
|
1293
|
+
price = self.safe_value(rawOrder, 'price')
|
1294
|
+
orderParams = self.safe_dict(rawOrder, 'params', {})
|
1295
|
+
orderRequest = self.create_advanced_order_request(marketId, type, side, amount, price, orderParams)
|
1296
|
+
ordersRequests.append(orderRequest)
|
1297
|
+
contigency = self.safe_string(params, 'contingency_type', 'LIST')
|
1298
|
+
request: dict = {
|
1299
|
+
'contingency_type': contigency, # or OCO
|
1300
|
+
'order_list': ordersRequests,
|
1301
|
+
}
|
1302
|
+
response = self.v1PrivatePostPrivateCreateOrderList(self.extend(request, params))
|
1303
|
+
#
|
1304
|
+
# {
|
1305
|
+
# "id": 12,
|
1306
|
+
# "method": "private/create-order-list",
|
1307
|
+
# "code": 10001,
|
1308
|
+
# "result": {
|
1309
|
+
# "result_list": [
|
1310
|
+
# {
|
1311
|
+
# "index": 0,
|
1312
|
+
# "code": 0,
|
1313
|
+
# "order_id": "2015106383706015873",
|
1314
|
+
# "client_oid": "my_order_0001"
|
1315
|
+
# },
|
1316
|
+
# {
|
1317
|
+
# "index": 1,
|
1318
|
+
# "code": 20007,
|
1319
|
+
# "message": "INVALID_REQUEST",
|
1320
|
+
# "client_oid": "my_order_0002"
|
1321
|
+
# }
|
1322
|
+
# ]
|
1323
|
+
# }
|
1324
|
+
# }
|
1325
|
+
#
|
1326
|
+
# {
|
1327
|
+
# "id" : 1698068111133,
|
1328
|
+
# "method" : "private/create-order-list",
|
1329
|
+
# "code" : 0,
|
1330
|
+
# "result" : [{
|
1331
|
+
# "code" : 0,
|
1332
|
+
# "index" : 0,
|
1333
|
+
# "client_oid" : "1698068111133_0",
|
1334
|
+
# "order_id" : "6142909896519488206"
|
1335
|
+
# }, {
|
1336
|
+
# "code" : 306,
|
1337
|
+
# "index" : 1,
|
1338
|
+
# "client_oid" : "1698068111133_1",
|
1339
|
+
# "message" : "INSUFFICIENT_AVAILABLE_BALANCE",
|
1340
|
+
# "order_id" : "6142909896519488207"
|
1341
|
+
# }]
|
1342
|
+
# }
|
1343
|
+
#
|
1344
|
+
result = self.safe_value(response, 'result', [])
|
1345
|
+
listId = self.safe_string(result, 'list_id')
|
1346
|
+
if listId is not None:
|
1347
|
+
ocoOrders = [{'order_id': listId}]
|
1348
|
+
return self.parse_orders(ocoOrders)
|
1349
|
+
return self.parse_orders(result)
|
1350
|
+
|
1351
|
+
def create_advanced_order_request(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, params={}):
|
1352
|
+
# differs slightly from createOrderRequest
|
1353
|
+
# since the advanced order endpoint requires a different set of parameters
|
1354
|
+
# namely here we don't support ref_price or spot_margin
|
1355
|
+
# and market-buy orders need to send notional instead of quantity
|
1356
|
+
market = self.market(symbol)
|
1357
|
+
uppercaseType = type.upper()
|
1358
|
+
request: dict = {
|
1359
|
+
'instrument_name': market['id'],
|
1360
|
+
'side': side.upper(),
|
1361
|
+
}
|
1362
|
+
if (uppercaseType == 'LIMIT') or (uppercaseType == 'STOP_LIMIT') or (uppercaseType == 'TAKE_PROFIT_LIMIT'):
|
1363
|
+
request['price'] = self.price_to_precision(symbol, price)
|
1364
|
+
broker = self.safe_string(self.options, 'broker', 'CCXT')
|
1365
|
+
request['broker_id'] = broker
|
1366
|
+
timeInForce = self.safe_string_upper_2(params, 'timeInForce', 'time_in_force')
|
1367
|
+
if timeInForce is not None:
|
1368
|
+
if timeInForce == 'GTC':
|
1369
|
+
request['time_in_force'] = 'GOOD_TILL_CANCEL'
|
1370
|
+
elif timeInForce == 'IOC':
|
1371
|
+
request['time_in_force'] = 'IMMEDIATE_OR_CANCEL'
|
1372
|
+
elif timeInForce == 'FOK':
|
1373
|
+
request['time_in_force'] = 'FILL_OR_KILL'
|
1374
|
+
else:
|
1375
|
+
request['time_in_force'] = timeInForce
|
1376
|
+
postOnly = self.safe_bool(params, 'postOnly', False)
|
1377
|
+
if (postOnly) or (timeInForce == 'PO'):
|
1378
|
+
request['exec_inst'] = ['POST_ONLY']
|
1379
|
+
request['time_in_force'] = 'GOOD_TILL_CANCEL'
|
1380
|
+
triggerPrice = self.safe_string_n(params, ['stopPrice', 'triggerPrice', 'ref_price'])
|
1381
|
+
stopLossPrice = self.safe_number(params, 'stopLossPrice')
|
1382
|
+
takeProfitPrice = self.safe_number(params, 'takeProfitPrice')
|
1383
|
+
isTrigger = (triggerPrice is not None)
|
1384
|
+
isStopLossTrigger = (stopLossPrice is not None)
|
1385
|
+
isTakeProfitTrigger = (takeProfitPrice is not None)
|
1386
|
+
if isTrigger:
|
1387
|
+
priceString = self.number_to_string(price)
|
1388
|
+
if (uppercaseType == 'LIMIT') or (uppercaseType == 'STOP_LIMIT') or (uppercaseType == 'TAKE_PROFIT_LIMIT'):
|
1389
|
+
if side == 'buy':
|
1390
|
+
if Precise.string_lt(priceString, triggerPrice):
|
1391
|
+
request['type'] = 'TAKE_PROFIT_LIMIT'
|
1392
|
+
else:
|
1393
|
+
request['type'] = 'STOP_LIMIT'
|
1394
|
+
else:
|
1395
|
+
if Precise.string_lt(priceString, triggerPrice):
|
1396
|
+
request['type'] = 'STOP_LIMIT'
|
1397
|
+
else:
|
1398
|
+
request['type'] = 'TAKE_PROFIT_LIMIT'
|
1399
|
+
else:
|
1400
|
+
if side == 'buy':
|
1401
|
+
if Precise.string_lt(priceString, triggerPrice):
|
1402
|
+
request['type'] = 'TAKE_PROFIT'
|
1403
|
+
else:
|
1404
|
+
request['type'] = 'STOP_LOSS'
|
1405
|
+
else:
|
1406
|
+
if Precise.string_lt(priceString, triggerPrice):
|
1407
|
+
request['type'] = 'STOP_LOSS'
|
1408
|
+
else:
|
1409
|
+
request['type'] = 'TAKE_PROFIT'
|
1410
|
+
elif isStopLossTrigger:
|
1411
|
+
if (uppercaseType == 'LIMIT') or (uppercaseType == 'STOP_LIMIT'):
|
1412
|
+
request['type'] = 'STOP_LIMIT'
|
1413
|
+
else:
|
1414
|
+
request['type'] = 'STOP_LOSS'
|
1415
|
+
elif isTakeProfitTrigger:
|
1416
|
+
if (uppercaseType == 'LIMIT') or (uppercaseType == 'TAKE_PROFIT_LIMIT'):
|
1417
|
+
request['type'] = 'TAKE_PROFIT_LIMIT'
|
1418
|
+
else:
|
1419
|
+
request['type'] = 'TAKE_PROFIT'
|
1420
|
+
else:
|
1421
|
+
request['type'] = uppercaseType
|
1422
|
+
if (side == 'buy') and ((uppercaseType == 'MARKET') or (uppercaseType == 'STOP_LOSS') or (uppercaseType == 'TAKE_PROFIT')):
|
1423
|
+
# use createmarketBuy logic here
|
1424
|
+
quoteAmount = None
|
1425
|
+
createMarketBuyOrderRequiresPrice = True
|
1426
|
+
createMarketBuyOrderRequiresPrice, params = self.handle_option_and_params(params, 'createOrder', 'createMarketBuyOrderRequiresPrice', True)
|
1427
|
+
cost = self.safe_number_2(params, 'cost', 'notional')
|
1428
|
+
params = self.omit(params, 'cost')
|
1429
|
+
if cost is not None:
|
1430
|
+
quoteAmount = self.cost_to_precision(symbol, cost)
|
1431
|
+
elif createMarketBuyOrderRequiresPrice:
|
1432
|
+
if price is None:
|
1433
|
+
raise InvalidOrder(self.id + ' createOrder() requires the price argument for market buy orders to calculate the total cost to spend(amount * price), alternatively set the createMarketBuyOrderRequiresPrice option or param to False and pass the cost to spend(quote quantity) in the amount argument')
|
1434
|
+
else:
|
1435
|
+
amountString = self.number_to_string(amount)
|
1436
|
+
priceString = self.number_to_string(price)
|
1437
|
+
costRequest = Precise.string_mul(amountString, priceString)
|
1438
|
+
quoteAmount = self.cost_to_precision(symbol, costRequest)
|
1439
|
+
else:
|
1440
|
+
quoteAmount = self.cost_to_precision(symbol, amount)
|
1441
|
+
request['notional'] = quoteAmount
|
1442
|
+
else:
|
1443
|
+
request['quantity'] = self.amount_to_precision(symbol, amount)
|
1444
|
+
params = self.omit(params, ['postOnly', 'clientOrderId', 'timeInForce', 'stopPrice', 'triggerPrice', 'stopLossPrice', 'takeProfitPrice'])
|
1445
|
+
return self.extend(request, params)
|
1446
|
+
|
1447
|
+
def cancel_all_orders(self, symbol: Str = None, params={}):
|
1448
|
+
"""
|
1449
|
+
cancel all open orders
|
1450
|
+
|
1451
|
+
https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-cancel-all-orders
|
1452
|
+
|
1453
|
+
:param str symbol: unified market symbol of the orders to cancel
|
1454
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
1455
|
+
:returns dict} Returns exchange raw message{@link https://docs.ccxt.com/#/?id=order-structure:
|
1456
|
+
"""
|
1457
|
+
self.load_markets()
|
1458
|
+
market = None
|
1459
|
+
request: dict = {}
|
1460
|
+
if symbol is not None:
|
1461
|
+
market = self.market(symbol)
|
1462
|
+
request['instrument_name'] = market['id']
|
1463
|
+
return self.v1PrivatePostPrivateCancelAllOrders(self.extend(request, params))
|
1464
|
+
|
1465
|
+
def cancel_order(self, id: str, symbol: Str = None, params={}):
|
1466
|
+
"""
|
1467
|
+
cancels an open order
|
1468
|
+
|
1469
|
+
https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-cancel-order
|
1470
|
+
|
1471
|
+
:param str id: the order id of the order to cancel
|
1472
|
+
:param str [symbol]: unified symbol of the market the order was made in
|
1473
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
1474
|
+
:returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
|
1475
|
+
"""
|
1476
|
+
self.load_markets()
|
1477
|
+
market = None
|
1478
|
+
if symbol is not None:
|
1479
|
+
market = self.market(symbol)
|
1480
|
+
request: dict = {
|
1481
|
+
'order_id': id,
|
1482
|
+
}
|
1483
|
+
response = self.v1PrivatePostPrivateCancelOrder(self.extend(request, params))
|
1484
|
+
#
|
1485
|
+
# {
|
1486
|
+
# "id": 1686882846638,
|
1487
|
+
# "method": "private/cancel-order",
|
1488
|
+
# "code": 0,
|
1489
|
+
# "message": "NO_ERROR",
|
1490
|
+
# "result": {
|
1491
|
+
# "client_oid": "CCXT_c2d2152cc32d40a3ae7fbf",
|
1492
|
+
# "order_id": "6142909895025252686"
|
1493
|
+
# }
|
1494
|
+
# }
|
1495
|
+
#
|
1496
|
+
result = self.safe_dict(response, 'result', {})
|
1497
|
+
return self.parse_order(result, market)
|
1498
|
+
|
1499
|
+
def cancel_orders(self, ids, symbol: Str = None, params={}):
|
1500
|
+
"""
|
1501
|
+
cancel multiple orders
|
1502
|
+
|
1503
|
+
https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-cancel-order-list-list
|
1504
|
+
|
1505
|
+
:param str[] ids: order ids
|
1506
|
+
:param str symbol: unified market symbol
|
1507
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
1508
|
+
:returns dict: an list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
|
1509
|
+
"""
|
1510
|
+
if symbol is None:
|
1511
|
+
raise ArgumentsRequired(self.id + ' cancelOrders() requires a symbol argument')
|
1512
|
+
self.load_markets()
|
1513
|
+
market = self.market(symbol)
|
1514
|
+
orderRequests = []
|
1515
|
+
for i in range(0, len(ids)):
|
1516
|
+
id = ids[i]
|
1517
|
+
order: dict = {
|
1518
|
+
'instrument_name': market['id'],
|
1519
|
+
'order_id': str(id),
|
1520
|
+
}
|
1521
|
+
orderRequests.append(order)
|
1522
|
+
request: dict = {
|
1523
|
+
'contingency_type': 'LIST',
|
1524
|
+
'order_list': orderRequests,
|
1525
|
+
}
|
1526
|
+
response = self.v1PrivatePostPrivateCancelOrderList(self.extend(request, params))
|
1527
|
+
result = self.safe_list(response, 'result', [])
|
1528
|
+
return self.parse_orders(result, market, None, None, params)
|
1529
|
+
|
1530
|
+
def cancel_orders_for_symbols(self, orders: List[CancellationRequest], params={}):
|
1531
|
+
"""
|
1532
|
+
cancel multiple orders for multiple symbols
|
1533
|
+
|
1534
|
+
https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-cancel-order-list-list
|
1535
|
+
|
1536
|
+
:param CancellationRequest[] orders: each order should contain the parameters required by cancelOrder namely id and symbol, example [{"id": "a", "symbol": "BTC/USDT"}, {"id": "b", "symbol": "ETH/USDT"}]
|
1537
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
1538
|
+
:returns dict: an list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
|
1539
|
+
"""
|
1540
|
+
self.load_markets()
|
1541
|
+
orderRequests = []
|
1542
|
+
for i in range(0, len(orders)):
|
1543
|
+
order = orders[i]
|
1544
|
+
id = self.safe_string(order, 'id')
|
1545
|
+
symbol = self.safe_string(order, 'symbol')
|
1546
|
+
market = self.market(symbol)
|
1547
|
+
orderItem: dict = {
|
1548
|
+
'instrument_name': market['id'],
|
1549
|
+
'order_id': str(id),
|
1550
|
+
}
|
1551
|
+
orderRequests.append(orderItem)
|
1552
|
+
request: dict = {
|
1553
|
+
'contingency_type': 'LIST',
|
1554
|
+
'order_list': orderRequests,
|
1555
|
+
}
|
1556
|
+
response = self.v1PrivatePostPrivateCancelOrderList(self.extend(request, params))
|
1557
|
+
result = self.safe_list(response, 'result', [])
|
1558
|
+
return self.parse_orders(result, None, None, None, params)
|
1559
|
+
|
1560
|
+
def fetch_open_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Order]:
|
1561
|
+
"""
|
1562
|
+
fetch all unfilled currently open orders
|
1563
|
+
|
1564
|
+
https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-get-open-orders
|
1565
|
+
|
1566
|
+
:param str symbol: unified market symbol
|
1567
|
+
:param int [since]: the earliest time in ms to fetch open orders for
|
1568
|
+
:param int [limit]: the maximum number of open order structures to retrieve
|
1569
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
1570
|
+
:returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
|
1571
|
+
"""
|
1572
|
+
self.load_markets()
|
1573
|
+
market = None
|
1574
|
+
request: dict = {}
|
1575
|
+
if symbol is not None:
|
1576
|
+
market = self.market(symbol)
|
1577
|
+
request['instrument_name'] = market['id']
|
1578
|
+
response = self.v1PrivatePostPrivateGetOpenOrders(self.extend(request, params))
|
1579
|
+
#
|
1580
|
+
# {
|
1581
|
+
# "id": 1686806134961,
|
1582
|
+
# "method": "private/get-open-orders",
|
1583
|
+
# "code": 0,
|
1584
|
+
# "result": {
|
1585
|
+
# "data": [
|
1586
|
+
# {
|
1587
|
+
# "account_id": "ce075bef-1234-4321-bd6g-ff9007252e63",
|
1588
|
+
# "order_id": "6530219477767564494",
|
1589
|
+
# "client_oid": "CCXT_7ce730f0388441df9bc218",
|
1590
|
+
# "order_type": "LIMIT",
|
1591
|
+
# "time_in_force": "GOOD_TILL_CANCEL",
|
1592
|
+
# "side": "BUY",
|
1593
|
+
# "exec_inst": [],
|
1594
|
+
# "quantity": "0.00020",
|
1595
|
+
# "limit_price": "20000.00",
|
1596
|
+
# "order_value": "4",
|
1597
|
+
# "avg_price": "0",
|
1598
|
+
# "trigger_price": "0",
|
1599
|
+
# "ref_price": "0",
|
1600
|
+
# "cumulative_quantity": "0",
|
1601
|
+
# "cumulative_value": "0",
|
1602
|
+
# "cumulative_fee": "0",
|
1603
|
+
# "status": "ACTIVE",
|
1604
|
+
# "update_user_id": "ce075bef-1234-4321-bd6g-gg9007252e63",
|
1605
|
+
# "order_date": "2023-06-15",
|
1606
|
+
# "instrument_name": "BTC_USD",
|
1607
|
+
# "fee_instrument_name": "BTC",
|
1608
|
+
# "create_time": 1686806053992,
|
1609
|
+
# "create_time_ns": "1686806053992921880",
|
1610
|
+
# "update_time": 1686806053993
|
1611
|
+
# }
|
1612
|
+
# ]
|
1613
|
+
# }
|
1614
|
+
# }
|
1615
|
+
#
|
1616
|
+
data = self.safe_dict(response, 'result', {})
|
1617
|
+
orders = self.safe_list(data, 'data', [])
|
1618
|
+
return self.parse_orders(orders, market, since, limit)
|
1619
|
+
|
1620
|
+
def fetch_my_trades(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}):
|
1621
|
+
"""
|
1622
|
+
fetch all trades made by the user
|
1623
|
+
|
1624
|
+
https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-get-trades
|
1625
|
+
|
1626
|
+
:param str symbol: unified market symbol
|
1627
|
+
:param int [since]: the earliest time in ms to fetch trades for, maximum date range is one day
|
1628
|
+
:param int [limit]: the maximum number of trade structures to retrieve
|
1629
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
1630
|
+
:param int [params.until]: timestamp in ms for the ending date filter, default is the current time
|
1631
|
+
:param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
|
1632
|
+
:returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
|
1633
|
+
"""
|
1634
|
+
self.load_markets()
|
1635
|
+
paginate = False
|
1636
|
+
paginate, params = self.handle_option_and_params(params, 'fetchMyTrades', 'paginate')
|
1637
|
+
if paginate:
|
1638
|
+
return self.fetch_paginated_call_dynamic('fetchMyTrades', symbol, since, limit, params, 100)
|
1639
|
+
request: dict = {}
|
1640
|
+
market = None
|
1641
|
+
if symbol is not None:
|
1642
|
+
market = self.market(symbol)
|
1643
|
+
request['instrument_name'] = market['id']
|
1644
|
+
if since is not None:
|
1645
|
+
request['start_time'] = since
|
1646
|
+
if limit is not None:
|
1647
|
+
request['limit'] = limit
|
1648
|
+
until = self.safe_integer(params, 'until')
|
1649
|
+
params = self.omit(params, ['until'])
|
1650
|
+
if until is not None:
|
1651
|
+
request['end_time'] = until
|
1652
|
+
response = self.v1PrivatePostPrivateGetTrades(self.extend(request, params))
|
1653
|
+
#
|
1654
|
+
# {
|
1655
|
+
# "id": 1686942003520,
|
1656
|
+
# "method": "private/get-trades",
|
1657
|
+
# "code": 0,
|
1658
|
+
# "result": {
|
1659
|
+
# "data": [
|
1660
|
+
# {
|
1661
|
+
# "account_id": "ds075abc-1234-4321-bd6g-ff9007252r63",
|
1662
|
+
# "event_date": "2023-06-16",
|
1663
|
+
# "journal_type": "TRADING",
|
1664
|
+
# "side": "BUY",
|
1665
|
+
# "instrument_name": "BTC_USD",
|
1666
|
+
# "fees": "-0.0000000525",
|
1667
|
+
# "trade_id": "6142909898247428343",
|
1668
|
+
# "trade_match_id": "4611686018455978480",
|
1669
|
+
# "create_time": 1686941992887,
|
1670
|
+
# "traded_price": "26347.16",
|
1671
|
+
# "traded_quantity": "0.00021",
|
1672
|
+
# "fee_instrument_name": "BTC",
|
1673
|
+
# "client_oid": "d1c70a60-810e-4c92-b2a0-72b931cb31e0",
|
1674
|
+
# "taker_side": "TAKER",
|
1675
|
+
# "order_id": "6142909895036331486",
|
1676
|
+
# "create_time_ns": "1686941992887207066"
|
1677
|
+
# }
|
1678
|
+
# ]
|
1679
|
+
# }
|
1680
|
+
# }
|
1681
|
+
#
|
1682
|
+
result = self.safe_dict(response, 'result', {})
|
1683
|
+
trades = self.safe_list(result, 'data', [])
|
1684
|
+
return self.parse_trades(trades, market, since, limit)
|
1685
|
+
|
1686
|
+
def parse_address(self, addressString):
|
1687
|
+
address = None
|
1688
|
+
tag = None
|
1689
|
+
rawTag = None
|
1690
|
+
if addressString.find('?') > 0:
|
1691
|
+
address, rawTag = addressString.split('?')
|
1692
|
+
splitted = rawTag.split('=')
|
1693
|
+
tag = splitted[1]
|
1694
|
+
else:
|
1695
|
+
address = addressString
|
1696
|
+
return [address, tag]
|
1697
|
+
|
1698
|
+
def withdraw(self, code: str, amount: float, address: str, tag=None, params={}) -> Transaction:
|
1699
|
+
"""
|
1700
|
+
make a withdrawal
|
1701
|
+
|
1702
|
+
https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-create-withdrawal
|
1703
|
+
|
1704
|
+
:param str code: unified currency code
|
1705
|
+
:param float amount: the amount to withdraw
|
1706
|
+
:param str address: the address to withdraw to
|
1707
|
+
:param str tag:
|
1708
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
1709
|
+
:returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
|
1710
|
+
"""
|
1711
|
+
tag, params = self.handle_withdraw_tag_and_params(tag, params)
|
1712
|
+
self.load_markets()
|
1713
|
+
currency = self.safe_currency(code) # for instance, USDC is not inferred from markets but it's still available
|
1714
|
+
request: dict = {
|
1715
|
+
'currency': currency['id'],
|
1716
|
+
'amount': amount,
|
1717
|
+
'address': address,
|
1718
|
+
}
|
1719
|
+
if tag is not None:
|
1720
|
+
request['address_tag'] = tag
|
1721
|
+
networkCode = None
|
1722
|
+
networkCode, params = self.handle_network_code_and_params(params)
|
1723
|
+
networkId = self.network_code_to_id(networkCode)
|
1724
|
+
if networkId is not None:
|
1725
|
+
request['network_id'] = networkId
|
1726
|
+
response = self.v1PrivatePostPrivateCreateWithdrawal(self.extend(request, params))
|
1727
|
+
#
|
1728
|
+
# {
|
1729
|
+
# "id":-1,
|
1730
|
+
# "method":"private/create-withdrawal",
|
1731
|
+
# "code":0,
|
1732
|
+
# "result": {
|
1733
|
+
# "id": 2220,
|
1734
|
+
# "amount": 1,
|
1735
|
+
# "fee": 0.0004,
|
1736
|
+
# "symbol": "BTC",
|
1737
|
+
# "address": "2NBqqD5GRJ8wHy1PYyCXTe9ke5226FhavBf",
|
1738
|
+
# "client_wid": "my_withdrawal_002",
|
1739
|
+
# "create_time":1607063412000
|
1740
|
+
# }
|
1741
|
+
# }
|
1742
|
+
#
|
1743
|
+
result = self.safe_dict(response, 'result')
|
1744
|
+
return self.parse_transaction(result, currency)
|
1745
|
+
|
1746
|
+
def fetch_deposit_addresses_by_network(self, code: str, params={}) -> List[DepositAddress]:
|
1747
|
+
"""
|
1748
|
+
fetch a dictionary of addresses for a currency, indexed by network
|
1749
|
+
|
1750
|
+
https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-get-deposit-address
|
1751
|
+
|
1752
|
+
:param str code: unified currency code of the currency for the deposit address
|
1753
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
1754
|
+
:returns dict: a dictionary of `address structures <https://docs.ccxt.com/#/?id=address-structure>` indexed by the network
|
1755
|
+
"""
|
1756
|
+
self.load_markets()
|
1757
|
+
currency = self.safe_currency(code)
|
1758
|
+
request: dict = {
|
1759
|
+
'currency': currency['id'],
|
1760
|
+
}
|
1761
|
+
response = self.v1PrivatePostPrivateGetDepositAddress(self.extend(request, params))
|
1762
|
+
#
|
1763
|
+
# {
|
1764
|
+
# "id": 1234555011221,
|
1765
|
+
# "method": "private/get-deposit-address",
|
1766
|
+
# "code": 0,
|
1767
|
+
# "result": {
|
1768
|
+
# "deposit_address_list": [
|
1769
|
+
# {
|
1770
|
+
# "currency": "BTC",
|
1771
|
+
# "create_time": 1686730755000,
|
1772
|
+
# "id": "3737377",
|
1773
|
+
# "address": "3N9afggxTSmJ3H4jaMQuWyEiLBzZdAbK6d",
|
1774
|
+
# "status":"1",
|
1775
|
+
# "network": "BTC"
|
1776
|
+
# },
|
1777
|
+
# ]
|
1778
|
+
# }
|
1779
|
+
# }
|
1780
|
+
#
|
1781
|
+
data = self.safe_dict(response, 'result', {})
|
1782
|
+
addresses = self.safe_list(data, 'deposit_address_list', [])
|
1783
|
+
addressesLength = len(addresses)
|
1784
|
+
if addressesLength == 0:
|
1785
|
+
raise ExchangeError(self.id + ' fetchDepositAddressesByNetwork() generating address...')
|
1786
|
+
result: dict = {}
|
1787
|
+
for i in range(0, addressesLength):
|
1788
|
+
value = self.safe_dict(addresses, i)
|
1789
|
+
addressString = self.safe_string(value, 'address')
|
1790
|
+
currencyId = self.safe_string(value, 'currency')
|
1791
|
+
responseCode = self.safe_currency_code(currencyId)
|
1792
|
+
address, tag = self.parse_address(addressString)
|
1793
|
+
self.check_address(address)
|
1794
|
+
networkId = self.safe_string(value, 'network')
|
1795
|
+
network = self.network_id_to_code(networkId, responseCode)
|
1796
|
+
result[network] = {
|
1797
|
+
'info': value,
|
1798
|
+
'currency': responseCode,
|
1799
|
+
'network': network,
|
1800
|
+
'address': address,
|
1801
|
+
'tag': tag,
|
1802
|
+
}
|
1803
|
+
return result
|
1804
|
+
|
1805
|
+
def fetch_deposit_address(self, code: str, params={}) -> DepositAddress:
|
1806
|
+
"""
|
1807
|
+
fetch the deposit address for a currency associated with self account
|
1808
|
+
|
1809
|
+
https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-get-deposit-address
|
1810
|
+
|
1811
|
+
:param str code: unified currency code
|
1812
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
1813
|
+
:returns dict: an `address structure <https://docs.ccxt.com/#/?id=address-structure>`
|
1814
|
+
"""
|
1815
|
+
network = self.safe_string_upper(params, 'network')
|
1816
|
+
params = self.omit(params, ['network'])
|
1817
|
+
depositAddresses = self.fetch_deposit_addresses_by_network(code, params)
|
1818
|
+
if network in depositAddresses:
|
1819
|
+
return depositAddresses[network]
|
1820
|
+
else:
|
1821
|
+
keys = list(depositAddresses.keys())
|
1822
|
+
return depositAddresses[keys[0]]
|
1823
|
+
|
1824
|
+
def fetch_deposits(self, code: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Transaction]:
|
1825
|
+
"""
|
1826
|
+
fetch all deposits made to an account
|
1827
|
+
|
1828
|
+
https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-get-deposit-history
|
1829
|
+
|
1830
|
+
:param str code: unified currency code
|
1831
|
+
:param int [since]: the earliest time in ms to fetch deposits for
|
1832
|
+
:param int [limit]: the maximum number of deposits structures to retrieve
|
1833
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
1834
|
+
:param int [params.until]: timestamp in ms for the ending date filter, default is the current time
|
1835
|
+
:returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
|
1836
|
+
"""
|
1837
|
+
self.load_markets()
|
1838
|
+
currency = None
|
1839
|
+
request: dict = {}
|
1840
|
+
if code is not None:
|
1841
|
+
currency = self.safe_currency(code)
|
1842
|
+
request['currency'] = currency['id']
|
1843
|
+
if since is not None:
|
1844
|
+
# 90 days date range
|
1845
|
+
request['start_ts'] = since
|
1846
|
+
if limit is not None:
|
1847
|
+
request['page_size'] = limit
|
1848
|
+
until = self.safe_integer(params, 'until')
|
1849
|
+
params = self.omit(params, ['until'])
|
1850
|
+
if until is not None:
|
1851
|
+
request['end_ts'] = until
|
1852
|
+
response = self.v1PrivatePostPrivateGetDepositHistory(self.extend(request, params))
|
1853
|
+
#
|
1854
|
+
# {
|
1855
|
+
# "id": 1688701375714,
|
1856
|
+
# "method": "private/get-deposit-history",
|
1857
|
+
# "code": 0,
|
1858
|
+
# "result": {
|
1859
|
+
# "deposit_list": [
|
1860
|
+
# {
|
1861
|
+
# "currency": "BTC",
|
1862
|
+
# "fee": 0,
|
1863
|
+
# "create_time": 1688023659000,
|
1864
|
+
# "id": "6201135",
|
1865
|
+
# "update_time": 1688178509000,
|
1866
|
+
# "amount": 0.00114571,
|
1867
|
+
# "address": "1234fggxTSmJ3H4jaMQuWyEiLBzZdAbK6d",
|
1868
|
+
# "status": "1",
|
1869
|
+
# "txid": "f0ae4202b76eb999c301eccdde44dc639bee42d1fdd5974105286ca3393f6065/2"
|
1870
|
+
# },
|
1871
|
+
# ]
|
1872
|
+
# }
|
1873
|
+
# }
|
1874
|
+
#
|
1875
|
+
data = self.safe_dict(response, 'result', {})
|
1876
|
+
depositList = self.safe_list(data, 'deposit_list', [])
|
1877
|
+
return self.parse_transactions(depositList, currency, since, limit)
|
1878
|
+
|
1879
|
+
def fetch_withdrawals(self, code: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Transaction]:
|
1880
|
+
"""
|
1881
|
+
fetch all withdrawals made from an account
|
1882
|
+
|
1883
|
+
https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-get-withdrawal-history
|
1884
|
+
|
1885
|
+
:param str code: unified currency code
|
1886
|
+
:param int [since]: the earliest time in ms to fetch withdrawals for
|
1887
|
+
:param int [limit]: the maximum number of withdrawals structures to retrieve
|
1888
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
1889
|
+
:param int [params.until]: timestamp in ms for the ending date filter, default is the current time
|
1890
|
+
:returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
|
1891
|
+
"""
|
1892
|
+
self.load_markets()
|
1893
|
+
currency = None
|
1894
|
+
request: dict = {}
|
1895
|
+
if code is not None:
|
1896
|
+
currency = self.safe_currency(code)
|
1897
|
+
request['currency'] = currency['id']
|
1898
|
+
if since is not None:
|
1899
|
+
# 90 days date range
|
1900
|
+
request['start_ts'] = since
|
1901
|
+
if limit is not None:
|
1902
|
+
request['page_size'] = limit
|
1903
|
+
until = self.safe_integer(params, 'until')
|
1904
|
+
params = self.omit(params, ['until'])
|
1905
|
+
if until is not None:
|
1906
|
+
request['end_ts'] = until
|
1907
|
+
response = self.v1PrivatePostPrivateGetWithdrawalHistory(self.extend(request, params))
|
1908
|
+
#
|
1909
|
+
# {
|
1910
|
+
# "id": 1688613879534,
|
1911
|
+
# "method": "private/get-withdrawal-history",
|
1912
|
+
# "code": 0,
|
1913
|
+
# "result": {
|
1914
|
+
# "withdrawal_list": [
|
1915
|
+
# {
|
1916
|
+
# "currency": "BTC",
|
1917
|
+
# "client_wid": "",
|
1918
|
+
# "fee": 0.0005,
|
1919
|
+
# "create_time": 1688613850000,
|
1920
|
+
# "id": "5275977",
|
1921
|
+
# "update_time": 1688613850000,
|
1922
|
+
# "amount": 0.0005,
|
1923
|
+
# "address": "1234NMEWbiF8ZkwUMxmfzMxi2A1MQ44bMn",
|
1924
|
+
# "status": "1",
|
1925
|
+
# "txid": "",
|
1926
|
+
# "network_id": "BTC"
|
1927
|
+
# }
|
1928
|
+
# ]
|
1929
|
+
# }
|
1930
|
+
# }
|
1931
|
+
#
|
1932
|
+
data = self.safe_dict(response, 'result', {})
|
1933
|
+
withdrawalList = self.safe_list(data, 'withdrawal_list', [])
|
1934
|
+
return self.parse_transactions(withdrawalList, currency, since, limit)
|
1935
|
+
|
1936
|
+
def parse_ticker(self, ticker: dict, market: Market = None) -> Ticker:
|
1937
|
+
#
|
1938
|
+
# fetchTicker
|
1939
|
+
#
|
1940
|
+
# {
|
1941
|
+
# "i": "BTC_USD",
|
1942
|
+
# "h": "30821.45",
|
1943
|
+
# "l": "28685.11",
|
1944
|
+
# "a": "30446.00",
|
1945
|
+
# "v": "1767.8734",
|
1946
|
+
# "vv": "52436726.42",
|
1947
|
+
# "c": "0.0583",
|
1948
|
+
# "b": "30442.00",
|
1949
|
+
# "k": "30447.66",
|
1950
|
+
# "t": 1687403045415
|
1951
|
+
# }
|
1952
|
+
#
|
1953
|
+
# fetchTickers
|
1954
|
+
#
|
1955
|
+
# {
|
1956
|
+
# "i": "AVAXUSD-PERP",
|
1957
|
+
# "h": "13.209",
|
1958
|
+
# "l": "12.148",
|
1959
|
+
# "a": "13.209",
|
1960
|
+
# "v": "1109.8",
|
1961
|
+
# "vv": "14017.33",
|
1962
|
+
# "c": "0.0732",
|
1963
|
+
# "b": "13.210",
|
1964
|
+
# "k": "13.230",
|
1965
|
+
# "oi": "10888.9",
|
1966
|
+
# "t": 1687402657575
|
1967
|
+
# }
|
1968
|
+
#
|
1969
|
+
timestamp = self.safe_integer(ticker, 't')
|
1970
|
+
marketId = self.safe_string(ticker, 'i')
|
1971
|
+
market = self.safe_market(marketId, market, '_')
|
1972
|
+
quote = self.safe_string(market, 'quote')
|
1973
|
+
last = self.safe_string(ticker, 'a')
|
1974
|
+
return self.safe_ticker({
|
1975
|
+
'symbol': market['symbol'],
|
1976
|
+
'timestamp': timestamp,
|
1977
|
+
'datetime': self.iso8601(timestamp),
|
1978
|
+
'high': self.safe_number(ticker, 'h'),
|
1979
|
+
'low': self.safe_number(ticker, 'l'),
|
1980
|
+
'bid': self.safe_number(ticker, 'b'),
|
1981
|
+
'bidVolume': None,
|
1982
|
+
'ask': self.safe_number(ticker, 'k'),
|
1983
|
+
'askVolume': None,
|
1984
|
+
'vwap': None,
|
1985
|
+
'open': None,
|
1986
|
+
'close': last,
|
1987
|
+
'last': last,
|
1988
|
+
'previousClose': None,
|
1989
|
+
'change': None,
|
1990
|
+
'percentage': self.safe_string(ticker, 'c'),
|
1991
|
+
'average': None,
|
1992
|
+
'baseVolume': self.safe_string(ticker, 'v'),
|
1993
|
+
'quoteVolume': self.safe_string(ticker, 'vv') if (quote == 'USD') else None,
|
1994
|
+
'info': ticker,
|
1995
|
+
}, market)
|
1996
|
+
|
1997
|
+
def parse_trade(self, trade: dict, market: Market = None) -> Trade:
|
1998
|
+
#
|
1999
|
+
# fetchTrades
|
2000
|
+
#
|
2001
|
+
# {
|
2002
|
+
# "s": "sell",
|
2003
|
+
# "p": "26386.00",
|
2004
|
+
# "q": "0.00453",
|
2005
|
+
# "tn": 1686944282062,
|
2006
|
+
# "tn": 1704476468851524373,
|
2007
|
+
# "d": "4611686018455979970",
|
2008
|
+
# "i": "BTC_USD"
|
2009
|
+
# }
|
2010
|
+
#
|
2011
|
+
# fetchMyTrades
|
2012
|
+
#
|
2013
|
+
# {
|
2014
|
+
# "account_id": "ds075abc-1234-4321-bd6g-ff9007252r63",
|
2015
|
+
# "event_date": "2023-06-16",
|
2016
|
+
# "journal_type": "TRADING",
|
2017
|
+
# "side": "BUY",
|
2018
|
+
# "instrument_name": "BTC_USD",
|
2019
|
+
# "fees": "-0.0000000525",
|
2020
|
+
# "trade_id": "6142909898247428343",
|
2021
|
+
# "trade_match_id": "4611686018455978480",
|
2022
|
+
# "create_time": 1686941992887,
|
2023
|
+
# "traded_price": "26347.16",
|
2024
|
+
# "traded_quantity": "0.00021",
|
2025
|
+
# "fee_instrument_name": "BTC",
|
2026
|
+
# "client_oid": "d1c70a60-1234-4c92-b2a0-72b931cb31e0",
|
2027
|
+
# "taker_side": "TAKER",
|
2028
|
+
# "order_id": "6142909895036331486",
|
2029
|
+
# "create_time_ns": "1686941992887207066"
|
2030
|
+
# }
|
2031
|
+
#
|
2032
|
+
timestamp = self.safe_integer_2(trade, 't', 'create_time')
|
2033
|
+
marketId = self.safe_string_2(trade, 'i', 'instrument_name')
|
2034
|
+
market = self.safe_market(marketId, market, '_')
|
2035
|
+
feeCurrency = self.safe_string(trade, 'fee_instrument_name')
|
2036
|
+
feeCostString = self.safe_string(trade, 'fees')
|
2037
|
+
return self.safe_trade({
|
2038
|
+
'info': trade,
|
2039
|
+
'id': self.safe_string_2(trade, 'd', 'trade_id'),
|
2040
|
+
'timestamp': timestamp,
|
2041
|
+
'datetime': self.iso8601(timestamp),
|
2042
|
+
'symbol': market['symbol'],
|
2043
|
+
'order': self.safe_string(trade, 'order_id'),
|
2044
|
+
'side': self.safe_string_lower_2(trade, 's', 'side'),
|
2045
|
+
'takerOrMaker': self.safe_string_lower(trade, 'taker_side'),
|
2046
|
+
'price': self.safe_number_2(trade, 'p', 'traded_price'),
|
2047
|
+
'amount': self.safe_number_2(trade, 'q', 'traded_quantity'),
|
2048
|
+
'cost': None,
|
2049
|
+
'type': None,
|
2050
|
+
'fee': {
|
2051
|
+
'currency': self.safe_currency_code(feeCurrency),
|
2052
|
+
'cost': self.parse_number(Precise.string_neg(feeCostString)),
|
2053
|
+
},
|
2054
|
+
}, market)
|
2055
|
+
|
2056
|
+
def parse_ohlcv(self, ohlcv, market: Market = None) -> list:
|
2057
|
+
#
|
2058
|
+
# {
|
2059
|
+
# "o": "26949.89",
|
2060
|
+
# "h": "26957.64",
|
2061
|
+
# "l": "26948.24",
|
2062
|
+
# "c": "26950.00",
|
2063
|
+
# "v": "0.0670",
|
2064
|
+
# "t": 1687237080000
|
2065
|
+
# }
|
2066
|
+
#
|
2067
|
+
return [
|
2068
|
+
self.safe_integer(ohlcv, 't'),
|
2069
|
+
self.safe_number(ohlcv, 'o'),
|
2070
|
+
self.safe_number(ohlcv, 'h'),
|
2071
|
+
self.safe_number(ohlcv, 'l'),
|
2072
|
+
self.safe_number(ohlcv, 'c'),
|
2073
|
+
self.safe_number(ohlcv, 'v'),
|
2074
|
+
]
|
2075
|
+
|
2076
|
+
def parse_order_status(self, status: Str):
|
2077
|
+
statuses: dict = {
|
2078
|
+
'ACTIVE': 'open',
|
2079
|
+
'CANCELED': 'canceled',
|
2080
|
+
'FILLED': 'closed',
|
2081
|
+
'REJECTED': 'rejected',
|
2082
|
+
'EXPIRED': 'expired',
|
2083
|
+
}
|
2084
|
+
return self.safe_string(statuses, status, status)
|
2085
|
+
|
2086
|
+
def parse_time_in_force(self, timeInForce: Str):
|
2087
|
+
timeInForces: dict = {
|
2088
|
+
'GOOD_TILL_CANCEL': 'GTC',
|
2089
|
+
'IMMEDIATE_OR_CANCEL': 'IOC',
|
2090
|
+
'FILL_OR_KILL': 'FOK',
|
2091
|
+
}
|
2092
|
+
return self.safe_string(timeInForces, timeInForce, timeInForce)
|
2093
|
+
|
2094
|
+
def parse_order(self, order: dict, market: Market = None) -> Order:
|
2095
|
+
#
|
2096
|
+
# createOrder, cancelOrder
|
2097
|
+
#
|
2098
|
+
# {
|
2099
|
+
# "order_id": "6540219377766741832",
|
2100
|
+
# "client_oid": "CCXT_d6ef7c3db6c1495aa8b757"
|
2101
|
+
# }
|
2102
|
+
#
|
2103
|
+
# fetchOpenOrders, fetchOrder, fetchOrders
|
2104
|
+
#
|
2105
|
+
# {
|
2106
|
+
# "account_id": "ce075bef-1234-4321-bd6g-ff9007252e63",
|
2107
|
+
# "order_id": "6530219477767564494",
|
2108
|
+
# "client_oid": "CCXT_7ce730f0388441df9bc218",
|
2109
|
+
# "order_type": "LIMIT",
|
2110
|
+
# "time_in_force": "GOOD_TILL_CANCEL",
|
2111
|
+
# "side": "BUY",
|
2112
|
+
# "exec_inst": [],
|
2113
|
+
# "quantity": "0.00020",
|
2114
|
+
# "limit_price": "20000.00",
|
2115
|
+
# "order_value": "4",
|
2116
|
+
# "avg_price": "0",
|
2117
|
+
# "trigger_price": "0",
|
2118
|
+
# "ref_price": "0",
|
2119
|
+
# "cumulative_quantity": "0",
|
2120
|
+
# "cumulative_value": "0",
|
2121
|
+
# "cumulative_fee": "0",
|
2122
|
+
# "status": "ACTIVE",
|
2123
|
+
# "update_user_id": "ce075bef-1234-4321-bd6g-gg9007252e63",
|
2124
|
+
# "order_date": "2023-06-15",
|
2125
|
+
# "instrument_name": "BTC_USD",
|
2126
|
+
# "fee_instrument_name": "BTC",
|
2127
|
+
# "create_time": 1686806053992,
|
2128
|
+
# "create_time_ns": "1686806053992921880",
|
2129
|
+
# "update_time": 1686806053993
|
2130
|
+
# }
|
2131
|
+
#
|
2132
|
+
# createOrders
|
2133
|
+
# {
|
2134
|
+
# "code" : 306,
|
2135
|
+
# "index" : 1,
|
2136
|
+
# "client_oid" : "1698068111133_1",
|
2137
|
+
# "message" : "INSUFFICIENT_AVAILABLE_BALANCE",
|
2138
|
+
# "order_id" : "6142909896519488207"
|
2139
|
+
# }
|
2140
|
+
#
|
2141
|
+
code = self.safe_integer(order, 'code')
|
2142
|
+
if (code is not None) and (code != 0):
|
2143
|
+
return self.safe_order({
|
2144
|
+
'id': self.safe_string(order, 'order_id'),
|
2145
|
+
'clientOrderId': self.safe_string(order, 'client_oid'),
|
2146
|
+
'info': order,
|
2147
|
+
'status': 'rejected',
|
2148
|
+
})
|
2149
|
+
created = self.safe_integer(order, 'create_time')
|
2150
|
+
marketId = self.safe_string(order, 'instrument_name')
|
2151
|
+
symbol = self.safe_symbol(marketId, market)
|
2152
|
+
execInst = self.safe_value(order, 'exec_inst')
|
2153
|
+
postOnly = None
|
2154
|
+
if execInst is not None:
|
2155
|
+
postOnly = False
|
2156
|
+
for i in range(0, len(execInst)):
|
2157
|
+
inst = execInst[i]
|
2158
|
+
if inst == 'POST_ONLY':
|
2159
|
+
postOnly = True
|
2160
|
+
break
|
2161
|
+
feeCurrency = self.safe_string(order, 'fee_instrument_name')
|
2162
|
+
return self.safe_order({
|
2163
|
+
'info': order,
|
2164
|
+
'id': self.safe_string(order, 'order_id'),
|
2165
|
+
'clientOrderId': self.safe_string(order, 'client_oid'),
|
2166
|
+
'timestamp': created,
|
2167
|
+
'datetime': self.iso8601(created),
|
2168
|
+
'lastTradeTimestamp': self.safe_integer(order, 'update_time'),
|
2169
|
+
'status': self.parse_order_status(self.safe_string(order, 'status')),
|
2170
|
+
'symbol': symbol,
|
2171
|
+
'type': self.safe_string_lower(order, 'order_type'),
|
2172
|
+
'timeInForce': self.parse_time_in_force(self.safe_string(order, 'time_in_force')),
|
2173
|
+
'postOnly': postOnly,
|
2174
|
+
'side': self.safe_string_lower(order, 'side'),
|
2175
|
+
'price': self.safe_number(order, 'limit_price'),
|
2176
|
+
'amount': self.safe_number(order, 'quantity'),
|
2177
|
+
'filled': self.safe_number(order, 'cumulative_quantity'),
|
2178
|
+
'remaining': None,
|
2179
|
+
'average': self.safe_number(order, 'avg_price'),
|
2180
|
+
'cost': self.safe_number(order, 'cumulative_value'),
|
2181
|
+
'fee': {
|
2182
|
+
'currency': self.safe_currency_code(feeCurrency),
|
2183
|
+
'cost': self.safe_number(order, 'cumulative_fee'),
|
2184
|
+
},
|
2185
|
+
'trades': [],
|
2186
|
+
}, market)
|
2187
|
+
|
2188
|
+
def parse_deposit_status(self, status):
|
2189
|
+
statuses: dict = {
|
2190
|
+
'0': 'pending',
|
2191
|
+
'1': 'ok',
|
2192
|
+
'2': 'failed',
|
2193
|
+
'3': 'pending',
|
2194
|
+
}
|
2195
|
+
return self.safe_string(statuses, status, status)
|
2196
|
+
|
2197
|
+
def parse_withdrawal_status(self, status):
|
2198
|
+
statuses: dict = {
|
2199
|
+
'0': 'pending',
|
2200
|
+
'1': 'pending',
|
2201
|
+
'2': 'failed',
|
2202
|
+
'3': 'pending',
|
2203
|
+
'4': 'failed',
|
2204
|
+
'5': 'ok',
|
2205
|
+
'6': 'canceled',
|
2206
|
+
}
|
2207
|
+
return self.safe_string(statuses, status, status)
|
2208
|
+
|
2209
|
+
def parse_transaction(self, transaction: dict, currency: Currency = None) -> Transaction:
|
2210
|
+
#
|
2211
|
+
# fetchDeposits
|
2212
|
+
#
|
2213
|
+
# {
|
2214
|
+
# "currency": "BTC",
|
2215
|
+
# "fee": 0,
|
2216
|
+
# "create_time": 1688023659000,
|
2217
|
+
# "id": "6201135",
|
2218
|
+
# "update_time": 1688178509000,
|
2219
|
+
# "amount": 0.00114571,
|
2220
|
+
# "address": "1234fggxTSmJ3H4jaMQuWyEiLBzZdAbK6d",
|
2221
|
+
# "status": "1",
|
2222
|
+
# "txid": "f0ae4202b76eb999c301eccdde44dc639bee42d1fdd5974105286ca3393f6065/2"
|
2223
|
+
# }
|
2224
|
+
#
|
2225
|
+
# fetchWithdrawals
|
2226
|
+
#
|
2227
|
+
# {
|
2228
|
+
# "currency": "BTC",
|
2229
|
+
# "client_wid": "",
|
2230
|
+
# "fee": 0.0005,
|
2231
|
+
# "create_time": 1688613850000,
|
2232
|
+
# "id": "5775977",
|
2233
|
+
# "update_time": 1688613850000,
|
2234
|
+
# "amount": 0.0005,
|
2235
|
+
# "address": "1234NMEWbiF8ZkwUMxmfzMxi2A1MQ44bMn",
|
2236
|
+
# "status": "1",
|
2237
|
+
# "txid": "",
|
2238
|
+
# "network_id": "BTC"
|
2239
|
+
# }
|
2240
|
+
#
|
2241
|
+
# withdraw
|
2242
|
+
#
|
2243
|
+
# {
|
2244
|
+
# "id": 2220,
|
2245
|
+
# "amount": 1,
|
2246
|
+
# "fee": 0.0004,
|
2247
|
+
# "symbol": "BTC",
|
2248
|
+
# "address": "2NBqqD5GRJ8wHy1PYyCXTe9ke5226FhavBf",
|
2249
|
+
# "client_wid": "my_withdrawal_002",
|
2250
|
+
# "create_time":1607063412000
|
2251
|
+
# }
|
2252
|
+
#
|
2253
|
+
type = None
|
2254
|
+
rawStatus = self.safe_string(transaction, 'status')
|
2255
|
+
status = None
|
2256
|
+
if 'client_wid' in transaction:
|
2257
|
+
type = 'withdrawal'
|
2258
|
+
status = self.parse_withdrawal_status(rawStatus)
|
2259
|
+
else:
|
2260
|
+
type = 'deposit'
|
2261
|
+
status = self.parse_deposit_status(rawStatus)
|
2262
|
+
addressString = self.safe_string(transaction, 'address')
|
2263
|
+
address, tag = self.parse_address(addressString)
|
2264
|
+
currencyId = self.safe_string(transaction, 'currency')
|
2265
|
+
code = self.safe_currency_code(currencyId, currency)
|
2266
|
+
timestamp = self.safe_integer(transaction, 'create_time')
|
2267
|
+
feeCost = self.safe_number(transaction, 'fee')
|
2268
|
+
fee = None
|
2269
|
+
if feeCost is not None:
|
2270
|
+
fee = {'currency': code, 'cost': feeCost}
|
2271
|
+
return {
|
2272
|
+
'info': transaction,
|
2273
|
+
'id': self.safe_string(transaction, 'id'),
|
2274
|
+
'txid': self.safe_string(transaction, 'txid'),
|
2275
|
+
'timestamp': timestamp,
|
2276
|
+
'datetime': self.iso8601(timestamp),
|
2277
|
+
'network': None,
|
2278
|
+
'address': address,
|
2279
|
+
'addressTo': address,
|
2280
|
+
'addressFrom': None,
|
2281
|
+
'tag': tag,
|
2282
|
+
'tagTo': tag,
|
2283
|
+
'tagFrom': None,
|
2284
|
+
'type': type,
|
2285
|
+
'amount': self.safe_number(transaction, 'amount'),
|
2286
|
+
'currency': code,
|
2287
|
+
'status': status,
|
2288
|
+
'updated': self.safe_integer(transaction, 'update_time'),
|
2289
|
+
'internal': None,
|
2290
|
+
'comment': self.safe_string(transaction, 'client_wid'),
|
2291
|
+
'fee': fee,
|
2292
|
+
}
|
2293
|
+
|
2294
|
+
def custom_handle_margin_mode_and_params(self, methodName, params={}):
|
2295
|
+
"""
|
2296
|
+
@ignore
|
2297
|
+
marginMode specified by params["marginMode"], self.options["marginMode"], self.options["defaultMarginMode"], params["margin"] = True or self.options["defaultType"] = 'margin'
|
2298
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
2299
|
+
:returns Array: the marginMode in lowercase
|
2300
|
+
"""
|
2301
|
+
defaultType = self.safe_string(self.options, 'defaultType')
|
2302
|
+
isMargin = self.safe_bool(params, 'margin', False)
|
2303
|
+
params = self.omit(params, 'margin')
|
2304
|
+
marginMode = None
|
2305
|
+
marginMode, params = self.handle_margin_mode_and_params(methodName, params)
|
2306
|
+
if marginMode is not None:
|
2307
|
+
if marginMode != 'cross':
|
2308
|
+
raise NotSupported(self.id + ' only cross margin is supported')
|
2309
|
+
else:
|
2310
|
+
if (defaultType == 'margin') or (isMargin is True):
|
2311
|
+
marginMode = 'cross'
|
2312
|
+
return [marginMode, params]
|
2313
|
+
|
2314
|
+
def parse_deposit_withdraw_fee(self, fee, currency: Currency = None):
|
2315
|
+
#
|
2316
|
+
# {
|
2317
|
+
# "full_name": "Alchemix",
|
2318
|
+
# "default_network": "ETH",
|
2319
|
+
# "network_list": [
|
2320
|
+
# {
|
2321
|
+
# "network_id": "ETH",
|
2322
|
+
# "withdrawal_fee": "0.25000000",
|
2323
|
+
# "withdraw_enabled": True,
|
2324
|
+
# "min_withdrawal_amount": "0.5",
|
2325
|
+
# "deposit_enabled": True,
|
2326
|
+
# "confirmation_required": "0"
|
2327
|
+
# }
|
2328
|
+
# ]
|
2329
|
+
# }
|
2330
|
+
#
|
2331
|
+
networkList = self.safe_list(fee, 'network_list', [])
|
2332
|
+
networkListLength = len(networkList)
|
2333
|
+
result: dict = {
|
2334
|
+
'info': fee,
|
2335
|
+
'withdraw': {
|
2336
|
+
'fee': None,
|
2337
|
+
'percentage': None,
|
2338
|
+
},
|
2339
|
+
'deposit': {
|
2340
|
+
'fee': None,
|
2341
|
+
'percentage': None,
|
2342
|
+
},
|
2343
|
+
'networks': {},
|
2344
|
+
}
|
2345
|
+
if networkList is not None:
|
2346
|
+
for i in range(0, networkListLength):
|
2347
|
+
networkInfo = networkList[i]
|
2348
|
+
networkId = self.safe_string(networkInfo, 'network_id')
|
2349
|
+
currencyCode = self.safe_string(currency, 'code')
|
2350
|
+
networkCode = self.network_id_to_code(networkId, currencyCode)
|
2351
|
+
result['networks'][networkCode] = {
|
2352
|
+
'deposit': {'fee': None, 'percentage': None},
|
2353
|
+
'withdraw': {'fee': self.safe_number(networkInfo, 'withdrawal_fee'), 'percentage': False},
|
2354
|
+
}
|
2355
|
+
if networkListLength == 1:
|
2356
|
+
result['withdraw']['fee'] = self.safe_number(networkInfo, 'withdrawal_fee')
|
2357
|
+
result['withdraw']['percentage'] = False
|
2358
|
+
return result
|
2359
|
+
|
2360
|
+
def fetch_deposit_withdraw_fees(self, codes: Strings = None, params={}):
|
2361
|
+
"""
|
2362
|
+
fetch deposit and withdraw fees
|
2363
|
+
|
2364
|
+
https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-get-currency-networks
|
2365
|
+
|
2366
|
+
:param str[]|None codes: list of unified currency codes
|
2367
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
2368
|
+
:returns dict: a list of `fee structures <https://docs.ccxt.com/#/?id=fee-structure>`
|
2369
|
+
"""
|
2370
|
+
self.load_markets()
|
2371
|
+
response = self.v1PrivatePostPrivateGetCurrencyNetworks(params)
|
2372
|
+
data = self.safe_value(response, 'result')
|
2373
|
+
currencyMap = self.safe_list(data, 'currency_map')
|
2374
|
+
return self.parse_deposit_withdraw_fees(currencyMap, codes, 'full_name')
|
2375
|
+
|
2376
|
+
def fetch_ledger(self, code: Str = None, since: Int = None, limit: Int = None, params={}) -> List[LedgerEntry]:
|
2377
|
+
"""
|
2378
|
+
fetch the history of changes, actions done by the user or operations that altered the balance of the user
|
2379
|
+
|
2380
|
+
https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-get-transactions
|
2381
|
+
|
2382
|
+
:param str [code]: unified currency code
|
2383
|
+
:param int [since]: timestamp in ms of the earliest ledger entry
|
2384
|
+
:param int [limit]: max number of ledger entries to return
|
2385
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
2386
|
+
:param int [params.until]: timestamp in ms for the ending date filter, default is the current time
|
2387
|
+
:returns dict: a `ledger structure <https://docs.ccxt.com/#/?id=ledger>`
|
2388
|
+
"""
|
2389
|
+
self.load_markets()
|
2390
|
+
request: dict = {}
|
2391
|
+
currency = None
|
2392
|
+
if code is not None:
|
2393
|
+
currency = self.safe_currency(code)
|
2394
|
+
if since is not None:
|
2395
|
+
request['start_time'] = since
|
2396
|
+
if limit is not None:
|
2397
|
+
request['limit'] = limit
|
2398
|
+
until = self.safe_integer(params, 'until')
|
2399
|
+
params = self.omit(params, ['until'])
|
2400
|
+
if until is not None:
|
2401
|
+
request['end_time'] = until
|
2402
|
+
response = self.v1PrivatePostPrivateGetTransactions(self.extend(request, params))
|
2403
|
+
#
|
2404
|
+
# {
|
2405
|
+
# "id": 1686813195698,
|
2406
|
+
# "method": "private/get-transactions",
|
2407
|
+
# "code": 0,
|
2408
|
+
# "result": {
|
2409
|
+
# "data": [
|
2410
|
+
# {
|
2411
|
+
# "account_id": "ce075cef-1234-4321-bd6e-gf9007351e64",
|
2412
|
+
# "event_date": "2023-06-15",
|
2413
|
+
# "journal_type": "TRADING",
|
2414
|
+
# "journal_id": "6530219460124075091",
|
2415
|
+
# "transaction_qty": "6.0091224",
|
2416
|
+
# "transaction_cost": "6.0091224",
|
2417
|
+
# "realized_pnl": "0",
|
2418
|
+
# "order_id": "6530219477766741833",
|
2419
|
+
# "trade_id": "6530219495775954765",
|
2420
|
+
# "trade_match_id": "4611686018455865176",
|
2421
|
+
# "event_timestamp_ms": 1686804665013,
|
2422
|
+
# "event_timestamp_ns": "1686804665013642422",
|
2423
|
+
# "client_oid": "CCXT_d6ea7c5db6c1495aa8b758",
|
2424
|
+
# "taker_side": "",
|
2425
|
+
# "side": "BUY",
|
2426
|
+
# "instrument_name": "USD"
|
2427
|
+
# },
|
2428
|
+
# ]
|
2429
|
+
# }
|
2430
|
+
# }
|
2431
|
+
#
|
2432
|
+
result = self.safe_dict(response, 'result', {})
|
2433
|
+
ledger = self.safe_list(result, 'data', [])
|
2434
|
+
return self.parse_ledger(ledger, currency, since, limit)
|
2435
|
+
|
2436
|
+
def parse_ledger_entry(self, item: dict, currency: Currency = None) -> LedgerEntry:
|
2437
|
+
#
|
2438
|
+
# {
|
2439
|
+
# "account_id": "ce075cef-1234-4321-bd6e-gf9007351e64",
|
2440
|
+
# "event_date": "2023-06-15",
|
2441
|
+
# "journal_type": "TRADING",
|
2442
|
+
# "journal_id": "6530219460124075091",
|
2443
|
+
# "transaction_qty": "6.0091224",
|
2444
|
+
# "transaction_cost": "6.0091224",
|
2445
|
+
# "realized_pnl": "0",
|
2446
|
+
# "order_id": "6530219477766741833",
|
2447
|
+
# "trade_id": "6530219495775954765",
|
2448
|
+
# "trade_match_id": "4611686018455865176",
|
2449
|
+
# "event_timestamp_ms": 1686804665013,
|
2450
|
+
# "event_timestamp_ns": "1686804665013642422",
|
2451
|
+
# "client_oid": "CCXT_d6ea7c5db6c1495aa8b758",
|
2452
|
+
# "taker_side": "",
|
2453
|
+
# "side": "BUY",
|
2454
|
+
# "instrument_name": "USD"
|
2455
|
+
# }
|
2456
|
+
#
|
2457
|
+
timestamp = self.safe_integer(item, 'event_timestamp_ms')
|
2458
|
+
currencyId = self.safe_string(item, 'instrument_name')
|
2459
|
+
code = self.safe_currency_code(currencyId, currency)
|
2460
|
+
currency = self.safe_currency(currencyId, currency)
|
2461
|
+
amount = self.safe_string(item, 'transaction_qty')
|
2462
|
+
direction = None
|
2463
|
+
if Precise.string_lt(amount, '0'):
|
2464
|
+
direction = 'out'
|
2465
|
+
amount = Precise.string_abs(amount)
|
2466
|
+
else:
|
2467
|
+
direction = 'in'
|
2468
|
+
return self.safe_ledger_entry({
|
2469
|
+
'info': item,
|
2470
|
+
'id': self.safe_string(item, 'order_id'),
|
2471
|
+
'direction': direction,
|
2472
|
+
'account': self.safe_string(item, 'account_id'),
|
2473
|
+
'referenceId': self.safe_string(item, 'trade_id'),
|
2474
|
+
'referenceAccount': self.safe_string(item, 'trade_match_id'),
|
2475
|
+
'type': self.parse_ledger_entry_type(self.safe_string(item, 'journal_type')),
|
2476
|
+
'currency': code,
|
2477
|
+
'amount': self.parse_number(amount),
|
2478
|
+
'timestamp': timestamp,
|
2479
|
+
'datetime': self.iso8601(timestamp),
|
2480
|
+
'before': None,
|
2481
|
+
'after': None,
|
2482
|
+
'status': None,
|
2483
|
+
'fee': {
|
2484
|
+
'currency': None,
|
2485
|
+
'cost': None,
|
2486
|
+
},
|
2487
|
+
}, currency)
|
2488
|
+
|
2489
|
+
def parse_ledger_entry_type(self, type):
|
2490
|
+
ledgerType: dict = {
|
2491
|
+
'TRADING': 'trade',
|
2492
|
+
'TRADE_FEE': 'fee',
|
2493
|
+
'WITHDRAW_FEE': 'fee',
|
2494
|
+
'WITHDRAW': 'withdrawal',
|
2495
|
+
'DEPOSIT': 'deposit',
|
2496
|
+
'ROLLBACK_WITHDRAW': 'rollback',
|
2497
|
+
'ROLLBACK_DEPOSIT': 'rollback',
|
2498
|
+
'FUNDING': 'fee',
|
2499
|
+
'REALIZED_PNL': 'trade',
|
2500
|
+
'INSURANCE_FUND': 'insurance',
|
2501
|
+
'SOCIALIZED_LOSS': 'trade',
|
2502
|
+
'LIQUIDATION_FEE': 'fee',
|
2503
|
+
'SESSION_RESET': 'reset',
|
2504
|
+
'ADJUSTMENT': 'adjustment',
|
2505
|
+
'SESSION_SETTLE': 'settlement',
|
2506
|
+
'UNCOVERED_LOSS': 'trade',
|
2507
|
+
'ADMIN_ADJUSTMENT': 'adjustment',
|
2508
|
+
'DELIST': 'delist',
|
2509
|
+
'SETTLEMENT_FEE': 'fee',
|
2510
|
+
'AUTO_CONVERSION': 'conversion',
|
2511
|
+
'MANUAL_CONVERSION': 'conversion',
|
2512
|
+
}
|
2513
|
+
return self.safe_string(ledgerType, type, type)
|
2514
|
+
|
2515
|
+
def fetch_accounts(self, params={}) -> List[Account]:
|
2516
|
+
"""
|
2517
|
+
fetch all the accounts associated with a profile
|
2518
|
+
|
2519
|
+
https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-get-accounts
|
2520
|
+
|
2521
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
2522
|
+
:returns dict: a dictionary of `account structures <https://docs.ccxt.com/#/?id=account-structure>` indexed by the account type
|
2523
|
+
"""
|
2524
|
+
self.load_markets()
|
2525
|
+
response = self.v1PrivatePostPrivateGetAccounts(params)
|
2526
|
+
#
|
2527
|
+
# {
|
2528
|
+
# "id": 1234567894321,
|
2529
|
+
# "method": "private/get-accounts",
|
2530
|
+
# "code": 0,
|
2531
|
+
# "result": {
|
2532
|
+
# "master_account": {
|
2533
|
+
# "uuid": "a1234abc-1234-4321-q5r7-b1ab0a0b12b",
|
2534
|
+
# "user_uuid": "a1234abc-1234-4321-q5r7-b1ab0a0b12b",
|
2535
|
+
# "enabled": True,
|
2536
|
+
# "tradable": True,
|
2537
|
+
# "name": "YOUR_NAME",
|
2538
|
+
# "country_code": "CAN",
|
2539
|
+
# "phone_country_code": "CAN",
|
2540
|
+
# "incorp_country_code": "",
|
2541
|
+
# "margin_access": "DEFAULT",
|
2542
|
+
# "derivatives_access": "DEFAULT",
|
2543
|
+
# "create_time": 1656445188000,
|
2544
|
+
# "update_time": 1660794567262,
|
2545
|
+
# "two_fa_enabled": True,
|
2546
|
+
# "kyc_level": "ADVANCED",
|
2547
|
+
# "suspended": False,
|
2548
|
+
# "terminated": False,
|
2549
|
+
# "spot_enabled": False,
|
2550
|
+
# "margin_enabled": False,
|
2551
|
+
# "derivatives_enabled": False
|
2552
|
+
# },
|
2553
|
+
# "sub_account_list": []
|
2554
|
+
# }
|
2555
|
+
# }
|
2556
|
+
#
|
2557
|
+
result = self.safe_dict(response, 'result', {})
|
2558
|
+
masterAccount = self.safe_dict(result, 'master_account', {})
|
2559
|
+
accounts = self.safe_list(result, 'sub_account_list', [])
|
2560
|
+
accounts.append(masterAccount)
|
2561
|
+
return self.parse_accounts(accounts, params)
|
2562
|
+
|
2563
|
+
def parse_account(self, account):
|
2564
|
+
#
|
2565
|
+
# {
|
2566
|
+
# "uuid": "a1234abc-1234-4321-q5r7-b1ab0a0b12b",
|
2567
|
+
# "user_uuid": "a1234abc-1234-4321-q5r7-b1ab0a0b12b",
|
2568
|
+
# "master_account_uuid": "a1234abc-1234-4321-q5r7-b1ab0a0b12b",
|
2569
|
+
# "label": "FORMER_MASTER_MARGIN",
|
2570
|
+
# "enabled": True,
|
2571
|
+
# "tradable": True,
|
2572
|
+
# "name": "YOUR_NAME",
|
2573
|
+
# "country_code": "YOUR_COUNTRY_CODE",
|
2574
|
+
# "incorp_country_code": "",
|
2575
|
+
# "margin_access": "DEFAULT",
|
2576
|
+
# "derivatives_access": "DEFAULT",
|
2577
|
+
# "create_time": 1656481992000,
|
2578
|
+
# "update_time": 1667272884594,
|
2579
|
+
# "two_fa_enabled": False,
|
2580
|
+
# "kyc_level": "ADVANCED",
|
2581
|
+
# "suspended": False,
|
2582
|
+
# "terminated": False,
|
2583
|
+
# "spot_enabled": False,
|
2584
|
+
# "margin_enabled": False,
|
2585
|
+
# "derivatives_enabled": False,
|
2586
|
+
# "system_label": "FORMER_MASTER_MARGIN"
|
2587
|
+
# }
|
2588
|
+
#
|
2589
|
+
return {
|
2590
|
+
'id': self.safe_string(account, 'uuid'),
|
2591
|
+
'type': self.safe_string(account, 'label'),
|
2592
|
+
'code': None,
|
2593
|
+
'info': account,
|
2594
|
+
}
|
2595
|
+
|
2596
|
+
def fetch_settlement_history(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}):
|
2597
|
+
"""
|
2598
|
+
fetches historical settlement records
|
2599
|
+
|
2600
|
+
https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#public-get-expired-settlement-price
|
2601
|
+
|
2602
|
+
:param str symbol: unified market symbol of the settlement history
|
2603
|
+
:param int [since]: timestamp in ms
|
2604
|
+
:param int [limit]: number of records
|
2605
|
+
:param dict [params]: exchange specific params
|
2606
|
+
:param int [params.type]: 'future', 'option'
|
2607
|
+
:returns dict[]: a list of `settlement history objects <https://docs.ccxt.com/#/?id=settlement-history-structure>`
|
2608
|
+
"""
|
2609
|
+
self.load_markets()
|
2610
|
+
market = None
|
2611
|
+
if symbol is not None:
|
2612
|
+
market = self.market(symbol)
|
2613
|
+
type = None
|
2614
|
+
type, params = self.handle_market_type_and_params('fetchSettlementHistory', market, params)
|
2615
|
+
self.check_required_argument('fetchSettlementHistory', type, 'type', ['future', 'option', 'WARRANT', 'FUTURE'])
|
2616
|
+
if type == 'option':
|
2617
|
+
type = 'WARRANT'
|
2618
|
+
request: dict = {
|
2619
|
+
'instrument_type': type.upper(),
|
2620
|
+
}
|
2621
|
+
response = self.v1PublicGetPublicGetExpiredSettlementPrice(self.extend(request, params))
|
2622
|
+
#
|
2623
|
+
# {
|
2624
|
+
# "id": -1,
|
2625
|
+
# "method": "public/get-expired-settlement-price",
|
2626
|
+
# "code": 0,
|
2627
|
+
# "result": {
|
2628
|
+
# "data": [
|
2629
|
+
# {
|
2630
|
+
# "i": "BTCUSD-230526",
|
2631
|
+
# "x": 1685088000000,
|
2632
|
+
# "v": "26464.1",
|
2633
|
+
# "t": 1685087999500
|
2634
|
+
# }
|
2635
|
+
# ]
|
2636
|
+
# }
|
2637
|
+
# }
|
2638
|
+
#
|
2639
|
+
result = self.safe_dict(response, 'result', {})
|
2640
|
+
data = self.safe_list(result, 'data', [])
|
2641
|
+
settlements = self.parse_settlements(data, market)
|
2642
|
+
sorted = self.sort_by(settlements, 'timestamp')
|
2643
|
+
return self.filter_by_symbol_since_limit(sorted, symbol, since, limit)
|
2644
|
+
|
2645
|
+
def parse_settlement(self, settlement, market):
|
2646
|
+
#
|
2647
|
+
# {
|
2648
|
+
# "i": "BTCUSD-230526",
|
2649
|
+
# "x": 1685088000000,
|
2650
|
+
# "v": "26464.1",
|
2651
|
+
# "t": 1685087999500
|
2652
|
+
# }
|
2653
|
+
#
|
2654
|
+
timestamp = self.safe_integer(settlement, 'x')
|
2655
|
+
marketId = self.safe_string(settlement, 'i')
|
2656
|
+
return {
|
2657
|
+
'info': settlement,
|
2658
|
+
'symbol': self.safe_symbol(marketId, market),
|
2659
|
+
'price': self.safe_number(settlement, 'v'),
|
2660
|
+
'timestamp': timestamp,
|
2661
|
+
'datetime': self.iso8601(timestamp),
|
2662
|
+
}
|
2663
|
+
|
2664
|
+
def parse_settlements(self, settlements, market):
|
2665
|
+
#
|
2666
|
+
# [
|
2667
|
+
# {
|
2668
|
+
# "i": "BTCUSD-230526",
|
2669
|
+
# "x": 1685088000000,
|
2670
|
+
# "v": "26464.1",
|
2671
|
+
# "t": 1685087999500
|
2672
|
+
# }
|
2673
|
+
# ]
|
2674
|
+
#
|
2675
|
+
result = []
|
2676
|
+
for i in range(0, len(settlements)):
|
2677
|
+
result.append(self.parse_settlement(settlements[i], market))
|
2678
|
+
return result
|
2679
|
+
|
2680
|
+
def fetch_funding_rate_history(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}):
|
2681
|
+
"""
|
2682
|
+
fetches historical funding rates
|
2683
|
+
|
2684
|
+
https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#public-get-valuations
|
2685
|
+
|
2686
|
+
:param str symbol: unified symbol of the market to fetch the funding rate history for
|
2687
|
+
:param int [since]: timestamp in ms of the earliest funding rate to fetch
|
2688
|
+
:param int [limit]: the maximum amount of [funding rate structures] to fetch
|
2689
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
2690
|
+
:param int [params.until]: timestamp in ms for the ending date filter, default is the current time
|
2691
|
+
:param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
|
2692
|
+
:returns dict[]: a list of `funding rate structures <https://docs.ccxt.com/#/?id=funding-rate-history-structure>`
|
2693
|
+
"""
|
2694
|
+
if symbol is None:
|
2695
|
+
raise ArgumentsRequired(self.id + ' fetchFundingRateHistory() requires a symbol argument')
|
2696
|
+
self.load_markets()
|
2697
|
+
paginate = False
|
2698
|
+
paginate, params = self.handle_option_and_params(params, 'fetchFundingRateHistory', 'paginate')
|
2699
|
+
if paginate:
|
2700
|
+
return self.fetch_paginated_call_deterministic('fetchFundingRateHistory', symbol, since, limit, '8h', params)
|
2701
|
+
market = self.market(symbol)
|
2702
|
+
if not market['swap']:
|
2703
|
+
raise BadSymbol(self.id + ' fetchFundingRateHistory() supports swap contracts only')
|
2704
|
+
request: dict = {
|
2705
|
+
'instrument_name': market['id'],
|
2706
|
+
'valuation_type': 'funding_hist',
|
2707
|
+
}
|
2708
|
+
if since is not None:
|
2709
|
+
request['start_ts'] = since
|
2710
|
+
if limit is not None:
|
2711
|
+
request['count'] = limit
|
2712
|
+
until = self.safe_integer(params, 'until')
|
2713
|
+
params = self.omit(params, ['until'])
|
2714
|
+
if until is not None:
|
2715
|
+
request['end_ts'] = until
|
2716
|
+
response = self.v1PublicGetPublicGetValuations(self.extend(request, params))
|
2717
|
+
#
|
2718
|
+
# {
|
2719
|
+
# "id": -1,
|
2720
|
+
# "method": "public/get-valuations",
|
2721
|
+
# "code": 0,
|
2722
|
+
# "result": {
|
2723
|
+
# "data": [
|
2724
|
+
# {
|
2725
|
+
# "v": "-0.000001884",
|
2726
|
+
# "t": 1687892400000
|
2727
|
+
# },
|
2728
|
+
# ],
|
2729
|
+
# "instrument_name": "BTCUSD-PERP"
|
2730
|
+
# }
|
2731
|
+
# }
|
2732
|
+
#
|
2733
|
+
result = self.safe_dict(response, 'result', {})
|
2734
|
+
data = self.safe_list(result, 'data', [])
|
2735
|
+
marketId = self.safe_string(result, 'instrument_name')
|
2736
|
+
rates = []
|
2737
|
+
for i in range(0, len(data)):
|
2738
|
+
entry = data[i]
|
2739
|
+
timestamp = self.safe_integer(entry, 't')
|
2740
|
+
rates.append({
|
2741
|
+
'info': entry,
|
2742
|
+
'symbol': self.safe_symbol(marketId, market),
|
2743
|
+
'fundingRate': self.safe_number(entry, 'v'),
|
2744
|
+
'timestamp': timestamp,
|
2745
|
+
'datetime': self.iso8601(timestamp),
|
2746
|
+
})
|
2747
|
+
sorted = self.sort_by(rates, 'timestamp')
|
2748
|
+
return self.filter_by_symbol_since_limit(sorted, market['symbol'], since, limit)
|
2749
|
+
|
2750
|
+
def fetch_position(self, symbol: str, params={}):
|
2751
|
+
"""
|
2752
|
+
fetch data on a single open contract trade position
|
2753
|
+
|
2754
|
+
https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-get-positions
|
2755
|
+
|
2756
|
+
:param str symbol: unified market symbol of the market the position is held in
|
2757
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
2758
|
+
:returns dict: a `position structure <https://docs.ccxt.com/#/?id=position-structure>`
|
2759
|
+
"""
|
2760
|
+
self.load_markets()
|
2761
|
+
market = self.market(symbol)
|
2762
|
+
request: dict = {
|
2763
|
+
'instrument_name': market['id'],
|
2764
|
+
}
|
2765
|
+
response = self.v1PrivatePostPrivateGetPositions(self.extend(request, params))
|
2766
|
+
#
|
2767
|
+
# {
|
2768
|
+
# "id": 1688015952050,
|
2769
|
+
# "method": "private/get-positions",
|
2770
|
+
# "code": 0,
|
2771
|
+
# "result": {
|
2772
|
+
# "data": [
|
2773
|
+
# {
|
2774
|
+
# "account_id": "ce075bef-b600-4277-bd6e-ff9007251e63",
|
2775
|
+
# "quantity": "0.0001",
|
2776
|
+
# "cost": "3.02392",
|
2777
|
+
# "open_pos_cost": "3.02392",
|
2778
|
+
# "open_position_pnl": "-0.0010281328",
|
2779
|
+
# "session_pnl": "-0.0010281328",
|
2780
|
+
# "update_timestamp_ms": 1688015919091,
|
2781
|
+
# "instrument_name": "BTCUSD-PERP",
|
2782
|
+
# "type": "PERPETUAL_SWAP"
|
2783
|
+
# }
|
2784
|
+
# ]
|
2785
|
+
# }
|
2786
|
+
# }
|
2787
|
+
#
|
2788
|
+
result = self.safe_dict(response, 'result', {})
|
2789
|
+
data = self.safe_list(result, 'data', [])
|
2790
|
+
return self.parse_position(self.safe_dict(data, 0), market)
|
2791
|
+
|
2792
|
+
def fetch_positions(self, symbols: Strings = None, params={}):
|
2793
|
+
"""
|
2794
|
+
fetch all open positions
|
2795
|
+
|
2796
|
+
https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-get-positions
|
2797
|
+
|
2798
|
+
:param str[]|None symbols: list of unified market symbols
|
2799
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
2800
|
+
:returns dict[]: a list of `position structure <https://docs.ccxt.com/#/?id=position-structure>`
|
2801
|
+
"""
|
2802
|
+
self.load_markets()
|
2803
|
+
symbols = self.market_symbols(symbols)
|
2804
|
+
request: dict = {}
|
2805
|
+
market = None
|
2806
|
+
if symbols is not None:
|
2807
|
+
symbol = None
|
2808
|
+
if isinstance(symbols, list):
|
2809
|
+
symbolsLength = len(symbols)
|
2810
|
+
if symbolsLength > 1:
|
2811
|
+
raise BadRequest(self.id + ' fetchPositions() symbols argument cannot contain more than 1 symbol')
|
2812
|
+
symbol = symbols[0]
|
2813
|
+
else:
|
2814
|
+
symbol = symbols
|
2815
|
+
market = self.market(symbol)
|
2816
|
+
request['instrument_name'] = market['id']
|
2817
|
+
response = self.v1PrivatePostPrivateGetPositions(self.extend(request, params))
|
2818
|
+
#
|
2819
|
+
# {
|
2820
|
+
# "id": 1688015952050,
|
2821
|
+
# "method": "private/get-positions",
|
2822
|
+
# "code": 0,
|
2823
|
+
# "result": {
|
2824
|
+
# "data": [
|
2825
|
+
# {
|
2826
|
+
# "account_id": "ce075bef-b600-4277-bd6e-ff9007251e63",
|
2827
|
+
# "quantity": "0.0001",
|
2828
|
+
# "cost": "3.02392",
|
2829
|
+
# "open_pos_cost": "3.02392",
|
2830
|
+
# "open_position_pnl": "-0.0010281328",
|
2831
|
+
# "session_pnl": "-0.0010281328",
|
2832
|
+
# "update_timestamp_ms": 1688015919091,
|
2833
|
+
# "instrument_name": "BTCUSD-PERP",
|
2834
|
+
# "type": "PERPETUAL_SWAP"
|
2835
|
+
# }
|
2836
|
+
# ]
|
2837
|
+
# }
|
2838
|
+
# }
|
2839
|
+
#
|
2840
|
+
responseResult = self.safe_dict(response, 'result', {})
|
2841
|
+
positions = self.safe_list(responseResult, 'data', [])
|
2842
|
+
result = []
|
2843
|
+
for i in range(0, len(positions)):
|
2844
|
+
entry = positions[i]
|
2845
|
+
marketId = self.safe_string(entry, 'instrument_name')
|
2846
|
+
marketInner = self.safe_market(marketId, None, None, 'contract')
|
2847
|
+
result.append(self.parse_position(entry, marketInner))
|
2848
|
+
return self.filter_by_array_positions(result, 'symbol', None, False)
|
2849
|
+
|
2850
|
+
def parse_position(self, position: dict, market: Market = None):
|
2851
|
+
#
|
2852
|
+
# {
|
2853
|
+
# "account_id": "ce075bef-b600-4277-bd6e-ff9007251e63",
|
2854
|
+
# "quantity": "0.0001",
|
2855
|
+
# "cost": "3.02392",
|
2856
|
+
# "open_pos_cost": "3.02392",
|
2857
|
+
# "open_position_pnl": "-0.0010281328",
|
2858
|
+
# "session_pnl": "-0.0010281328",
|
2859
|
+
# "update_timestamp_ms": 1688015919091,
|
2860
|
+
# "instrument_name": "BTCUSD-PERP",
|
2861
|
+
# "type": "PERPETUAL_SWAP"
|
2862
|
+
# }
|
2863
|
+
#
|
2864
|
+
marketId = self.safe_string(position, 'instrument_name')
|
2865
|
+
market = self.safe_market(marketId, market, None, 'contract')
|
2866
|
+
symbol = self.safe_symbol(marketId, market, None, 'contract')
|
2867
|
+
timestamp = self.safe_integer(position, 'update_timestamp_ms')
|
2868
|
+
amount = self.safe_string(position, 'quantity')
|
2869
|
+
return self.safe_position({
|
2870
|
+
'info': position,
|
2871
|
+
'id': None,
|
2872
|
+
'symbol': symbol,
|
2873
|
+
'timestamp': timestamp,
|
2874
|
+
'datetime': self.iso8601(timestamp),
|
2875
|
+
'hedged': None,
|
2876
|
+
'side': 'buy' if Precise.string_gt(amount, '0') else 'sell',
|
2877
|
+
'contracts': Precise.string_abs(amount),
|
2878
|
+
'contractSize': market['contractSize'],
|
2879
|
+
'entryPrice': None,
|
2880
|
+
'markPrice': None,
|
2881
|
+
'notional': None,
|
2882
|
+
'leverage': None,
|
2883
|
+
'collateral': self.safe_number(position, 'open_pos_cost'),
|
2884
|
+
'initialMargin': self.safe_number(position, 'cost'),
|
2885
|
+
'maintenanceMargin': None,
|
2886
|
+
'initialMarginPercentage': None,
|
2887
|
+
'maintenanceMarginPercentage': None,
|
2888
|
+
'unrealizedPnl': self.safe_number(position, 'open_position_pnl'),
|
2889
|
+
'liquidationPrice': None,
|
2890
|
+
'marginMode': None,
|
2891
|
+
'percentage': None,
|
2892
|
+
'marginRatio': None,
|
2893
|
+
'stopLossPrice': None,
|
2894
|
+
'takeProfitPrice': None,
|
2895
|
+
})
|
2896
|
+
|
2897
|
+
def nonce(self):
|
2898
|
+
return self.milliseconds()
|
2899
|
+
|
2900
|
+
def params_to_string(self, object, level):
|
2901
|
+
maxLevel = 3
|
2902
|
+
if level >= maxLevel:
|
2903
|
+
return str(object)
|
2904
|
+
if isinstance(object, str):
|
2905
|
+
return object
|
2906
|
+
returnString = ''
|
2907
|
+
paramsKeys = None
|
2908
|
+
if isinstance(object, list):
|
2909
|
+
paramsKeys = object
|
2910
|
+
else:
|
2911
|
+
sorted = self.keysort(object)
|
2912
|
+
paramsKeys = list(sorted.keys())
|
2913
|
+
for i in range(0, len(paramsKeys)):
|
2914
|
+
key = paramsKeys[i]
|
2915
|
+
returnString += key
|
2916
|
+
value = object[key]
|
2917
|
+
if value == 'None':
|
2918
|
+
returnString += 'None'
|
2919
|
+
elif isinstance(value, list):
|
2920
|
+
for j in range(0, len(value)):
|
2921
|
+
returnString += self.params_to_string(value[j], level + 1)
|
2922
|
+
else:
|
2923
|
+
returnString += str(value)
|
2924
|
+
return returnString
|
2925
|
+
|
2926
|
+
def close_position(self, symbol: str, side: OrderSide = None, params={}) -> Order:
|
2927
|
+
"""
|
2928
|
+
closes open positions for a market
|
2929
|
+
|
2930
|
+
https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-close-position
|
2931
|
+
|
2932
|
+
:param str symbol: Unified CCXT market symbol
|
2933
|
+
:param str [side]: not used by cryptocom.closePositions
|
2934
|
+
:param dict [params]: extra parameters specific to the okx api endpoint
|
2935
|
+
|
2936
|
+
EXCHANGE SPECIFIC PARAMETERS
|
2937
|
+
:param str [params.type]: LIMIT or MARKET
|
2938
|
+
:param number [params.price]: for limit orders only
|
2939
|
+
:returns dict[]: `A list of position structures <https://docs.ccxt.com/#/?id=position-structure>`
|
2940
|
+
"""
|
2941
|
+
self.load_markets()
|
2942
|
+
market = self.market(symbol)
|
2943
|
+
request: dict = {
|
2944
|
+
'instrument_name': market['id'],
|
2945
|
+
'type': 'MARKET',
|
2946
|
+
}
|
2947
|
+
type = self.safe_string_upper(params, 'type')
|
2948
|
+
price = self.safe_string(params, 'price')
|
2949
|
+
if type is not None:
|
2950
|
+
request['type'] = type
|
2951
|
+
if price is not None:
|
2952
|
+
request['price'] = self.price_to_precision(market['symbol'], price)
|
2953
|
+
response = self.v1PrivatePostPrivateClosePosition(self.extend(request, params))
|
2954
|
+
#
|
2955
|
+
# {
|
2956
|
+
# "id" : 1700830813298,
|
2957
|
+
# "method" : "private/close-position",
|
2958
|
+
# "code" : 0,
|
2959
|
+
# "result" : {
|
2960
|
+
# "client_oid" : "179a909d-5614-655b-0d0e-9e85c9a25c85",
|
2961
|
+
# "order_id" : "6142909897021751347"
|
2962
|
+
# }
|
2963
|
+
# }
|
2964
|
+
#
|
2965
|
+
result = self.safe_dict(response, 'result')
|
2966
|
+
return self.parse_order(result, market)
|
2967
|
+
|
2968
|
+
def fetch_trading_fee(self, symbol: str, params={}) -> TradingFeeInterface:
|
2969
|
+
"""
|
2970
|
+
fetch the trading fees for a market
|
2971
|
+
|
2972
|
+
https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-get-instrument-fee-rate
|
2973
|
+
|
2974
|
+
:param str symbol: unified market symbol
|
2975
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
2976
|
+
:returns dict: a `fee structure <https://docs.ccxt.com/#/?id=fee-structure>`
|
2977
|
+
"""
|
2978
|
+
self.load_markets()
|
2979
|
+
market = self.market(symbol)
|
2980
|
+
request: dict = {
|
2981
|
+
'instrument_name': market['id'],
|
2982
|
+
}
|
2983
|
+
response = self.v1PrivatePostPrivateGetInstrumentFeeRate(self.extend(request, params))
|
2984
|
+
#
|
2985
|
+
# {
|
2986
|
+
# "id": 1,
|
2987
|
+
# "code": 0,
|
2988
|
+
# "method": "private/staking/unstake",
|
2989
|
+
# "result": {
|
2990
|
+
# "staking_id": "1",
|
2991
|
+
# "instrument_name": "SOL.staked",
|
2992
|
+
# "status": "NEW",
|
2993
|
+
# "quantity": "1",
|
2994
|
+
# "underlying_inst_name": "SOL",
|
2995
|
+
# "reason": "NO_ERROR"
|
2996
|
+
# }
|
2997
|
+
# }
|
2998
|
+
#
|
2999
|
+
data = self.safe_dict(response, 'result', {})
|
3000
|
+
return self.parse_trading_fee(data, market)
|
3001
|
+
|
3002
|
+
def fetch_trading_fees(self, params={}) -> TradingFees:
|
3003
|
+
"""
|
3004
|
+
|
3005
|
+
https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-get-fee-rate
|
3006
|
+
|
3007
|
+
fetch the trading fees for multiple markets
|
3008
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
3009
|
+
:returns dict: a dictionary of `fee structures <https://docs.ccxt.com/#/?id=fee-structure>` indexed by market symbols
|
3010
|
+
"""
|
3011
|
+
self.load_markets()
|
3012
|
+
response = self.v1PrivatePostPrivateGetFeeRate(params)
|
3013
|
+
#
|
3014
|
+
# {
|
3015
|
+
# "id": 1,
|
3016
|
+
# "method": "/private/get-fee-rate",
|
3017
|
+
# "code": 0,
|
3018
|
+
# "result": {
|
3019
|
+
# "spot_tier": "3",
|
3020
|
+
# "deriv_tier": "3",
|
3021
|
+
# "effective_spot_maker_rate_bps": "6.5",
|
3022
|
+
# "effective_spot_taker_rate_bps": "6.9",
|
3023
|
+
# "effective_deriv_maker_rate_bps": "1.1",
|
3024
|
+
# "effective_deriv_taker_rate_bps": "3"
|
3025
|
+
# }
|
3026
|
+
# }
|
3027
|
+
#
|
3028
|
+
result = self.safe_dict(response, 'result', {})
|
3029
|
+
return self.parse_trading_fees(result)
|
3030
|
+
|
3031
|
+
def parse_trading_fees(self, response):
|
3032
|
+
#
|
3033
|
+
# {
|
3034
|
+
# "spot_tier": "3",
|
3035
|
+
# "deriv_tier": "3",
|
3036
|
+
# "effective_spot_maker_rate_bps": "6.5",
|
3037
|
+
# "effective_spot_taker_rate_bps": "6.9",
|
3038
|
+
# "effective_deriv_maker_rate_bps": "1.1",
|
3039
|
+
# "effective_deriv_taker_rate_bps": "3"
|
3040
|
+
# }
|
3041
|
+
#
|
3042
|
+
result: dict = {}
|
3043
|
+
result['info'] = response
|
3044
|
+
for i in range(0, len(self.symbols)):
|
3045
|
+
symbol = self.symbols[i]
|
3046
|
+
market = self.market(symbol)
|
3047
|
+
isSwap = market['swap']
|
3048
|
+
takerFeeKey = 'effective_deriv_taker_rate_bps' if isSwap else 'effective_spot_taker_rate_bps'
|
3049
|
+
makerFeeKey = 'effective_deriv_maker_rate_bps' if isSwap else 'effective_spot_maker_rate_bps'
|
3050
|
+
tradingFee = {
|
3051
|
+
'info': response,
|
3052
|
+
'symbol': symbol,
|
3053
|
+
'maker': self.parse_number(Precise.string_div(self.safe_string(response, makerFeeKey), '10000')),
|
3054
|
+
'taker': self.parse_number(Precise.string_div(self.safe_string(response, takerFeeKey), '10000')),
|
3055
|
+
'percentage': None,
|
3056
|
+
'tierBased': None,
|
3057
|
+
}
|
3058
|
+
result[symbol] = tradingFee
|
3059
|
+
return result
|
3060
|
+
|
3061
|
+
def parse_trading_fee(self, fee: dict, market: Market = None) -> TradingFeeInterface:
|
3062
|
+
#
|
3063
|
+
# {
|
3064
|
+
# "instrument_name": "BTC_USD",
|
3065
|
+
# "effective_maker_rate_bps": "6.5",
|
3066
|
+
# "effective_taker_rate_bps": "6.9"
|
3067
|
+
# }
|
3068
|
+
#
|
3069
|
+
marketId = self.safe_string(fee, 'instrument_name')
|
3070
|
+
symbol = self.safe_symbol(marketId, market)
|
3071
|
+
return {
|
3072
|
+
'info': fee,
|
3073
|
+
'symbol': symbol,
|
3074
|
+
'maker': self.parse_number(Precise.string_div(self.safe_string(fee, 'effective_maker_rate_bps'), '10000')),
|
3075
|
+
'taker': self.parse_number(Precise.string_div(self.safe_string(fee, 'effective_taker_rate_bps'), '10000')),
|
3076
|
+
'percentage': None,
|
3077
|
+
'tierBased': None,
|
3078
|
+
}
|
3079
|
+
|
3080
|
+
def sign(self, path, api='public', method='GET', params={}, headers=None, body=None):
|
3081
|
+
type = self.safe_string(api, 0)
|
3082
|
+
access = self.safe_string(api, 1)
|
3083
|
+
url = self.urls['api'][type] + '/' + path
|
3084
|
+
query = self.omit(params, self.extract_params(path))
|
3085
|
+
if access == 'public':
|
3086
|
+
if query:
|
3087
|
+
url += '?' + self.urlencode(query)
|
3088
|
+
else:
|
3089
|
+
self.check_required_credentials()
|
3090
|
+
nonce = str(self.nonce())
|
3091
|
+
requestParams = self.extend({}, params)
|
3092
|
+
paramsKeys = list(requestParams.keys())
|
3093
|
+
strSortKey = self.params_to_string(requestParams, 0)
|
3094
|
+
payload = path + nonce + self.apiKey + strSortKey + nonce
|
3095
|
+
signature = self.hmac(self.encode(payload), self.encode(self.secret), hashlib.sha256)
|
3096
|
+
paramsKeysLength = len(paramsKeys)
|
3097
|
+
body = self.json({
|
3098
|
+
'id': nonce,
|
3099
|
+
'method': path,
|
3100
|
+
'params': params,
|
3101
|
+
'api_key': self.apiKey,
|
3102
|
+
'sig': signature,
|
3103
|
+
'nonce': nonce,
|
3104
|
+
})
|
3105
|
+
# fix issue https://github.com/ccxt/ccxt/issues/11179
|
3106
|
+
# php always encodes dictionaries
|
3107
|
+
# if an array is empty, php will put it in square brackets
|
3108
|
+
# python and js will put it in curly brackets
|
3109
|
+
# the code below checks and replaces those brackets in empty requests
|
3110
|
+
if paramsKeysLength == 0:
|
3111
|
+
paramsString = '{}'
|
3112
|
+
arrayString = '[]'
|
3113
|
+
body = body.replace(arrayString, paramsString)
|
3114
|
+
headers = {
|
3115
|
+
'Content-Type': 'application/json',
|
3116
|
+
}
|
3117
|
+
return {'url': url, 'method': method, 'body': body, 'headers': headers}
|
3118
|
+
|
3119
|
+
def handle_errors(self, code: int, reason: str, url: str, method: str, headers: dict, body: str, response, requestHeaders, requestBody):
|
3120
|
+
errorCode = self.safe_string(response, 'code')
|
3121
|
+
if errorCode != '0':
|
3122
|
+
feedback = self.id + ' ' + body
|
3123
|
+
self.throw_exactly_matched_exception(self.exceptions['exact'], errorCode, feedback)
|
3124
|
+
raise ExchangeError(self.id + ' ' + body)
|
3125
|
+
return None
|