hyperliquid 0.4.66__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.
- hyperliquid/__init__.py +7 -0
- hyperliquid/ccxt/__init__.py +101 -0
- hyperliquid/ccxt/abstract/hyperliquid.py +6 -0
- hyperliquid/ccxt/async_support/__init__.py +80 -0
- hyperliquid/ccxt/async_support/base/__init__.py +1 -0
- hyperliquid/ccxt/async_support/base/exchange.py +2095 -0
- hyperliquid/ccxt/async_support/base/throttler.py +50 -0
- hyperliquid/ccxt/async_support/base/ws/__init__.py +38 -0
- hyperliquid/ccxt/async_support/base/ws/aiohttp_client.py +147 -0
- hyperliquid/ccxt/async_support/base/ws/cache.py +213 -0
- hyperliquid/ccxt/async_support/base/ws/client.py +214 -0
- hyperliquid/ccxt/async_support/base/ws/fast_client.py +97 -0
- hyperliquid/ccxt/async_support/base/ws/functions.py +59 -0
- hyperliquid/ccxt/async_support/base/ws/future.py +69 -0
- hyperliquid/ccxt/async_support/base/ws/order_book.py +78 -0
- hyperliquid/ccxt/async_support/base/ws/order_book_side.py +174 -0
- hyperliquid/ccxt/async_support/hyperliquid.py +3446 -0
- hyperliquid/ccxt/base/__init__.py +27 -0
- hyperliquid/ccxt/base/decimal_to_precision.py +174 -0
- hyperliquid/ccxt/base/errors.py +267 -0
- hyperliquid/ccxt/base/exchange.py +6767 -0
- hyperliquid/ccxt/base/precise.py +297 -0
- hyperliquid/ccxt/base/types.py +577 -0
- hyperliquid/ccxt/hyperliquid.py +3445 -0
- hyperliquid/ccxt/pro/__init__.py +21 -0
- hyperliquid/ccxt/pro/hyperliquid.py +997 -0
- hyperliquid/ccxt/static_dependencies/__init__.py +1 -0
- hyperliquid/ccxt/static_dependencies/ecdsa/__init__.py +14 -0
- hyperliquid/ccxt/static_dependencies/ecdsa/_version.py +520 -0
- hyperliquid/ccxt/static_dependencies/ecdsa/curves.py +56 -0
- hyperliquid/ccxt/static_dependencies/ecdsa/der.py +221 -0
- hyperliquid/ccxt/static_dependencies/ecdsa/ecdsa.py +310 -0
- hyperliquid/ccxt/static_dependencies/ecdsa/ellipticcurve.py +197 -0
- hyperliquid/ccxt/static_dependencies/ecdsa/keys.py +332 -0
- hyperliquid/ccxt/static_dependencies/ecdsa/numbertheory.py +531 -0
- hyperliquid/ccxt/static_dependencies/ecdsa/rfc6979.py +100 -0
- hyperliquid/ccxt/static_dependencies/ecdsa/util.py +266 -0
- hyperliquid/ccxt/static_dependencies/ethereum/__init__.py +7 -0
- hyperliquid/ccxt/static_dependencies/ethereum/abi/__init__.py +16 -0
- hyperliquid/ccxt/static_dependencies/ethereum/abi/abi.py +19 -0
- hyperliquid/ccxt/static_dependencies/ethereum/abi/base.py +152 -0
- hyperliquid/ccxt/static_dependencies/ethereum/abi/codec.py +217 -0
- hyperliquid/ccxt/static_dependencies/ethereum/abi/constants.py +3 -0
- hyperliquid/ccxt/static_dependencies/ethereum/abi/decoding.py +565 -0
- hyperliquid/ccxt/static_dependencies/ethereum/abi/encoding.py +720 -0
- hyperliquid/ccxt/static_dependencies/ethereum/abi/exceptions.py +139 -0
- hyperliquid/ccxt/static_dependencies/ethereum/abi/grammar.py +443 -0
- hyperliquid/ccxt/static_dependencies/ethereum/abi/packed.py +13 -0
- hyperliquid/ccxt/static_dependencies/ethereum/abi/py.typed +0 -0
- hyperliquid/ccxt/static_dependencies/ethereum/abi/registry.py +643 -0
- hyperliquid/ccxt/static_dependencies/ethereum/abi/tools/__init__.py +3 -0
- hyperliquid/ccxt/static_dependencies/ethereum/abi/tools/_strategies.py +230 -0
- hyperliquid/ccxt/static_dependencies/ethereum/abi/utils/__init__.py +0 -0
- hyperliquid/ccxt/static_dependencies/ethereum/abi/utils/numeric.py +83 -0
- hyperliquid/ccxt/static_dependencies/ethereum/abi/utils/padding.py +27 -0
- hyperliquid/ccxt/static_dependencies/ethereum/abi/utils/string.py +19 -0
- hyperliquid/ccxt/static_dependencies/ethereum/account/__init__.py +3 -0
- hyperliquid/ccxt/static_dependencies/ethereum/account/encode_typed_data/__init__.py +4 -0
- hyperliquid/ccxt/static_dependencies/ethereum/account/encode_typed_data/encoding_and_hashing.py +239 -0
- hyperliquid/ccxt/static_dependencies/ethereum/account/encode_typed_data/helpers.py +40 -0
- hyperliquid/ccxt/static_dependencies/ethereum/account/messages.py +263 -0
- hyperliquid/ccxt/static_dependencies/ethereum/account/py.typed +0 -0
- hyperliquid/ccxt/static_dependencies/ethereum/hexbytes/__init__.py +5 -0
- hyperliquid/ccxt/static_dependencies/ethereum/hexbytes/_utils.py +54 -0
- hyperliquid/ccxt/static_dependencies/ethereum/hexbytes/main.py +65 -0
- hyperliquid/ccxt/static_dependencies/ethereum/hexbytes/py.typed +0 -0
- hyperliquid/ccxt/static_dependencies/ethereum/typing/__init__.py +63 -0
- hyperliquid/ccxt/static_dependencies/ethereum/typing/abi.py +6 -0
- hyperliquid/ccxt/static_dependencies/ethereum/typing/bls.py +7 -0
- hyperliquid/ccxt/static_dependencies/ethereum/typing/discovery.py +5 -0
- hyperliquid/ccxt/static_dependencies/ethereum/typing/encoding.py +7 -0
- hyperliquid/ccxt/static_dependencies/ethereum/typing/enums.py +17 -0
- hyperliquid/ccxt/static_dependencies/ethereum/typing/ethpm.py +9 -0
- hyperliquid/ccxt/static_dependencies/ethereum/typing/evm.py +20 -0
- hyperliquid/ccxt/static_dependencies/ethereum/typing/networks.py +1122 -0
- hyperliquid/ccxt/static_dependencies/ethereum/typing/py.typed +0 -0
- hyperliquid/ccxt/static_dependencies/ethereum/utils/__init__.py +115 -0
- hyperliquid/ccxt/static_dependencies/ethereum/utils/abi.py +72 -0
- hyperliquid/ccxt/static_dependencies/ethereum/utils/address.py +171 -0
- hyperliquid/ccxt/static_dependencies/ethereum/utils/applicators.py +151 -0
- hyperliquid/ccxt/static_dependencies/ethereum/utils/conversions.py +190 -0
- hyperliquid/ccxt/static_dependencies/ethereum/utils/currency.py +107 -0
- hyperliquid/ccxt/static_dependencies/ethereum/utils/curried/__init__.py +269 -0
- hyperliquid/ccxt/static_dependencies/ethereum/utils/debug.py +20 -0
- hyperliquid/ccxt/static_dependencies/ethereum/utils/decorators.py +132 -0
- hyperliquid/ccxt/static_dependencies/ethereum/utils/encoding.py +6 -0
- hyperliquid/ccxt/static_dependencies/ethereum/utils/exceptions.py +4 -0
- hyperliquid/ccxt/static_dependencies/ethereum/utils/functional.py +75 -0
- hyperliquid/ccxt/static_dependencies/ethereum/utils/hexadecimal.py +74 -0
- hyperliquid/ccxt/static_dependencies/ethereum/utils/humanize.py +188 -0
- hyperliquid/ccxt/static_dependencies/ethereum/utils/logging.py +159 -0
- hyperliquid/ccxt/static_dependencies/ethereum/utils/module_loading.py +31 -0
- hyperliquid/ccxt/static_dependencies/ethereum/utils/numeric.py +43 -0
- hyperliquid/ccxt/static_dependencies/ethereum/utils/py.typed +0 -0
- hyperliquid/ccxt/static_dependencies/ethereum/utils/toolz.py +76 -0
- hyperliquid/ccxt/static_dependencies/ethereum/utils/types.py +54 -0
- hyperliquid/ccxt/static_dependencies/ethereum/utils/typing/__init__.py +18 -0
- hyperliquid/ccxt/static_dependencies/ethereum/utils/typing/misc.py +14 -0
- hyperliquid/ccxt/static_dependencies/ethereum/utils/units.py +31 -0
- hyperliquid/ccxt/static_dependencies/keccak/__init__.py +3 -0
- hyperliquid/ccxt/static_dependencies/keccak/keccak.py +197 -0
- hyperliquid/ccxt/static_dependencies/lark/__init__.py +38 -0
- hyperliquid/ccxt/static_dependencies/lark/__pyinstaller/__init__.py +6 -0
- hyperliquid/ccxt/static_dependencies/lark/__pyinstaller/hook-lark.py +14 -0
- hyperliquid/ccxt/static_dependencies/lark/ast_utils.py +59 -0
- hyperliquid/ccxt/static_dependencies/lark/common.py +86 -0
- hyperliquid/ccxt/static_dependencies/lark/exceptions.py +292 -0
- hyperliquid/ccxt/static_dependencies/lark/grammar.py +130 -0
- hyperliquid/ccxt/static_dependencies/lark/grammars/__init__.py +0 -0
- hyperliquid/ccxt/static_dependencies/lark/indenter.py +143 -0
- hyperliquid/ccxt/static_dependencies/lark/lark.py +658 -0
- hyperliquid/ccxt/static_dependencies/lark/lexer.py +678 -0
- hyperliquid/ccxt/static_dependencies/lark/load_grammar.py +1428 -0
- hyperliquid/ccxt/static_dependencies/lark/parse_tree_builder.py +391 -0
- hyperliquid/ccxt/static_dependencies/lark/parser_frontends.py +257 -0
- hyperliquid/ccxt/static_dependencies/lark/parsers/__init__.py +0 -0
- hyperliquid/ccxt/static_dependencies/lark/parsers/cyk.py +340 -0
- hyperliquid/ccxt/static_dependencies/lark/parsers/earley.py +314 -0
- hyperliquid/ccxt/static_dependencies/lark/parsers/earley_common.py +42 -0
- hyperliquid/ccxt/static_dependencies/lark/parsers/earley_forest.py +801 -0
- hyperliquid/ccxt/static_dependencies/lark/parsers/grammar_analysis.py +203 -0
- hyperliquid/ccxt/static_dependencies/lark/parsers/lalr_analysis.py +332 -0
- hyperliquid/ccxt/static_dependencies/lark/parsers/lalr_interactive_parser.py +158 -0
- hyperliquid/ccxt/static_dependencies/lark/parsers/lalr_parser.py +122 -0
- hyperliquid/ccxt/static_dependencies/lark/parsers/lalr_parser_state.py +110 -0
- hyperliquid/ccxt/static_dependencies/lark/parsers/xearley.py +165 -0
- hyperliquid/ccxt/static_dependencies/lark/py.typed +0 -0
- hyperliquid/ccxt/static_dependencies/lark/reconstruct.py +107 -0
- hyperliquid/ccxt/static_dependencies/lark/tools/__init__.py +70 -0
- hyperliquid/ccxt/static_dependencies/lark/tools/nearley.py +202 -0
- hyperliquid/ccxt/static_dependencies/lark/tools/serialize.py +32 -0
- hyperliquid/ccxt/static_dependencies/lark/tools/standalone.py +196 -0
- hyperliquid/ccxt/static_dependencies/lark/tree.py +267 -0
- hyperliquid/ccxt/static_dependencies/lark/tree_matcher.py +186 -0
- hyperliquid/ccxt/static_dependencies/lark/tree_templates.py +180 -0
- hyperliquid/ccxt/static_dependencies/lark/utils.py +343 -0
- hyperliquid/ccxt/static_dependencies/lark/visitors.py +596 -0
- hyperliquid/ccxt/static_dependencies/marshmallow/__init__.py +81 -0
- hyperliquid/ccxt/static_dependencies/marshmallow/base.py +65 -0
- hyperliquid/ccxt/static_dependencies/marshmallow/class_registry.py +94 -0
- hyperliquid/ccxt/static_dependencies/marshmallow/decorators.py +231 -0
- hyperliquid/ccxt/static_dependencies/marshmallow/error_store.py +60 -0
- hyperliquid/ccxt/static_dependencies/marshmallow/exceptions.py +71 -0
- hyperliquid/ccxt/static_dependencies/marshmallow/fields.py +2114 -0
- hyperliquid/ccxt/static_dependencies/marshmallow/orderedset.py +89 -0
- hyperliquid/ccxt/static_dependencies/marshmallow/py.typed +0 -0
- hyperliquid/ccxt/static_dependencies/marshmallow/schema.py +1228 -0
- hyperliquid/ccxt/static_dependencies/marshmallow/types.py +12 -0
- hyperliquid/ccxt/static_dependencies/marshmallow/utils.py +378 -0
- hyperliquid/ccxt/static_dependencies/marshmallow/validate.py +678 -0
- hyperliquid/ccxt/static_dependencies/marshmallow/warnings.py +2 -0
- hyperliquid/ccxt/static_dependencies/marshmallow_dataclass/__init__.py +1047 -0
- hyperliquid/ccxt/static_dependencies/marshmallow_dataclass/collection_field.py +51 -0
- hyperliquid/ccxt/static_dependencies/marshmallow_dataclass/lazy_class_attribute.py +45 -0
- hyperliquid/ccxt/static_dependencies/marshmallow_dataclass/mypy.py +71 -0
- hyperliquid/ccxt/static_dependencies/marshmallow_dataclass/py.typed +0 -0
- hyperliquid/ccxt/static_dependencies/marshmallow_dataclass/typing.py +14 -0
- hyperliquid/ccxt/static_dependencies/marshmallow_dataclass/union_field.py +82 -0
- hyperliquid/ccxt/static_dependencies/marshmallow_oneofschema/__init__.py +1 -0
- hyperliquid/ccxt/static_dependencies/marshmallow_oneofschema/one_of_schema.py +193 -0
- hyperliquid/ccxt/static_dependencies/marshmallow_oneofschema/py.typed +0 -0
- hyperliquid/ccxt/static_dependencies/msgpack/__init__.py +55 -0
- hyperliquid/ccxt/static_dependencies/msgpack/exceptions.py +48 -0
- hyperliquid/ccxt/static_dependencies/msgpack/ext.py +168 -0
- hyperliquid/ccxt/static_dependencies/msgpack/fallback.py +951 -0
- hyperliquid/ccxt/static_dependencies/parsimonious/__init__.py +10 -0
- hyperliquid/ccxt/static_dependencies/parsimonious/exceptions.py +105 -0
- hyperliquid/ccxt/static_dependencies/parsimonious/expressions.py +479 -0
- hyperliquid/ccxt/static_dependencies/parsimonious/grammar.py +487 -0
- hyperliquid/ccxt/static_dependencies/parsimonious/nodes.py +325 -0
- hyperliquid/ccxt/static_dependencies/parsimonious/utils.py +40 -0
- hyperliquid/ccxt/static_dependencies/starknet/__init__.py +0 -0
- hyperliquid/ccxt/static_dependencies/starknet/abi/v0/__init__.py +2 -0
- hyperliquid/ccxt/static_dependencies/starknet/abi/v0/model.py +44 -0
- hyperliquid/ccxt/static_dependencies/starknet/abi/v0/parser.py +216 -0
- hyperliquid/ccxt/static_dependencies/starknet/abi/v0/schemas.py +72 -0
- hyperliquid/ccxt/static_dependencies/starknet/abi/v0/shape.py +63 -0
- hyperliquid/ccxt/static_dependencies/starknet/abi/v1/__init__.py +2 -0
- hyperliquid/ccxt/static_dependencies/starknet/abi/v1/model.py +39 -0
- hyperliquid/ccxt/static_dependencies/starknet/abi/v1/parser.py +220 -0
- hyperliquid/ccxt/static_dependencies/starknet/abi/v1/parser_transformer.py +179 -0
- hyperliquid/ccxt/static_dependencies/starknet/abi/v1/schemas.py +66 -0
- hyperliquid/ccxt/static_dependencies/starknet/abi/v1/shape.py +47 -0
- hyperliquid/ccxt/static_dependencies/starknet/abi/v2/__init__.py +2 -0
- hyperliquid/ccxt/static_dependencies/starknet/abi/v2/model.py +89 -0
- hyperliquid/ccxt/static_dependencies/starknet/abi/v2/parser.py +293 -0
- hyperliquid/ccxt/static_dependencies/starknet/abi/v2/parser_transformer.py +192 -0
- hyperliquid/ccxt/static_dependencies/starknet/abi/v2/schemas.py +132 -0
- hyperliquid/ccxt/static_dependencies/starknet/abi/v2/shape.py +107 -0
- hyperliquid/ccxt/static_dependencies/starknet/cairo/__init__.py +0 -0
- hyperliquid/ccxt/static_dependencies/starknet/cairo/data_types.py +123 -0
- hyperliquid/ccxt/static_dependencies/starknet/cairo/deprecated_parse/__init__.py +0 -0
- hyperliquid/ccxt/static_dependencies/starknet/cairo/deprecated_parse/cairo_types.py +77 -0
- hyperliquid/ccxt/static_dependencies/starknet/cairo/deprecated_parse/parser.py +46 -0
- hyperliquid/ccxt/static_dependencies/starknet/cairo/deprecated_parse/parser_transformer.py +138 -0
- hyperliquid/ccxt/static_dependencies/starknet/cairo/felt.py +64 -0
- hyperliquid/ccxt/static_dependencies/starknet/cairo/type_parser.py +121 -0
- hyperliquid/ccxt/static_dependencies/starknet/cairo/v1/__init__.py +0 -0
- hyperliquid/ccxt/static_dependencies/starknet/cairo/v1/type_parser.py +59 -0
- hyperliquid/ccxt/static_dependencies/starknet/cairo/v2/__init__.py +0 -0
- hyperliquid/ccxt/static_dependencies/starknet/cairo/v2/type_parser.py +77 -0
- hyperliquid/ccxt/static_dependencies/starknet/ccxt_utils.py +7 -0
- hyperliquid/ccxt/static_dependencies/starknet/common.py +15 -0
- hyperliquid/ccxt/static_dependencies/starknet/constants.py +39 -0
- hyperliquid/ccxt/static_dependencies/starknet/hash/__init__.py +0 -0
- hyperliquid/ccxt/static_dependencies/starknet/hash/address.py +79 -0
- hyperliquid/ccxt/static_dependencies/starknet/hash/compiled_class_hash_objects.py +111 -0
- hyperliquid/ccxt/static_dependencies/starknet/hash/selector.py +16 -0
- hyperliquid/ccxt/static_dependencies/starknet/hash/storage.py +12 -0
- hyperliquid/ccxt/static_dependencies/starknet/hash/utils.py +78 -0
- hyperliquid/ccxt/static_dependencies/starknet/models/__init__.py +0 -0
- hyperliquid/ccxt/static_dependencies/starknet/models/typed_data.py +45 -0
- hyperliquid/ccxt/static_dependencies/starknet/serialization/__init__.py +24 -0
- hyperliquid/ccxt/static_dependencies/starknet/serialization/_calldata_reader.py +40 -0
- hyperliquid/ccxt/static_dependencies/starknet/serialization/_context.py +142 -0
- hyperliquid/ccxt/static_dependencies/starknet/serialization/data_serializers/__init__.py +10 -0
- hyperliquid/ccxt/static_dependencies/starknet/serialization/data_serializers/_common.py +82 -0
- hyperliquid/ccxt/static_dependencies/starknet/serialization/data_serializers/array_serializer.py +43 -0
- hyperliquid/ccxt/static_dependencies/starknet/serialization/data_serializers/bool_serializer.py +37 -0
- hyperliquid/ccxt/static_dependencies/starknet/serialization/data_serializers/byte_array_serializer.py +66 -0
- hyperliquid/ccxt/static_dependencies/starknet/serialization/data_serializers/cairo_data_serializer.py +71 -0
- hyperliquid/ccxt/static_dependencies/starknet/serialization/data_serializers/enum_serializer.py +71 -0
- hyperliquid/ccxt/static_dependencies/starknet/serialization/data_serializers/felt_serializer.py +50 -0
- hyperliquid/ccxt/static_dependencies/starknet/serialization/data_serializers/named_tuple_serializer.py +58 -0
- hyperliquid/ccxt/static_dependencies/starknet/serialization/data_serializers/option_serializer.py +43 -0
- hyperliquid/ccxt/static_dependencies/starknet/serialization/data_serializers/output_serializer.py +40 -0
- hyperliquid/ccxt/static_dependencies/starknet/serialization/data_serializers/payload_serializer.py +72 -0
- hyperliquid/ccxt/static_dependencies/starknet/serialization/data_serializers/struct_serializer.py +36 -0
- hyperliquid/ccxt/static_dependencies/starknet/serialization/data_serializers/tuple_serializer.py +36 -0
- hyperliquid/ccxt/static_dependencies/starknet/serialization/data_serializers/uint256_serializer.py +76 -0
- hyperliquid/ccxt/static_dependencies/starknet/serialization/data_serializers/uint_serializer.py +100 -0
- hyperliquid/ccxt/static_dependencies/starknet/serialization/data_serializers/unit_serializer.py +32 -0
- hyperliquid/ccxt/static_dependencies/starknet/serialization/errors.py +10 -0
- hyperliquid/ccxt/static_dependencies/starknet/serialization/factory.py +229 -0
- hyperliquid/ccxt/static_dependencies/starknet/serialization/function_serialization_adapter.py +110 -0
- hyperliquid/ccxt/static_dependencies/starknet/serialization/tuple_dataclass.py +59 -0
- hyperliquid/ccxt/static_dependencies/starknet/utils/__init__.py +0 -0
- hyperliquid/ccxt/static_dependencies/starknet/utils/constructor_args_translator.py +86 -0
- hyperliquid/ccxt/static_dependencies/starknet/utils/iterable.py +13 -0
- hyperliquid/ccxt/static_dependencies/starknet/utils/schema.py +13 -0
- hyperliquid/ccxt/static_dependencies/starknet/utils/typed_data.py +182 -0
- hyperliquid/ccxt/static_dependencies/starkware/__init__.py +0 -0
- hyperliquid/ccxt/static_dependencies/starkware/crypto/__init__.py +0 -0
- hyperliquid/ccxt/static_dependencies/starkware/crypto/fast_pedersen_hash.py +50 -0
- hyperliquid/ccxt/static_dependencies/starkware/crypto/math_utils.py +78 -0
- hyperliquid/ccxt/static_dependencies/starkware/crypto/signature.py +2344 -0
- hyperliquid/ccxt/static_dependencies/starkware/crypto/utils.py +63 -0
- hyperliquid/ccxt/static_dependencies/sympy/__init__.py +0 -0
- hyperliquid/ccxt/static_dependencies/sympy/core/__init__.py +0 -0
- hyperliquid/ccxt/static_dependencies/sympy/core/intfunc.py +35 -0
- hyperliquid/ccxt/static_dependencies/sympy/external/__init__.py +0 -0
- hyperliquid/ccxt/static_dependencies/sympy/external/gmpy.py +345 -0
- hyperliquid/ccxt/static_dependencies/sympy/external/importtools.py +187 -0
- hyperliquid/ccxt/static_dependencies/sympy/external/ntheory.py +637 -0
- hyperliquid/ccxt/static_dependencies/sympy/external/pythonmpq.py +341 -0
- hyperliquid/ccxt/static_dependencies/toolz/__init__.py +26 -0
- hyperliquid/ccxt/static_dependencies/toolz/_signatures.py +784 -0
- hyperliquid/ccxt/static_dependencies/toolz/_version.py +520 -0
- hyperliquid/ccxt/static_dependencies/toolz/compatibility.py +30 -0
- hyperliquid/ccxt/static_dependencies/toolz/curried/__init__.py +101 -0
- hyperliquid/ccxt/static_dependencies/toolz/curried/exceptions.py +22 -0
- hyperliquid/ccxt/static_dependencies/toolz/curried/operator.py +22 -0
- hyperliquid/ccxt/static_dependencies/toolz/dicttoolz.py +339 -0
- hyperliquid/ccxt/static_dependencies/toolz/functoolz.py +1049 -0
- hyperliquid/ccxt/static_dependencies/toolz/itertoolz.py +1057 -0
- hyperliquid/ccxt/static_dependencies/toolz/recipes.py +46 -0
- hyperliquid/ccxt/static_dependencies/toolz/utils.py +9 -0
- hyperliquid/ccxt/static_dependencies/typing_inspect/__init__.py +0 -0
- hyperliquid/ccxt/static_dependencies/typing_inspect/typing_inspect.py +851 -0
- hyperliquid-0.4.66.dist-info/LICENSE +21 -0
- hyperliquid-0.4.66.dist-info/METADATA +219 -0
- hyperliquid-0.4.66.dist-info/RECORD +274 -0
- hyperliquid-0.4.66.dist-info/WHEEL +5 -0
- hyperliquid-0.4.66.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,3446 @@
|
|
|
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.async_support.base.exchange import Exchange
|
|
7
|
+
from ccxt.abstract.hyperliquid import ImplicitAPI
|
|
8
|
+
import asyncio
|
|
9
|
+
import math
|
|
10
|
+
from ccxt.base.types import Any, Balances, Currencies, Currency, Int, LedgerEntry, MarginModification, Market, Num, Order, OrderBook, OrderRequest, CancellationRequest, OrderSide, OrderType, Str, Strings, Ticker, Tickers, FundingRate, FundingRates, Trade, TradingFeeInterface, Transaction, TransferEntry
|
|
11
|
+
from typing import List
|
|
12
|
+
from ccxt.base.errors import ExchangeError
|
|
13
|
+
from ccxt.base.errors import ArgumentsRequired
|
|
14
|
+
from ccxt.base.errors import BadRequest
|
|
15
|
+
from ccxt.base.errors import InsufficientFunds
|
|
16
|
+
from ccxt.base.errors import InvalidOrder
|
|
17
|
+
from ccxt.base.errors import OrderNotFound
|
|
18
|
+
from ccxt.base.errors import NotSupported
|
|
19
|
+
from ccxt.base.decimal_to_precision import ROUND
|
|
20
|
+
from ccxt.base.decimal_to_precision import DECIMAL_PLACES
|
|
21
|
+
from ccxt.base.decimal_to_precision import SIGNIFICANT_DIGITS
|
|
22
|
+
from ccxt.base.decimal_to_precision import TICK_SIZE
|
|
23
|
+
from ccxt.base.precise import Precise
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class hyperliquid(Exchange, ImplicitAPI):
|
|
27
|
+
|
|
28
|
+
def describe(self) -> Any:
|
|
29
|
+
return self.deep_extend(super(hyperliquid, self).describe(), {
|
|
30
|
+
'id': 'hyperliquid',
|
|
31
|
+
'name': 'Hyperliquid',
|
|
32
|
+
'countries': [],
|
|
33
|
+
'version': 'v1',
|
|
34
|
+
'rateLimit': 50, # 1200 requests per minute, 20 request per second
|
|
35
|
+
'certified': True,
|
|
36
|
+
'pro': True,
|
|
37
|
+
'dex': True,
|
|
38
|
+
'has': {
|
|
39
|
+
'CORS': None,
|
|
40
|
+
'spot': True,
|
|
41
|
+
'margin': False,
|
|
42
|
+
'swap': True,
|
|
43
|
+
'future': True,
|
|
44
|
+
'option': False,
|
|
45
|
+
'addMargin': True,
|
|
46
|
+
'borrowCrossMargin': False,
|
|
47
|
+
'borrowIsolatedMargin': False,
|
|
48
|
+
'cancelAllOrders': False,
|
|
49
|
+
'cancelAllOrdersAfter': True,
|
|
50
|
+
'cancelOrder': True,
|
|
51
|
+
'cancelOrders': True,
|
|
52
|
+
'cancelOrdersForSymbols': True,
|
|
53
|
+
'closeAllPositions': False,
|
|
54
|
+
'closePosition': False,
|
|
55
|
+
'createMarketBuyOrderWithCost': False,
|
|
56
|
+
'createMarketOrderWithCost': False,
|
|
57
|
+
'createMarketSellOrderWithCost': False,
|
|
58
|
+
'createOrder': True,
|
|
59
|
+
'createOrders': True,
|
|
60
|
+
'createReduceOnlyOrder': True,
|
|
61
|
+
'createStopOrder': True,
|
|
62
|
+
'createTriggerOrder': True,
|
|
63
|
+
'editOrder': True,
|
|
64
|
+
'editOrders': True,
|
|
65
|
+
'fetchAccounts': False,
|
|
66
|
+
'fetchBalance': True,
|
|
67
|
+
'fetchBorrowInterest': False,
|
|
68
|
+
'fetchBorrowRateHistories': False,
|
|
69
|
+
'fetchBorrowRateHistory': False,
|
|
70
|
+
'fetchCanceledAndClosedOrders': True,
|
|
71
|
+
'fetchCanceledOrders': True,
|
|
72
|
+
'fetchClosedOrders': True,
|
|
73
|
+
'fetchCrossBorrowRate': False,
|
|
74
|
+
'fetchCrossBorrowRates': False,
|
|
75
|
+
'fetchCurrencies': True,
|
|
76
|
+
'fetchDepositAddress': False,
|
|
77
|
+
'fetchDepositAddresses': False,
|
|
78
|
+
'fetchDeposits': True,
|
|
79
|
+
'fetchDepositWithdrawFee': 'emulated',
|
|
80
|
+
'fetchDepositWithdrawFees': False,
|
|
81
|
+
'fetchFundingHistory': True,
|
|
82
|
+
'fetchFundingRate': False,
|
|
83
|
+
'fetchFundingRateHistory': True,
|
|
84
|
+
'fetchFundingRates': True,
|
|
85
|
+
'fetchIndexOHLCV': False,
|
|
86
|
+
'fetchIsolatedBorrowRate': False,
|
|
87
|
+
'fetchIsolatedBorrowRates': False,
|
|
88
|
+
'fetchLedger': True,
|
|
89
|
+
'fetchLeverage': False,
|
|
90
|
+
'fetchLeverageTiers': False,
|
|
91
|
+
'fetchLiquidations': False,
|
|
92
|
+
'fetchMarginMode': None,
|
|
93
|
+
'fetchMarketLeverageTiers': False,
|
|
94
|
+
'fetchMarkets': True,
|
|
95
|
+
'fetchMarkOHLCV': False,
|
|
96
|
+
'fetchMyLiquidations': False,
|
|
97
|
+
'fetchMyTrades': True,
|
|
98
|
+
'fetchOHLCV': True,
|
|
99
|
+
'fetchOpenInterest': True,
|
|
100
|
+
'fetchOpenInterestHistory': False,
|
|
101
|
+
'fetchOpenInterests': True,
|
|
102
|
+
'fetchOpenOrders': True,
|
|
103
|
+
'fetchOrder': True,
|
|
104
|
+
'fetchOrderBook': True,
|
|
105
|
+
'fetchOrders': True,
|
|
106
|
+
'fetchOrderTrades': False,
|
|
107
|
+
'fetchPosition': True,
|
|
108
|
+
'fetchPositionMode': False,
|
|
109
|
+
'fetchPositions': True,
|
|
110
|
+
'fetchPositionsRisk': False,
|
|
111
|
+
'fetchPremiumIndexOHLCV': False,
|
|
112
|
+
'fetchTicker': 'emulated',
|
|
113
|
+
'fetchTickers': True,
|
|
114
|
+
'fetchTime': False,
|
|
115
|
+
'fetchTrades': True,
|
|
116
|
+
'fetchTradingFee': True,
|
|
117
|
+
'fetchTradingFees': False,
|
|
118
|
+
'fetchTransfer': False,
|
|
119
|
+
'fetchTransfers': False,
|
|
120
|
+
'fetchWithdrawal': False,
|
|
121
|
+
'fetchWithdrawals': True,
|
|
122
|
+
'reduceMargin': True,
|
|
123
|
+
'repayCrossMargin': False,
|
|
124
|
+
'repayIsolatedMargin': False,
|
|
125
|
+
'sandbox': True,
|
|
126
|
+
'setLeverage': True,
|
|
127
|
+
'setMarginMode': True,
|
|
128
|
+
'setPositionMode': False,
|
|
129
|
+
'transfer': True,
|
|
130
|
+
'withdraw': True,
|
|
131
|
+
},
|
|
132
|
+
'timeframes': {
|
|
133
|
+
'1m': '1m',
|
|
134
|
+
'3m': '3m',
|
|
135
|
+
'5m': '5m',
|
|
136
|
+
'15m': '15m',
|
|
137
|
+
'30m': '30m',
|
|
138
|
+
'1h': '1h',
|
|
139
|
+
'2h': '2h',
|
|
140
|
+
'4h': '4h',
|
|
141
|
+
'8h': '8h',
|
|
142
|
+
'12h': '12h',
|
|
143
|
+
'1d': '1d',
|
|
144
|
+
'3d': '3d',
|
|
145
|
+
'1w': '1w',
|
|
146
|
+
'1M': '1M',
|
|
147
|
+
},
|
|
148
|
+
'hostname': 'hyperliquid.xyz',
|
|
149
|
+
'urls': {
|
|
150
|
+
'logo': 'https://github.com/ccxt/ccxt/assets/43336371/b371bc6c-4a8c-489f-87f4-20a913dd8d4b',
|
|
151
|
+
'api': {
|
|
152
|
+
'public': 'https://api.{hostname}',
|
|
153
|
+
'private': 'https://api.{hostname}',
|
|
154
|
+
},
|
|
155
|
+
'test': {
|
|
156
|
+
'public': 'https://api.hyperliquid-testnet.xyz',
|
|
157
|
+
'private': 'https://api.hyperliquid-testnet.xyz',
|
|
158
|
+
},
|
|
159
|
+
'www': 'https://hyperliquid.xyz',
|
|
160
|
+
'doc': 'https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api',
|
|
161
|
+
'fees': 'https://hyperliquid.gitbook.io/hyperliquid-docs/trading/fees',
|
|
162
|
+
'referral': 'https://app.hyperliquid.xyz/',
|
|
163
|
+
},
|
|
164
|
+
'api': {
|
|
165
|
+
'public': {
|
|
166
|
+
'post': {
|
|
167
|
+
'info': {
|
|
168
|
+
'cost': 20,
|
|
169
|
+
'byType': {
|
|
170
|
+
'l2Book': 2,
|
|
171
|
+
'allMids': 2,
|
|
172
|
+
'clearinghouseState': 2,
|
|
173
|
+
'orderStatus': 2,
|
|
174
|
+
'spotClearinghouseState': 2,
|
|
175
|
+
'exchangeStatus': 2,
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
},
|
|
179
|
+
},
|
|
180
|
+
'private': {
|
|
181
|
+
'post': {
|
|
182
|
+
'exchange': 1,
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
},
|
|
186
|
+
'fees': {
|
|
187
|
+
'swap': {
|
|
188
|
+
'taker': self.parse_number('0.00035'),
|
|
189
|
+
'maker': self.parse_number('0.0001'),
|
|
190
|
+
},
|
|
191
|
+
'spot': {
|
|
192
|
+
'taker': self.parse_number('0.00035'),
|
|
193
|
+
'maker': self.parse_number('0.0001'),
|
|
194
|
+
},
|
|
195
|
+
},
|
|
196
|
+
'requiredCredentials': {
|
|
197
|
+
'apiKey': False,
|
|
198
|
+
'secret': False,
|
|
199
|
+
'walletAddress': True,
|
|
200
|
+
'privateKey': True,
|
|
201
|
+
},
|
|
202
|
+
'exceptions': {
|
|
203
|
+
'exact': {
|
|
204
|
+
},
|
|
205
|
+
'broad': {
|
|
206
|
+
'Price must be divisible by tick size.': InvalidOrder,
|
|
207
|
+
'Order must have minimum value of $10': InvalidOrder,
|
|
208
|
+
'Insufficient margin to place order.': InsufficientFunds,
|
|
209
|
+
'Reduce only order would increase position.': InvalidOrder,
|
|
210
|
+
'Post only order would have immediately matched,': InvalidOrder,
|
|
211
|
+
'Order could not immediately match against any resting orders.': InvalidOrder,
|
|
212
|
+
'Invalid TP/SL price.': InvalidOrder,
|
|
213
|
+
'No liquidity available for market order.': InvalidOrder,
|
|
214
|
+
'Order was never placed, already canceled, or filled.': OrderNotFound,
|
|
215
|
+
'User or API Wallet ': InvalidOrder,
|
|
216
|
+
'Order has invalid size': InvalidOrder,
|
|
217
|
+
'Order price cannot be more than 80% away from the reference price': InvalidOrder,
|
|
218
|
+
'Order has zero size.': InvalidOrder,
|
|
219
|
+
'Insufficient spot balance asset': InsufficientFunds,
|
|
220
|
+
'Insufficient balance for withdrawal': InsufficientFunds,
|
|
221
|
+
'Insufficient balance for token transfer': InsufficientFunds,
|
|
222
|
+
},
|
|
223
|
+
},
|
|
224
|
+
'precisionMode': TICK_SIZE,
|
|
225
|
+
'commonCurrencies': {
|
|
226
|
+
},
|
|
227
|
+
'options': {
|
|
228
|
+
'defaultType': 'swap',
|
|
229
|
+
'sandboxMode': False,
|
|
230
|
+
'defaultSlippage': 0.05,
|
|
231
|
+
'zeroAddress': '0x0000000000000000000000000000000000000000',
|
|
232
|
+
},
|
|
233
|
+
'features': {
|
|
234
|
+
'default': {
|
|
235
|
+
'sandbox': True,
|
|
236
|
+
'createOrder': {
|
|
237
|
+
'marginMode': False,
|
|
238
|
+
'triggerPrice': False,
|
|
239
|
+
'triggerPriceType': None,
|
|
240
|
+
'triggerDirection': False,
|
|
241
|
+
'stopLossPrice': False,
|
|
242
|
+
'takeProfitPrice': False,
|
|
243
|
+
'attachedStopLossTakeProfit': None,
|
|
244
|
+
'timeInForce': {
|
|
245
|
+
'IOC': True,
|
|
246
|
+
'FOK': False,
|
|
247
|
+
'PO': True,
|
|
248
|
+
'GTD': False,
|
|
249
|
+
},
|
|
250
|
+
'hedged': False,
|
|
251
|
+
'trailing': False,
|
|
252
|
+
'leverage': False,
|
|
253
|
+
'marketBuyByCost': False,
|
|
254
|
+
'marketBuyRequiresPrice': False,
|
|
255
|
+
'selfTradePrevention': False,
|
|
256
|
+
'iceberg': False,
|
|
257
|
+
},
|
|
258
|
+
'createOrders': {
|
|
259
|
+
'max': 1000,
|
|
260
|
+
},
|
|
261
|
+
'fetchMyTrades': {
|
|
262
|
+
'marginMode': False,
|
|
263
|
+
'limit': 2000,
|
|
264
|
+
'daysBack': None,
|
|
265
|
+
'untilDays': None,
|
|
266
|
+
'symbolRequired': True,
|
|
267
|
+
},
|
|
268
|
+
'fetchOrder': {
|
|
269
|
+
'marginMode': False,
|
|
270
|
+
'trigger': False,
|
|
271
|
+
'trailing': False,
|
|
272
|
+
'symbolRequired': True,
|
|
273
|
+
},
|
|
274
|
+
'fetchOpenOrders': {
|
|
275
|
+
'marginMode': False,
|
|
276
|
+
'limit': 2000,
|
|
277
|
+
'trigger': False,
|
|
278
|
+
'trailing': False,
|
|
279
|
+
'symbolRequired': True,
|
|
280
|
+
},
|
|
281
|
+
'fetchOrders': {
|
|
282
|
+
'marginMode': False,
|
|
283
|
+
'limit': 2000,
|
|
284
|
+
'daysBack': None,
|
|
285
|
+
'untilDays': None,
|
|
286
|
+
'trigger': False,
|
|
287
|
+
'trailing': False,
|
|
288
|
+
'symbolRequired': True,
|
|
289
|
+
},
|
|
290
|
+
'fetchClosedOrders': {
|
|
291
|
+
'marginMode': False,
|
|
292
|
+
'limit': 2000,
|
|
293
|
+
'daysBack': None,
|
|
294
|
+
'daysBackCanceled': None,
|
|
295
|
+
'untilDays': None,
|
|
296
|
+
'trigger': False,
|
|
297
|
+
'trailing': False,
|
|
298
|
+
'symbolRequired': True,
|
|
299
|
+
},
|
|
300
|
+
'fetchOHLCV': {
|
|
301
|
+
'limit': 5000,
|
|
302
|
+
},
|
|
303
|
+
},
|
|
304
|
+
'spot': {
|
|
305
|
+
'extends': 'default',
|
|
306
|
+
},
|
|
307
|
+
'forPerps': {
|
|
308
|
+
'extends': 'default',
|
|
309
|
+
'createOrder': {
|
|
310
|
+
'stopLossPrice': True,
|
|
311
|
+
'takeProfitPrice': True,
|
|
312
|
+
'attachedStopLossTakeProfit': None, # todo, in two orders
|
|
313
|
+
},
|
|
314
|
+
},
|
|
315
|
+
'swap': {
|
|
316
|
+
'linear': {
|
|
317
|
+
'extends': 'forPerps',
|
|
318
|
+
},
|
|
319
|
+
'inverse': {
|
|
320
|
+
'extends': 'forPerps',
|
|
321
|
+
},
|
|
322
|
+
},
|
|
323
|
+
'future': {
|
|
324
|
+
'linear': {
|
|
325
|
+
'extends': 'forPerps',
|
|
326
|
+
},
|
|
327
|
+
'inverse': {
|
|
328
|
+
'extends': 'forPerps',
|
|
329
|
+
},
|
|
330
|
+
},
|
|
331
|
+
},
|
|
332
|
+
})
|
|
333
|
+
|
|
334
|
+
def set_sandbox_mode(self, enabled):
|
|
335
|
+
super(hyperliquid, self).set_sandbox_mode(enabled)
|
|
336
|
+
self.options['sandboxMode'] = enabled
|
|
337
|
+
|
|
338
|
+
async def fetch_currencies(self, params={}) -> Currencies:
|
|
339
|
+
"""
|
|
340
|
+
fetches all available currencies on an exchange
|
|
341
|
+
|
|
342
|
+
https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint/perpetuals#retrieve-perpetuals-metadata
|
|
343
|
+
|
|
344
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
|
345
|
+
:returns dict: an associative dictionary of currencies
|
|
346
|
+
"""
|
|
347
|
+
request: dict = {
|
|
348
|
+
'type': 'meta',
|
|
349
|
+
}
|
|
350
|
+
response = await self.publicPostInfo(self.extend(request, params))
|
|
351
|
+
#
|
|
352
|
+
# [
|
|
353
|
+
# {
|
|
354
|
+
# "universe": [
|
|
355
|
+
# {
|
|
356
|
+
# "maxLeverage": 50,
|
|
357
|
+
# "name": "SOL",
|
|
358
|
+
# "onlyIsolated": False,
|
|
359
|
+
# "szDecimals": 2
|
|
360
|
+
# }
|
|
361
|
+
# ]
|
|
362
|
+
# }
|
|
363
|
+
# ]
|
|
364
|
+
#
|
|
365
|
+
meta = self.safe_list(response, 'universe', [])
|
|
366
|
+
result: dict = {}
|
|
367
|
+
for i in range(0, len(meta)):
|
|
368
|
+
data = self.safe_dict(meta, i, {})
|
|
369
|
+
id = i
|
|
370
|
+
name = self.safe_string(data, 'name')
|
|
371
|
+
code = self.safe_currency_code(name)
|
|
372
|
+
result[code] = {
|
|
373
|
+
'id': id,
|
|
374
|
+
'name': name,
|
|
375
|
+
'code': code,
|
|
376
|
+
'precision': None,
|
|
377
|
+
'info': data,
|
|
378
|
+
'active': None,
|
|
379
|
+
'deposit': None,
|
|
380
|
+
'withdraw': None,
|
|
381
|
+
'networks': None,
|
|
382
|
+
'fee': None,
|
|
383
|
+
'limits': {
|
|
384
|
+
'amount': {
|
|
385
|
+
'min': None,
|
|
386
|
+
'max': None,
|
|
387
|
+
},
|
|
388
|
+
'withdraw': {
|
|
389
|
+
'min': None,
|
|
390
|
+
'max': None,
|
|
391
|
+
},
|
|
392
|
+
},
|
|
393
|
+
}
|
|
394
|
+
return result
|
|
395
|
+
|
|
396
|
+
async def fetch_markets(self, params={}) -> List[Market]:
|
|
397
|
+
"""
|
|
398
|
+
retrieves data on all markets for hyperliquid
|
|
399
|
+
|
|
400
|
+
https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint/perpetuals#retrieve-perpetuals-asset-contexts-includes-mark-price-current-funding-open-interest-etc
|
|
401
|
+
https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint/spot#retrieve-spot-asset-contexts
|
|
402
|
+
|
|
403
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
|
404
|
+
:returns dict[]: an array of objects representing market data
|
|
405
|
+
"""
|
|
406
|
+
rawPromises = [
|
|
407
|
+
self.fetch_swap_markets(params),
|
|
408
|
+
self.fetch_spot_markets(params),
|
|
409
|
+
]
|
|
410
|
+
promises = await asyncio.gather(*rawPromises)
|
|
411
|
+
swapMarkets = promises[0]
|
|
412
|
+
spotMarkets = promises[1]
|
|
413
|
+
return self.array_concat(swapMarkets, spotMarkets)
|
|
414
|
+
|
|
415
|
+
async def fetch_swap_markets(self, params={}) -> List[Market]:
|
|
416
|
+
"""
|
|
417
|
+
retrieves data on all swap markets for hyperliquid
|
|
418
|
+
|
|
419
|
+
https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint/perpetuals#retrieve-perpetuals-asset-contexts-includes-mark-price-current-funding-open-interest-etc
|
|
420
|
+
|
|
421
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
|
422
|
+
:returns dict[]: an array of objects representing market data
|
|
423
|
+
"""
|
|
424
|
+
request: dict = {
|
|
425
|
+
'type': 'metaAndAssetCtxs',
|
|
426
|
+
}
|
|
427
|
+
response = await self.publicPostInfo(self.extend(request, params))
|
|
428
|
+
#
|
|
429
|
+
# [
|
|
430
|
+
# {
|
|
431
|
+
# "universe": [
|
|
432
|
+
# {
|
|
433
|
+
# "maxLeverage": 50,
|
|
434
|
+
# "name": "SOL",
|
|
435
|
+
# "onlyIsolated": False,
|
|
436
|
+
# "szDecimals": 2
|
|
437
|
+
# }
|
|
438
|
+
# ]
|
|
439
|
+
# },
|
|
440
|
+
# [
|
|
441
|
+
# {
|
|
442
|
+
# "dayNtlVlm": "9450588.2273",
|
|
443
|
+
# "funding": "0.0000198",
|
|
444
|
+
# "impactPxs": [
|
|
445
|
+
# "108.04",
|
|
446
|
+
# "108.06"
|
|
447
|
+
# ],
|
|
448
|
+
# "markPx": "108.04",
|
|
449
|
+
# "midPx": "108.05",
|
|
450
|
+
# "openInterest": "10764.48",
|
|
451
|
+
# "oraclePx": "107.99",
|
|
452
|
+
# "premium": "0.00055561",
|
|
453
|
+
# "prevDayPx": "111.81"
|
|
454
|
+
# }
|
|
455
|
+
# ]
|
|
456
|
+
# ]
|
|
457
|
+
#
|
|
458
|
+
#
|
|
459
|
+
meta = self.safe_dict(response, 0, {})
|
|
460
|
+
universe = self.safe_list(meta, 'universe', [])
|
|
461
|
+
assetCtxs = self.safe_list(response, 1, [])
|
|
462
|
+
result = []
|
|
463
|
+
for i in range(0, len(universe)):
|
|
464
|
+
data = self.extend(
|
|
465
|
+
self.safe_dict(universe, i, {}),
|
|
466
|
+
self.safe_dict(assetCtxs, i, {})
|
|
467
|
+
)
|
|
468
|
+
data['baseId'] = i
|
|
469
|
+
result.append(data)
|
|
470
|
+
return self.parse_markets(result)
|
|
471
|
+
|
|
472
|
+
def calculate_price_precision(self, price: float, amountPrecision: float, maxDecimals: float):
|
|
473
|
+
"""
|
|
474
|
+
Helper function to calculate the Hyperliquid DECIMAL_PLACES price precision
|
|
475
|
+
:param float price: the price to use in the calculation
|
|
476
|
+
:param int amountPrecision: the amountPrecision to use in the calculation
|
|
477
|
+
:param int maxDecimals: the maxDecimals to use in the calculation
|
|
478
|
+
:returns int: The calculated price precision
|
|
479
|
+
"""
|
|
480
|
+
pricePrecision = 0
|
|
481
|
+
priceStr = self.number_to_string(price)
|
|
482
|
+
if priceStr is None:
|
|
483
|
+
return 0
|
|
484
|
+
priceSplitted = priceStr.split('.')
|
|
485
|
+
if Precise.string_eq(priceStr, '0'):
|
|
486
|
+
# Significant digits is always hasattr(self, 5) case
|
|
487
|
+
significantDigits = 5
|
|
488
|
+
# Integer digits is always hasattr(self, 0) case(0 doesn't count)
|
|
489
|
+
integerDigits = 0
|
|
490
|
+
# Calculate the price precision
|
|
491
|
+
pricePrecision = min(maxDecimals - amountPrecision, significantDigits - integerDigits)
|
|
492
|
+
elif Precise.string_gt(priceStr, '0') and Precise.string_lt(priceStr, '1'):
|
|
493
|
+
# Significant digits, always hasattr(self, 5) case
|
|
494
|
+
significantDigits = 5
|
|
495
|
+
# Get the part after the decimal separator
|
|
496
|
+
decimalPart = self.safe_string(priceSplitted, 1, '')
|
|
497
|
+
# Count the number of leading zeros in the decimal part
|
|
498
|
+
leadingZeros = 0
|
|
499
|
+
while((leadingZeros <= len(decimalPart)) and (decimalPart[leadingZeros] == '0')):
|
|
500
|
+
leadingZeros = leadingZeros + 1
|
|
501
|
+
# Calculate price precision based on leading zeros and significant digits
|
|
502
|
+
pricePrecision = leadingZeros + significantDigits
|
|
503
|
+
# Calculate the price precision based on maxDecimals - szDecimals and the calculated price precision from the previous step
|
|
504
|
+
pricePrecision = min(maxDecimals - amountPrecision, pricePrecision)
|
|
505
|
+
else:
|
|
506
|
+
# Count the numbers before the decimal separator
|
|
507
|
+
integerPart = self.safe_string(priceSplitted, 0, '')
|
|
508
|
+
# Get significant digits, take the max() of 5 and the integer digits count
|
|
509
|
+
significantDigits = max(5, len(integerPart))
|
|
510
|
+
# Calculate price precision based on maxDecimals - szDecimals and significantDigits - len(integerPart)
|
|
511
|
+
pricePrecision = min(maxDecimals - amountPrecision, significantDigits - len(integerPart))
|
|
512
|
+
return self.parse_to_int(pricePrecision)
|
|
513
|
+
|
|
514
|
+
async def fetch_spot_markets(self, params={}) -> List[Market]:
|
|
515
|
+
"""
|
|
516
|
+
retrieves data on all spot markets for hyperliquid
|
|
517
|
+
|
|
518
|
+
https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint/spot#retrieve-spot-asset-contexts
|
|
519
|
+
|
|
520
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
|
521
|
+
:returns dict[]: an array of objects representing market data
|
|
522
|
+
"""
|
|
523
|
+
request: dict = {
|
|
524
|
+
'type': 'spotMetaAndAssetCtxs',
|
|
525
|
+
}
|
|
526
|
+
response = await self.publicPostInfo(self.extend(request, params))
|
|
527
|
+
#
|
|
528
|
+
# [
|
|
529
|
+
# {
|
|
530
|
+
# "tokens": [
|
|
531
|
+
# {
|
|
532
|
+
# "name": "USDC",
|
|
533
|
+
# "szDecimals": 8,
|
|
534
|
+
# "weiDecimals" 8,
|
|
535
|
+
# "index": 0,
|
|
536
|
+
# "tokenId": "0x6d1e7cde53ba9467b783cb7c530ce054",
|
|
537
|
+
# "isCanonical": True,
|
|
538
|
+
# "evmContract":null,
|
|
539
|
+
# "fullName":null
|
|
540
|
+
# },
|
|
541
|
+
# {
|
|
542
|
+
# "name": "PURR",
|
|
543
|
+
# "szDecimals": 0,
|
|
544
|
+
# "weiDecimals": 5,
|
|
545
|
+
# "index": 1,
|
|
546
|
+
# "tokenId": "0xc1fb593aeffbeb02f85e0308e9956a90",
|
|
547
|
+
# "isCanonical": True,
|
|
548
|
+
# "evmContract":null,
|
|
549
|
+
# "fullName":null
|
|
550
|
+
# }
|
|
551
|
+
# ],
|
|
552
|
+
# "universe": [
|
|
553
|
+
# {
|
|
554
|
+
# "name": "PURR/USDC",
|
|
555
|
+
# "tokens": [1, 0],
|
|
556
|
+
# "index": 0,
|
|
557
|
+
# "isCanonical": True
|
|
558
|
+
# }
|
|
559
|
+
# ]
|
|
560
|
+
# },
|
|
561
|
+
# [
|
|
562
|
+
# {
|
|
563
|
+
# "dayNtlVlm":"8906.0",
|
|
564
|
+
# "markPx":"0.14",
|
|
565
|
+
# "midPx":"0.209265",
|
|
566
|
+
# "prevDayPx":"0.20432"
|
|
567
|
+
# }
|
|
568
|
+
# ]
|
|
569
|
+
# ]
|
|
570
|
+
#
|
|
571
|
+
first = self.safe_dict(response, 0, {})
|
|
572
|
+
second = self.safe_list(response, 1, [])
|
|
573
|
+
meta = self.safe_list(first, 'universe', [])
|
|
574
|
+
tokens = self.safe_list(first, 'tokens', [])
|
|
575
|
+
markets = []
|
|
576
|
+
for i in range(0, len(meta)):
|
|
577
|
+
market = self.safe_dict(meta, i, {})
|
|
578
|
+
index = self.safe_integer(market, 'index')
|
|
579
|
+
extraData = self.safe_dict(second, index, {})
|
|
580
|
+
marketName = self.safe_string(market, 'name')
|
|
581
|
+
# if marketName.find('/') < 0:
|
|
582
|
+
# # there are some weird spot markets in testnet, eg @2
|
|
583
|
+
# continue
|
|
584
|
+
# }
|
|
585
|
+
# marketParts = marketName.split('/')
|
|
586
|
+
# baseName = self.safe_string(marketParts, 0)
|
|
587
|
+
# quoteId = self.safe_string(marketParts, 1)
|
|
588
|
+
fees = self.safe_dict(self.fees, 'spot', {})
|
|
589
|
+
taker = self.safe_number(fees, 'taker')
|
|
590
|
+
maker = self.safe_number(fees, 'maker')
|
|
591
|
+
tokensPos = self.safe_list(market, 'tokens', [])
|
|
592
|
+
baseTokenPos = self.safe_integer(tokensPos, 0)
|
|
593
|
+
quoteTokenPos = self.safe_integer(tokensPos, 1)
|
|
594
|
+
baseTokenInfo = self.safe_dict(tokens, baseTokenPos, {})
|
|
595
|
+
quoteTokenInfo = self.safe_dict(tokens, quoteTokenPos, {})
|
|
596
|
+
baseName = self.safe_string(baseTokenInfo, 'name')
|
|
597
|
+
quoteId = self.safe_string(quoteTokenInfo, 'name')
|
|
598
|
+
base = self.safe_currency_code(baseName)
|
|
599
|
+
quote = self.safe_currency_code(quoteId)
|
|
600
|
+
symbol = base + '/' + quote
|
|
601
|
+
innerBaseTokenInfo = self.safe_dict(baseTokenInfo, 'spec', baseTokenInfo)
|
|
602
|
+
# innerQuoteTokenInfo = self.safe_dict(quoteTokenInfo, 'spec', quoteTokenInfo)
|
|
603
|
+
amountPrecisionStr = self.safe_string(innerBaseTokenInfo, 'szDecimals')
|
|
604
|
+
amountPrecision = int(amountPrecisionStr)
|
|
605
|
+
price = self.safe_number(extraData, 'midPx')
|
|
606
|
+
pricePrecision = 0
|
|
607
|
+
if price is not None:
|
|
608
|
+
pricePrecision = self.calculate_price_precision(price, amountPrecision, 8)
|
|
609
|
+
pricePrecisionStr = self.number_to_string(pricePrecision)
|
|
610
|
+
# quotePrecision = self.parse_number(self.parse_precision(self.safe_string(innerQuoteTokenInfo, 'szDecimals')))
|
|
611
|
+
baseId = self.number_to_string(index + 10000)
|
|
612
|
+
markets.append(self.safe_market_structure({
|
|
613
|
+
'id': marketName,
|
|
614
|
+
'symbol': symbol,
|
|
615
|
+
'base': base,
|
|
616
|
+
'quote': quote,
|
|
617
|
+
'settle': None,
|
|
618
|
+
'baseId': baseId,
|
|
619
|
+
'quoteId': quoteId,
|
|
620
|
+
'settleId': None,
|
|
621
|
+
'type': 'spot',
|
|
622
|
+
'spot': True,
|
|
623
|
+
'subType': None,
|
|
624
|
+
'margin': None,
|
|
625
|
+
'swap': False,
|
|
626
|
+
'future': False,
|
|
627
|
+
'option': False,
|
|
628
|
+
'active': True,
|
|
629
|
+
'contract': False,
|
|
630
|
+
'linear': None,
|
|
631
|
+
'inverse': None,
|
|
632
|
+
'taker': taker,
|
|
633
|
+
'maker': maker,
|
|
634
|
+
'contractSize': None,
|
|
635
|
+
'expiry': None,
|
|
636
|
+
'expiryDatetime': None,
|
|
637
|
+
'strike': None,
|
|
638
|
+
'optionType': None,
|
|
639
|
+
'precision': {
|
|
640
|
+
'amount': self.parse_number(self.parse_precision(amountPrecisionStr)),
|
|
641
|
+
'price': self.parse_number(self.parse_precision(pricePrecisionStr)),
|
|
642
|
+
},
|
|
643
|
+
'limits': {
|
|
644
|
+
'leverage': {
|
|
645
|
+
'min': None,
|
|
646
|
+
'max': None,
|
|
647
|
+
},
|
|
648
|
+
'amount': {
|
|
649
|
+
'min': None,
|
|
650
|
+
'max': None,
|
|
651
|
+
},
|
|
652
|
+
'price': {
|
|
653
|
+
'min': None,
|
|
654
|
+
'max': None,
|
|
655
|
+
},
|
|
656
|
+
'cost': {
|
|
657
|
+
'min': self.parse_number('10'),
|
|
658
|
+
'max': None,
|
|
659
|
+
},
|
|
660
|
+
},
|
|
661
|
+
'created': None,
|
|
662
|
+
'info': self.extend(extraData, market),
|
|
663
|
+
}))
|
|
664
|
+
return markets
|
|
665
|
+
|
|
666
|
+
def parse_market(self, market: dict) -> Market:
|
|
667
|
+
#
|
|
668
|
+
# {
|
|
669
|
+
# "maxLeverage": "50",
|
|
670
|
+
# "name": "ETH",
|
|
671
|
+
# "onlyIsolated": False,
|
|
672
|
+
# "szDecimals": "4",
|
|
673
|
+
# "dayNtlVlm": "1709813.11535",
|
|
674
|
+
# "funding": "0.00004807",
|
|
675
|
+
# "impactPxs": [
|
|
676
|
+
# "2369.3",
|
|
677
|
+
# "2369.6"
|
|
678
|
+
# ],
|
|
679
|
+
# "markPx": "2369.6",
|
|
680
|
+
# "midPx": "2369.45",
|
|
681
|
+
# "openInterest": "1815.4712",
|
|
682
|
+
# "oraclePx": "2367.3",
|
|
683
|
+
# "premium": "0.00090821",
|
|
684
|
+
# "prevDayPx": "2381.5"
|
|
685
|
+
# }
|
|
686
|
+
#
|
|
687
|
+
quoteId = 'USDC'
|
|
688
|
+
base = self.safe_string(market, 'name')
|
|
689
|
+
quote = self.safe_currency_code(quoteId)
|
|
690
|
+
baseId = self.safe_string(market, 'baseId')
|
|
691
|
+
settleId = 'USDC'
|
|
692
|
+
settle = self.safe_currency_code(settleId)
|
|
693
|
+
symbol = base + '/' + quote
|
|
694
|
+
contract = True
|
|
695
|
+
swap = True
|
|
696
|
+
if contract:
|
|
697
|
+
if swap:
|
|
698
|
+
symbol = symbol + ':' + settle
|
|
699
|
+
fees = self.safe_dict(self.fees, 'swap', {})
|
|
700
|
+
taker = self.safe_number(fees, 'taker')
|
|
701
|
+
maker = self.safe_number(fees, 'maker')
|
|
702
|
+
amountPrecisionStr = self.safe_string(market, 'szDecimals')
|
|
703
|
+
amountPrecision = int(amountPrecisionStr)
|
|
704
|
+
price = self.safe_number(market, 'markPx', 0)
|
|
705
|
+
pricePrecision = 0
|
|
706
|
+
if price is not None:
|
|
707
|
+
pricePrecision = self.calculate_price_precision(price, amountPrecision, 6)
|
|
708
|
+
pricePrecisionStr = self.number_to_string(pricePrecision)
|
|
709
|
+
isDelisted = self.safe_bool(market, 'isDelisted')
|
|
710
|
+
active = True
|
|
711
|
+
if isDelisted is not None:
|
|
712
|
+
active = not isDelisted
|
|
713
|
+
return self.safe_market_structure({
|
|
714
|
+
'id': baseId,
|
|
715
|
+
'symbol': symbol,
|
|
716
|
+
'base': base,
|
|
717
|
+
'quote': quote,
|
|
718
|
+
'settle': settle,
|
|
719
|
+
'baseId': baseId,
|
|
720
|
+
'quoteId': quoteId,
|
|
721
|
+
'settleId': settleId,
|
|
722
|
+
'type': 'swap',
|
|
723
|
+
'spot': False,
|
|
724
|
+
'margin': None,
|
|
725
|
+
'swap': swap,
|
|
726
|
+
'future': False,
|
|
727
|
+
'option': False,
|
|
728
|
+
'active': active,
|
|
729
|
+
'contract': contract,
|
|
730
|
+
'linear': True,
|
|
731
|
+
'inverse': False,
|
|
732
|
+
'taker': taker,
|
|
733
|
+
'maker': maker,
|
|
734
|
+
'contractSize': self.parse_number('1'),
|
|
735
|
+
'expiry': None,
|
|
736
|
+
'expiryDatetime': None,
|
|
737
|
+
'strike': None,
|
|
738
|
+
'optionType': None,
|
|
739
|
+
'precision': {
|
|
740
|
+
'amount': self.parse_number(self.parse_precision(amountPrecisionStr)),
|
|
741
|
+
'price': self.parse_number(self.parse_precision(pricePrecisionStr)),
|
|
742
|
+
},
|
|
743
|
+
'limits': {
|
|
744
|
+
'leverage': {
|
|
745
|
+
'min': None,
|
|
746
|
+
'max': self.safe_integer(market, 'maxLeverage'),
|
|
747
|
+
},
|
|
748
|
+
'amount': {
|
|
749
|
+
'min': None,
|
|
750
|
+
'max': None,
|
|
751
|
+
},
|
|
752
|
+
'price': {
|
|
753
|
+
'min': None,
|
|
754
|
+
'max': None,
|
|
755
|
+
},
|
|
756
|
+
'cost': {
|
|
757
|
+
'min': self.parse_number('10'),
|
|
758
|
+
'max': None,
|
|
759
|
+
},
|
|
760
|
+
},
|
|
761
|
+
'created': None,
|
|
762
|
+
'info': market,
|
|
763
|
+
})
|
|
764
|
+
|
|
765
|
+
async def fetch_balance(self, params={}) -> Balances:
|
|
766
|
+
"""
|
|
767
|
+
query for balance and get the amount of funds available for trading or funds locked in orders
|
|
768
|
+
|
|
769
|
+
https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint/spot#retrieve-a-users-token-balances
|
|
770
|
+
https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint/perpetuals#retrieve-users-perpetuals-account-summary
|
|
771
|
+
|
|
772
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
|
773
|
+
:param str [params.user]: user address, will default to self.walletAddress if not provided
|
|
774
|
+
:param str [params.type]: wallet type, ['spot', 'swap'], defaults to swap
|
|
775
|
+
:returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
|
|
776
|
+
"""
|
|
777
|
+
userAddress = None
|
|
778
|
+
userAddress, params = self.handle_public_address('fetchBalance', params)
|
|
779
|
+
type = None
|
|
780
|
+
type, params = self.handle_market_type_and_params('fetchBalance', None, params)
|
|
781
|
+
isSpot = (type == 'spot')
|
|
782
|
+
reqType = 'spotClearinghouseState' if (isSpot) else 'clearinghouseState'
|
|
783
|
+
request: dict = {
|
|
784
|
+
'type': reqType,
|
|
785
|
+
'user': userAddress,
|
|
786
|
+
}
|
|
787
|
+
response = await self.publicPostInfo(self.extend(request, params))
|
|
788
|
+
#
|
|
789
|
+
# {
|
|
790
|
+
# "assetPositions": [],
|
|
791
|
+
# "crossMaintenanceMarginUsed": "0.0",
|
|
792
|
+
# "crossMarginSummary": {
|
|
793
|
+
# "accountValue": "100.0",
|
|
794
|
+
# "totalMarginUsed": "0.0",
|
|
795
|
+
# "totalNtlPos": "0.0",
|
|
796
|
+
# "totalRawUsd": "100.0"
|
|
797
|
+
# },
|
|
798
|
+
# "marginSummary": {
|
|
799
|
+
# "accountValue": "100.0",
|
|
800
|
+
# "totalMarginUsed": "0.0",
|
|
801
|
+
# "totalNtlPos": "0.0",
|
|
802
|
+
# "totalRawUsd": "100.0"
|
|
803
|
+
# },
|
|
804
|
+
# "time": "1704261007014",
|
|
805
|
+
# "withdrawable": "100.0"
|
|
806
|
+
# }
|
|
807
|
+
# spot
|
|
808
|
+
#
|
|
809
|
+
# {
|
|
810
|
+
# "balances":[
|
|
811
|
+
# {
|
|
812
|
+
# "coin":"USDC",
|
|
813
|
+
# "hold":"0.0",
|
|
814
|
+
# "total":"1481.844"
|
|
815
|
+
# },
|
|
816
|
+
# {
|
|
817
|
+
# "coin":"PURR",
|
|
818
|
+
# "hold":"0.0",
|
|
819
|
+
# "total":"999.65004"
|
|
820
|
+
# }
|
|
821
|
+
# }
|
|
822
|
+
#
|
|
823
|
+
balances = self.safe_list(response, 'balances')
|
|
824
|
+
if balances is not None:
|
|
825
|
+
spotBalances: dict = {'info': response}
|
|
826
|
+
for i in range(0, len(balances)):
|
|
827
|
+
balance = balances[i]
|
|
828
|
+
code = self.safe_currency_code(self.safe_string(balance, 'coin'))
|
|
829
|
+
account = self.account()
|
|
830
|
+
total = self.safe_string(balance, 'total')
|
|
831
|
+
used = self.safe_string(balance, 'hold')
|
|
832
|
+
account['total'] = total
|
|
833
|
+
account['used'] = used
|
|
834
|
+
spotBalances[code] = account
|
|
835
|
+
return self.safe_balance(spotBalances)
|
|
836
|
+
data = self.safe_dict(response, 'marginSummary', {})
|
|
837
|
+
result: dict = {
|
|
838
|
+
'info': response,
|
|
839
|
+
'USDC': {
|
|
840
|
+
'total': self.safe_number(data, 'accountValue'),
|
|
841
|
+
'free': self.safe_number(response, 'withdrawable'),
|
|
842
|
+
},
|
|
843
|
+
}
|
|
844
|
+
timestamp = self.safe_integer(response, 'time')
|
|
845
|
+
result['timestamp'] = timestamp
|
|
846
|
+
result['datetime'] = self.iso8601(timestamp)
|
|
847
|
+
return self.safe_balance(result)
|
|
848
|
+
|
|
849
|
+
async def fetch_order_book(self, symbol: str, limit: Int = None, params={}) -> OrderBook:
|
|
850
|
+
"""
|
|
851
|
+
fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
|
|
852
|
+
|
|
853
|
+
https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint#l2-book-snapshot
|
|
854
|
+
|
|
855
|
+
:param str symbol: unified symbol of the market to fetch the order book for
|
|
856
|
+
:param int [limit]: the maximum amount of order book entries to return
|
|
857
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
|
858
|
+
:returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
|
|
859
|
+
"""
|
|
860
|
+
await self.load_markets()
|
|
861
|
+
market = self.market(symbol)
|
|
862
|
+
request: dict = {
|
|
863
|
+
'type': 'l2Book',
|
|
864
|
+
'coin': market['base'] if market['swap'] else market['id'],
|
|
865
|
+
}
|
|
866
|
+
response = await self.publicPostInfo(self.extend(request, params))
|
|
867
|
+
#
|
|
868
|
+
# {
|
|
869
|
+
# "coin": "ETH",
|
|
870
|
+
# "levels": [
|
|
871
|
+
# [
|
|
872
|
+
# {
|
|
873
|
+
# "n": "2",
|
|
874
|
+
# "px": "2216.2",
|
|
875
|
+
# "sz": "74.0637"
|
|
876
|
+
# }
|
|
877
|
+
# ],
|
|
878
|
+
# [
|
|
879
|
+
# {
|
|
880
|
+
# "n": "2",
|
|
881
|
+
# "px": "2216.5",
|
|
882
|
+
# "sz": "70.5893"
|
|
883
|
+
# }
|
|
884
|
+
# ]
|
|
885
|
+
# ],
|
|
886
|
+
# "time": "1704290104840"
|
|
887
|
+
# }
|
|
888
|
+
#
|
|
889
|
+
data = self.safe_list(response, 'levels', [])
|
|
890
|
+
result: dict = {
|
|
891
|
+
'bids': self.safe_list(data, 0, []),
|
|
892
|
+
'asks': self.safe_list(data, 1, []),
|
|
893
|
+
}
|
|
894
|
+
timestamp = self.safe_integer(response, 'time')
|
|
895
|
+
return self.parse_order_book(result, market['symbol'], timestamp, 'bids', 'asks', 'px', 'sz')
|
|
896
|
+
|
|
897
|
+
async def fetch_tickers(self, symbols: Strings = None, params={}) -> Tickers:
|
|
898
|
+
"""
|
|
899
|
+
fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
|
|
900
|
+
|
|
901
|
+
https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint/perpetuals#retrieve-perpetuals-asset-contexts-includes-mark-price-current-funding-open-interest-etc
|
|
902
|
+
https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint/spot#retrieve-spot-asset-contexts
|
|
903
|
+
|
|
904
|
+
:param str[] [symbols]: unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
|
|
905
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
|
906
|
+
:param str [params.type]: 'spot' or 'swap', by default fetches both
|
|
907
|
+
:returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
|
|
908
|
+
"""
|
|
909
|
+
await self.load_markets()
|
|
910
|
+
symbols = self.market_symbols(symbols)
|
|
911
|
+
# at self stage, to get tickers data, we use fetchMarkets endpoints
|
|
912
|
+
response = []
|
|
913
|
+
type = self.safe_string(params, 'type')
|
|
914
|
+
params = self.omit(params, 'type')
|
|
915
|
+
if type == 'spot':
|
|
916
|
+
response = await self.fetch_spot_markets(params)
|
|
917
|
+
elif type == 'swap':
|
|
918
|
+
response = await self.fetch_swap_markets(params)
|
|
919
|
+
else:
|
|
920
|
+
response = await self.fetch_markets(params)
|
|
921
|
+
# same response "fetchMarkets"
|
|
922
|
+
result: dict = {}
|
|
923
|
+
for i in range(0, len(response)):
|
|
924
|
+
market = response[i]
|
|
925
|
+
info = market['info']
|
|
926
|
+
ticker = self.parse_ticker(info, market)
|
|
927
|
+
symbol = self.safe_string(ticker, 'symbol')
|
|
928
|
+
result[symbol] = ticker
|
|
929
|
+
return self.filter_by_array_tickers(result, 'symbol', symbols)
|
|
930
|
+
|
|
931
|
+
async def fetch_funding_rates(self, symbols: Strings = None, params={}) -> FundingRates:
|
|
932
|
+
"""
|
|
933
|
+
retrieves data on all swap markets for hyperliquid
|
|
934
|
+
|
|
935
|
+
https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint/perpetuals#retrieve-perpetuals-asset-contexts-includes-mark-price-current-funding-open-interest-etc
|
|
936
|
+
|
|
937
|
+
:param str[] [symbols]: list of unified market symbols
|
|
938
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
|
939
|
+
:returns dict[]: an array of objects representing market data
|
|
940
|
+
"""
|
|
941
|
+
request: dict = {
|
|
942
|
+
'type': 'metaAndAssetCtxs',
|
|
943
|
+
}
|
|
944
|
+
response = await self.publicPostInfo(self.extend(request, params))
|
|
945
|
+
#
|
|
946
|
+
# [
|
|
947
|
+
# {
|
|
948
|
+
# "universe": [
|
|
949
|
+
# {
|
|
950
|
+
# "maxLeverage": 50,
|
|
951
|
+
# "name": "SOL",
|
|
952
|
+
# "onlyIsolated": False,
|
|
953
|
+
# "szDecimals": 2
|
|
954
|
+
# }
|
|
955
|
+
# ]
|
|
956
|
+
# },
|
|
957
|
+
# [
|
|
958
|
+
# {
|
|
959
|
+
# "dayNtlVlm": "9450588.2273",
|
|
960
|
+
# "funding": "0.0000198",
|
|
961
|
+
# "impactPxs": [
|
|
962
|
+
# "108.04",
|
|
963
|
+
# "108.06"
|
|
964
|
+
# ],
|
|
965
|
+
# "markPx": "108.04",
|
|
966
|
+
# "midPx": "108.05",
|
|
967
|
+
# "openInterest": "10764.48",
|
|
968
|
+
# "oraclePx": "107.99",
|
|
969
|
+
# "premium": "0.00055561",
|
|
970
|
+
# "prevDayPx": "111.81"
|
|
971
|
+
# }
|
|
972
|
+
# ]
|
|
973
|
+
# ]
|
|
974
|
+
#
|
|
975
|
+
#
|
|
976
|
+
meta = self.safe_dict(response, 0, {})
|
|
977
|
+
universe = self.safe_list(meta, 'universe', [])
|
|
978
|
+
assetCtxs = self.safe_list(response, 1, [])
|
|
979
|
+
result = []
|
|
980
|
+
for i in range(0, len(universe)):
|
|
981
|
+
data = self.extend(
|
|
982
|
+
self.safe_dict(universe, i, {}),
|
|
983
|
+
self.safe_dict(assetCtxs, i, {})
|
|
984
|
+
)
|
|
985
|
+
result.append(data)
|
|
986
|
+
return self.parse_funding_rates(result, symbols)
|
|
987
|
+
|
|
988
|
+
def parse_funding_rate(self, info, market: Market = None) -> FundingRate:
|
|
989
|
+
#
|
|
990
|
+
# {
|
|
991
|
+
# "maxLeverage": "50",
|
|
992
|
+
# "name": "ETH",
|
|
993
|
+
# "onlyIsolated": False,
|
|
994
|
+
# "szDecimals": "4",
|
|
995
|
+
# "dayNtlVlm": "1709813.11535",
|
|
996
|
+
# "funding": "0.00004807",
|
|
997
|
+
# "impactPxs": [
|
|
998
|
+
# "2369.3",
|
|
999
|
+
# "2369.6"
|
|
1000
|
+
# ],
|
|
1001
|
+
# "markPx": "2369.6",
|
|
1002
|
+
# "midPx": "2369.45",
|
|
1003
|
+
# "openInterest": "1815.4712",
|
|
1004
|
+
# "oraclePx": "2367.3",
|
|
1005
|
+
# "premium": "0.00090821",
|
|
1006
|
+
# "prevDayPx": "2381.5"
|
|
1007
|
+
# }
|
|
1008
|
+
#
|
|
1009
|
+
base = self.safe_string(info, 'name')
|
|
1010
|
+
marketId = self.coin_to_market_id(base)
|
|
1011
|
+
symbol = self.safe_symbol(marketId, market)
|
|
1012
|
+
funding = self.safe_number(info, 'funding')
|
|
1013
|
+
markPx = self.safe_number(info, 'markPx')
|
|
1014
|
+
oraclePx = self.safe_number(info, 'oraclePx')
|
|
1015
|
+
fundingTimestamp = (int(math.floor(self.milliseconds()) / 60 / 60 / 1000) + 1) * 60 * 60 * 1000
|
|
1016
|
+
return {
|
|
1017
|
+
'info': info,
|
|
1018
|
+
'symbol': symbol,
|
|
1019
|
+
'markPrice': markPx,
|
|
1020
|
+
'indexPrice': oraclePx,
|
|
1021
|
+
'interestRate': None,
|
|
1022
|
+
'estimatedSettlePrice': None,
|
|
1023
|
+
'timestamp': None,
|
|
1024
|
+
'datetime': None,
|
|
1025
|
+
'fundingRate': funding,
|
|
1026
|
+
'fundingTimestamp': fundingTimestamp,
|
|
1027
|
+
'fundingDatetime': self.iso8601(fundingTimestamp),
|
|
1028
|
+
'nextFundingRate': None,
|
|
1029
|
+
'nextFundingTimestamp': None,
|
|
1030
|
+
'nextFundingDatetime': None,
|
|
1031
|
+
'previousFundingRate': None,
|
|
1032
|
+
'previousFundingTimestamp': None,
|
|
1033
|
+
'previousFundingDatetime': None,
|
|
1034
|
+
'interval': '1h',
|
|
1035
|
+
}
|
|
1036
|
+
|
|
1037
|
+
def parse_ticker(self, ticker: dict, market: Market = None) -> Ticker:
|
|
1038
|
+
#
|
|
1039
|
+
# {
|
|
1040
|
+
# "prevDayPx": "3400.5",
|
|
1041
|
+
# "dayNtlVlm": "511297257.47936022",
|
|
1042
|
+
# "markPx": "3464.7",
|
|
1043
|
+
# "midPx": "3465.05",
|
|
1044
|
+
# "oraclePx": "3460.1", # only in swap
|
|
1045
|
+
# "openInterest": "64638.1108", # only in swap
|
|
1046
|
+
# "premium": "0.00141614", # only in swap
|
|
1047
|
+
# "funding": "0.00008727", # only in swap
|
|
1048
|
+
# "impactPxs": ["3465.0", "3465.1"], # only in swap
|
|
1049
|
+
# "coin": "PURR", # only in spot
|
|
1050
|
+
# "circulatingSupply": "998949190.03400207", # only in spot
|
|
1051
|
+
# },
|
|
1052
|
+
#
|
|
1053
|
+
bidAsk = self.safe_list(ticker, 'impactPxs')
|
|
1054
|
+
return self.safe_ticker({
|
|
1055
|
+
'symbol': market['symbol'],
|
|
1056
|
+
'timestamp': None,
|
|
1057
|
+
'datetime': None,
|
|
1058
|
+
'previousClose': self.safe_number(ticker, 'prevDayPx'),
|
|
1059
|
+
'close': self.safe_number(ticker, 'midPx'),
|
|
1060
|
+
'bid': self.safe_number(bidAsk, 0),
|
|
1061
|
+
'ask': self.safe_number(bidAsk, 1),
|
|
1062
|
+
'quoteVolume': self.safe_number(ticker, 'dayNtlVlm'),
|
|
1063
|
+
'info': ticker,
|
|
1064
|
+
}, market)
|
|
1065
|
+
|
|
1066
|
+
async def fetch_ohlcv(self, symbol: str, timeframe='1m', since: Int = None, limit: Int = None, params={}) -> List[list]:
|
|
1067
|
+
"""
|
|
1068
|
+
fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
|
|
1069
|
+
|
|
1070
|
+
https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint#candle-snapshot
|
|
1071
|
+
|
|
1072
|
+
:param str symbol: unified symbol of the market to fetch OHLCV data for
|
|
1073
|
+
:param str timeframe: the length of time each candle represents, support '1m', '15m', '1h', '1d'
|
|
1074
|
+
:param int [since]: timestamp in ms of the earliest candle to fetch
|
|
1075
|
+
:param int [limit]: the maximum amount of candles to fetch
|
|
1076
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
|
1077
|
+
:param int [params.until]: timestamp in ms of the latest candle to fetch
|
|
1078
|
+
:returns int[][]: A list of candles ordered, open, high, low, close, volume
|
|
1079
|
+
"""
|
|
1080
|
+
await self.load_markets()
|
|
1081
|
+
market = self.market(symbol)
|
|
1082
|
+
until = self.safe_integer(params, 'until', self.milliseconds())
|
|
1083
|
+
useTail = since is None
|
|
1084
|
+
originalSince = since
|
|
1085
|
+
if since is None:
|
|
1086
|
+
if limit is not None:
|
|
1087
|
+
# optimization if limit is provided
|
|
1088
|
+
timeframeInMilliseconds = self.parse_timeframe(timeframe) * 1000
|
|
1089
|
+
since = self.sum(until, timeframeInMilliseconds * limit * -1)
|
|
1090
|
+
useTail = False
|
|
1091
|
+
else:
|
|
1092
|
+
since = 0
|
|
1093
|
+
params = self.omit(params, ['until'])
|
|
1094
|
+
request: dict = {
|
|
1095
|
+
'type': 'candleSnapshot',
|
|
1096
|
+
'req': {
|
|
1097
|
+
'coin': market['base'] if market['swap'] else market['id'],
|
|
1098
|
+
'interval': self.safe_string(self.timeframes, timeframe, timeframe),
|
|
1099
|
+
'startTime': since,
|
|
1100
|
+
'endTime': until,
|
|
1101
|
+
},
|
|
1102
|
+
}
|
|
1103
|
+
response = await self.publicPostInfo(self.extend(request, params))
|
|
1104
|
+
#
|
|
1105
|
+
# [
|
|
1106
|
+
# {
|
|
1107
|
+
# "T": 1704287699999,
|
|
1108
|
+
# "c": "2226.4",
|
|
1109
|
+
# "h": "2247.9",
|
|
1110
|
+
# "i": "15m",
|
|
1111
|
+
# "l": "2224.6",
|
|
1112
|
+
# "n": 46,
|
|
1113
|
+
# "o": "2247.9",
|
|
1114
|
+
# "s": "ETH",
|
|
1115
|
+
# "t": 1704286800000,
|
|
1116
|
+
# "v": "591.6427"
|
|
1117
|
+
# }
|
|
1118
|
+
# ]
|
|
1119
|
+
#
|
|
1120
|
+
return self.parse_ohlcvs(response, market, timeframe, originalSince, limit, useTail)
|
|
1121
|
+
|
|
1122
|
+
def parse_ohlcv(self, ohlcv, market: Market = None) -> list:
|
|
1123
|
+
#
|
|
1124
|
+
# {
|
|
1125
|
+
# "T": 1704287699999,
|
|
1126
|
+
# "c": "2226.4",
|
|
1127
|
+
# "h": "2247.9",
|
|
1128
|
+
# "i": "15m",
|
|
1129
|
+
# "l": "2224.6",
|
|
1130
|
+
# "n": 46,
|
|
1131
|
+
# "o": "2247.9",
|
|
1132
|
+
# "s": "ETH",
|
|
1133
|
+
# "t": 1704286800000,
|
|
1134
|
+
# "v": "591.6427"
|
|
1135
|
+
# }
|
|
1136
|
+
#
|
|
1137
|
+
return [
|
|
1138
|
+
self.safe_integer(ohlcv, 't'),
|
|
1139
|
+
self.safe_number(ohlcv, 'o'),
|
|
1140
|
+
self.safe_number(ohlcv, 'h'),
|
|
1141
|
+
self.safe_number(ohlcv, 'l'),
|
|
1142
|
+
self.safe_number(ohlcv, 'c'),
|
|
1143
|
+
self.safe_number(ohlcv, 'v'),
|
|
1144
|
+
]
|
|
1145
|
+
|
|
1146
|
+
async def fetch_trades(self, symbol: Str, since: Int = None, limit: Int = None, params={}):
|
|
1147
|
+
"""
|
|
1148
|
+
get the list of most recent trades for a particular symbol
|
|
1149
|
+
|
|
1150
|
+
https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint#retrieve-a-users-fills
|
|
1151
|
+
https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint#retrieve-a-users-fills-by-time
|
|
1152
|
+
|
|
1153
|
+
:param str symbol: unified market symbol
|
|
1154
|
+
:param int [since]: the earliest time in ms to fetch trades for
|
|
1155
|
+
:param int [limit]: the maximum number of trades structures to retrieve
|
|
1156
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
|
1157
|
+
:param int [params.until]: timestamp in ms of the latest trade
|
|
1158
|
+
:param str [params.address]: wallet address that made trades
|
|
1159
|
+
:param str [params.user]: wallet address that made trades
|
|
1160
|
+
:returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
|
|
1161
|
+
"""
|
|
1162
|
+
userAddress = None
|
|
1163
|
+
userAddress, params = self.handle_public_address('fetchTrades', params)
|
|
1164
|
+
await self.load_markets()
|
|
1165
|
+
market = self.safe_market(symbol)
|
|
1166
|
+
request: dict = {
|
|
1167
|
+
'user': userAddress,
|
|
1168
|
+
}
|
|
1169
|
+
if since is not None:
|
|
1170
|
+
request['type'] = 'userFillsByTime'
|
|
1171
|
+
request['startTime'] = since
|
|
1172
|
+
else:
|
|
1173
|
+
request['type'] = 'userFills'
|
|
1174
|
+
until = self.safe_integer(params, 'until')
|
|
1175
|
+
params = self.omit(params, 'until')
|
|
1176
|
+
if until is not None:
|
|
1177
|
+
request['endTime'] = until
|
|
1178
|
+
response = await self.publicPostInfo(self.extend(request, params))
|
|
1179
|
+
#
|
|
1180
|
+
# [
|
|
1181
|
+
# {
|
|
1182
|
+
# "closedPnl": "0.19343",
|
|
1183
|
+
# "coin": "ETH",
|
|
1184
|
+
# "crossed": True,
|
|
1185
|
+
# "dir": "Close Long",
|
|
1186
|
+
# "fee": "0.050062",
|
|
1187
|
+
# "hash": "0x09d77c96791e98b5775a04092584ab010d009445119c71e4005c0d634ea322bc",
|
|
1188
|
+
# "liquidationMarkPx": null,
|
|
1189
|
+
# "oid": 3929354691,
|
|
1190
|
+
# "px": "2381.1",
|
|
1191
|
+
# "side": "A",
|
|
1192
|
+
# "startPosition": "0.0841",
|
|
1193
|
+
# "sz": "0.0841",
|
|
1194
|
+
# "tid": 128423918764978,
|
|
1195
|
+
# "time": 1704262888911
|
|
1196
|
+
# }
|
|
1197
|
+
# ]
|
|
1198
|
+
#
|
|
1199
|
+
return self.parse_trades(response, market, since, limit)
|
|
1200
|
+
|
|
1201
|
+
def amount_to_precision(self, symbol, amount):
|
|
1202
|
+
market = self.market(symbol)
|
|
1203
|
+
return self.decimal_to_precision(amount, ROUND, market['precision']['amount'], self.precisionMode, self.paddingMode)
|
|
1204
|
+
|
|
1205
|
+
def price_to_precision(self, symbol: str, price) -> str:
|
|
1206
|
+
market = self.market(symbol)
|
|
1207
|
+
priceStr = self.number_to_string(price)
|
|
1208
|
+
integerPart = priceStr.split('.')[0]
|
|
1209
|
+
significantDigits = max(5, len(integerPart))
|
|
1210
|
+
result = self.decimal_to_precision(price, ROUND, significantDigits, SIGNIFICANT_DIGITS, self.paddingMode)
|
|
1211
|
+
maxDecimals = 8 if market['spot'] else 6
|
|
1212
|
+
subtractedValue = maxDecimals - self.precision_from_string(self.safe_string(market['precision'], 'amount'))
|
|
1213
|
+
return self.decimal_to_precision(result, ROUND, subtractedValue, DECIMAL_PLACES, self.paddingMode)
|
|
1214
|
+
|
|
1215
|
+
def hash_message(self, message):
|
|
1216
|
+
return '0x' + self.hash(message, 'keccak', 'hex')
|
|
1217
|
+
|
|
1218
|
+
def sign_hash(self, hash, privateKey):
|
|
1219
|
+
signature = self.ecdsa(hash[-64:], privateKey[-64:], 'secp256k1', None)
|
|
1220
|
+
return {
|
|
1221
|
+
'r': '0x' + signature['r'],
|
|
1222
|
+
's': '0x' + signature['s'],
|
|
1223
|
+
'v': self.sum(27, signature['v']),
|
|
1224
|
+
}
|
|
1225
|
+
|
|
1226
|
+
def sign_message(self, message, privateKey):
|
|
1227
|
+
return self.sign_hash(self.hash_message(message), privateKey[-64:])
|
|
1228
|
+
|
|
1229
|
+
def construct_phantom_agent(self, hash, isTestnet=True):
|
|
1230
|
+
source = 'b' if (isTestnet) else 'a'
|
|
1231
|
+
return {
|
|
1232
|
+
'source': source,
|
|
1233
|
+
'connectionId': hash,
|
|
1234
|
+
}
|
|
1235
|
+
|
|
1236
|
+
def action_hash(self, action, vaultAddress, nonce):
|
|
1237
|
+
dataBinary = self.packb(action)
|
|
1238
|
+
dataHex = self.binary_to_base16(dataBinary)
|
|
1239
|
+
data = dataHex
|
|
1240
|
+
data += '00000' + self.int_to_base16(nonce)
|
|
1241
|
+
if vaultAddress is None:
|
|
1242
|
+
data += '00'
|
|
1243
|
+
else:
|
|
1244
|
+
data += '01'
|
|
1245
|
+
data += vaultAddress
|
|
1246
|
+
return self.hash(self.base16_to_binary(data), 'keccak', 'binary')
|
|
1247
|
+
|
|
1248
|
+
def sign_l1_action(self, action, nonce, vaultAdress=None) -> object:
|
|
1249
|
+
hash = self.action_hash(action, vaultAdress, nonce)
|
|
1250
|
+
isTestnet = self.safe_bool(self.options, 'sandboxMode', False)
|
|
1251
|
+
phantomAgent = self.construct_phantom_agent(hash, isTestnet)
|
|
1252
|
+
# data: Dict = {
|
|
1253
|
+
# 'domain': {
|
|
1254
|
+
# 'chainId': 1337,
|
|
1255
|
+
# 'name': 'Exchange',
|
|
1256
|
+
# 'verifyingContract': '0x0000000000000000000000000000000000000000',
|
|
1257
|
+
# 'version': '1',
|
|
1258
|
+
# },
|
|
1259
|
+
# 'types': {
|
|
1260
|
+
# 'Agent': [
|
|
1261
|
+
# {'name': 'source', 'type': 'string'},
|
|
1262
|
+
# {'name': 'connectionId', 'type': 'bytes32'},
|
|
1263
|
+
# ],
|
|
1264
|
+
# 'EIP712Domain': [
|
|
1265
|
+
# {'name': 'name', 'type': 'string'},
|
|
1266
|
+
# {'name': 'version', 'type': 'string'},
|
|
1267
|
+
# {'name': 'chainId', 'type': 'uint256'},
|
|
1268
|
+
# {'name': 'verifyingContract', 'type': 'address'},
|
|
1269
|
+
# ],
|
|
1270
|
+
# },
|
|
1271
|
+
# 'primaryType': 'Agent',
|
|
1272
|
+
# 'message': phantomAgent,
|
|
1273
|
+
# }
|
|
1274
|
+
zeroAddress = self.safe_string(self.options, 'zeroAddress')
|
|
1275
|
+
chainId = 1337 # check self out
|
|
1276
|
+
domain: dict = {
|
|
1277
|
+
'chainId': chainId,
|
|
1278
|
+
'name': 'Exchange',
|
|
1279
|
+
'verifyingContract': zeroAddress,
|
|
1280
|
+
'version': '1',
|
|
1281
|
+
}
|
|
1282
|
+
messageTypes: dict = {
|
|
1283
|
+
'Agent': [
|
|
1284
|
+
{'name': 'source', 'type': 'string'},
|
|
1285
|
+
{'name': 'connectionId', 'type': 'bytes32'},
|
|
1286
|
+
],
|
|
1287
|
+
}
|
|
1288
|
+
msg = self.eth_encode_structured_data(domain, messageTypes, phantomAgent)
|
|
1289
|
+
signature = self.sign_message(msg, self.privateKey)
|
|
1290
|
+
return signature
|
|
1291
|
+
|
|
1292
|
+
def sign_user_signed_action(self, messageTypes, message):
|
|
1293
|
+
zeroAddress = self.safe_string(self.options, 'zeroAddress')
|
|
1294
|
+
chainId = 421614 # check self out
|
|
1295
|
+
domain: dict = {
|
|
1296
|
+
'chainId': chainId,
|
|
1297
|
+
'name': 'HyperliquidSignTransaction',
|
|
1298
|
+
'verifyingContract': zeroAddress,
|
|
1299
|
+
'version': '1',
|
|
1300
|
+
}
|
|
1301
|
+
msg = self.eth_encode_structured_data(domain, messageTypes, message)
|
|
1302
|
+
signature = self.sign_message(msg, self.privateKey)
|
|
1303
|
+
return signature
|
|
1304
|
+
|
|
1305
|
+
def build_usd_send_sig(self, message):
|
|
1306
|
+
messageTypes: dict = {
|
|
1307
|
+
'HyperliquidTransaction:UsdSend': [
|
|
1308
|
+
{'name': 'hyperliquidChain', 'type': 'string'},
|
|
1309
|
+
{'name': 'destination', 'type': 'string'},
|
|
1310
|
+
{'name': 'amount', 'type': 'string'},
|
|
1311
|
+
{'name': 'time', 'type': 'uint64'},
|
|
1312
|
+
],
|
|
1313
|
+
}
|
|
1314
|
+
return self.sign_user_signed_action(messageTypes, message)
|
|
1315
|
+
|
|
1316
|
+
def build_usd_class_send_sig(self, message):
|
|
1317
|
+
messageTypes: dict = {
|
|
1318
|
+
'HyperliquidTransaction:UsdClassTransfer': [
|
|
1319
|
+
{'name': 'hyperliquidChain', 'type': 'string'},
|
|
1320
|
+
{'name': 'amount', 'type': 'string'},
|
|
1321
|
+
{'name': 'toPerp', 'type': 'bool'},
|
|
1322
|
+
{'name': 'nonce', 'type': 'uint64'},
|
|
1323
|
+
],
|
|
1324
|
+
}
|
|
1325
|
+
return self.sign_user_signed_action(messageTypes, message)
|
|
1326
|
+
|
|
1327
|
+
def build_withdraw_sig(self, message):
|
|
1328
|
+
messageTypes: dict = {
|
|
1329
|
+
'HyperliquidTransaction:Withdraw': [
|
|
1330
|
+
{'name': 'hyperliquidChain', 'type': 'string'},
|
|
1331
|
+
{'name': 'destination', 'type': 'string'},
|
|
1332
|
+
{'name': 'amount', 'type': 'string'},
|
|
1333
|
+
{'name': 'time', 'type': 'uint64'},
|
|
1334
|
+
],
|
|
1335
|
+
}
|
|
1336
|
+
return self.sign_user_signed_action(messageTypes, message)
|
|
1337
|
+
|
|
1338
|
+
async def create_order(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, params={}):
|
|
1339
|
+
"""
|
|
1340
|
+
create a trade order
|
|
1341
|
+
|
|
1342
|
+
https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#place-an-order
|
|
1343
|
+
|
|
1344
|
+
:param str symbol: unified symbol of the market to create an order in
|
|
1345
|
+
:param str type: 'market' or 'limit'
|
|
1346
|
+
:param str side: 'buy' or 'sell'
|
|
1347
|
+
:param float amount: how much of currency you want to trade in units of base currency
|
|
1348
|
+
:param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
|
|
1349
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
|
1350
|
+
:param str [params.timeInForce]: 'Gtc', 'Ioc', 'Alo'
|
|
1351
|
+
:param bool [params.postOnly]: True or False whether the order is post-only
|
|
1352
|
+
:param bool [params.reduceOnly]: True or False whether the order is reduce-only
|
|
1353
|
+
:param float [params.triggerPrice]: The price at which a trigger order is triggered at
|
|
1354
|
+
:param str [params.clientOrderId]: client order id,(optional 128 bit hex string e.g. 0x1234567890abcdef1234567890abcdef)
|
|
1355
|
+
:param str [params.slippage]: the slippage for market order
|
|
1356
|
+
:param str [params.vaultAddress]: the vault address for order
|
|
1357
|
+
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
|
|
1358
|
+
"""
|
|
1359
|
+
await self.load_markets()
|
|
1360
|
+
order, globalParams = self.parse_create_edit_order_args(None, symbol, type, side, amount, price, params)
|
|
1361
|
+
orders = await self.create_orders([order], globalParams)
|
|
1362
|
+
return orders[0]
|
|
1363
|
+
|
|
1364
|
+
async def create_orders(self, orders: List[OrderRequest], params={}):
|
|
1365
|
+
"""
|
|
1366
|
+
create a list of trade orders
|
|
1367
|
+
|
|
1368
|
+
https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#place-an-order
|
|
1369
|
+
|
|
1370
|
+
: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
|
|
1371
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
|
1372
|
+
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
|
|
1373
|
+
"""
|
|
1374
|
+
await self.load_markets()
|
|
1375
|
+
request = self.create_orders_request(orders, params)
|
|
1376
|
+
response = await self.privatePostExchange(request)
|
|
1377
|
+
#
|
|
1378
|
+
# {
|
|
1379
|
+
# "status": "ok",
|
|
1380
|
+
# "response": {
|
|
1381
|
+
# "type": "order",
|
|
1382
|
+
# "data": {
|
|
1383
|
+
# "statuses": [
|
|
1384
|
+
# {
|
|
1385
|
+
# "resting": {
|
|
1386
|
+
# "oid": 5063830287
|
|
1387
|
+
# }
|
|
1388
|
+
# }
|
|
1389
|
+
# ]
|
|
1390
|
+
# }
|
|
1391
|
+
# }
|
|
1392
|
+
# }
|
|
1393
|
+
#
|
|
1394
|
+
responseObj = self.safe_dict(response, 'response', {})
|
|
1395
|
+
data = self.safe_dict(responseObj, 'data', {})
|
|
1396
|
+
statuses = self.safe_list(data, 'statuses', [])
|
|
1397
|
+
return self.parse_orders(statuses, None)
|
|
1398
|
+
|
|
1399
|
+
def create_orders_request(self, orders, params={}) -> dict:
|
|
1400
|
+
"""
|
|
1401
|
+
create a list of trade orders
|
|
1402
|
+
https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#place-an-order
|
|
1403
|
+
: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
|
|
1404
|
+
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
|
|
1405
|
+
"""
|
|
1406
|
+
self.check_required_credentials()
|
|
1407
|
+
defaultSlippage = self.safe_string(self.options, 'defaultSlippage')
|
|
1408
|
+
defaultSlippage = self.safe_string(params, 'slippage', defaultSlippage)
|
|
1409
|
+
hasClientOrderId = False
|
|
1410
|
+
for i in range(0, len(orders)):
|
|
1411
|
+
rawOrder = orders[i]
|
|
1412
|
+
orderParams = self.safe_dict(rawOrder, 'params', {})
|
|
1413
|
+
clientOrderId = self.safe_string_2(orderParams, 'clientOrderId', 'client_id')
|
|
1414
|
+
if clientOrderId is not None:
|
|
1415
|
+
hasClientOrderId = True
|
|
1416
|
+
if hasClientOrderId:
|
|
1417
|
+
for i in range(0, len(orders)):
|
|
1418
|
+
rawOrder = orders[i]
|
|
1419
|
+
orderParams = self.safe_dict(rawOrder, 'params', {})
|
|
1420
|
+
clientOrderId = self.safe_string_2(orderParams, 'clientOrderId', 'client_id')
|
|
1421
|
+
if clientOrderId is None:
|
|
1422
|
+
raise ArgumentsRequired(self.id + ' createOrders() all orders must have clientOrderId if at least one has a clientOrderId')
|
|
1423
|
+
params = self.omit(params, ['slippage', 'clientOrderId', 'client_id', 'slippage', 'triggerPrice', 'stopPrice', 'stopLossPrice', 'takeProfitPrice', 'timeInForce'])
|
|
1424
|
+
nonce = self.milliseconds()
|
|
1425
|
+
orderReq = []
|
|
1426
|
+
for i in range(0, len(orders)):
|
|
1427
|
+
rawOrder = orders[i]
|
|
1428
|
+
marketId = self.safe_string(rawOrder, 'symbol')
|
|
1429
|
+
market = self.market(marketId)
|
|
1430
|
+
symbol = market['symbol']
|
|
1431
|
+
type = self.safe_string_upper(rawOrder, 'type')
|
|
1432
|
+
isMarket = (type == 'MARKET')
|
|
1433
|
+
side = self.safe_string_upper(rawOrder, 'side')
|
|
1434
|
+
isBuy = (side == 'BUY')
|
|
1435
|
+
amount = self.safe_string(rawOrder, 'amount')
|
|
1436
|
+
price = self.safe_string(rawOrder, 'price')
|
|
1437
|
+
orderParams = self.safe_dict(rawOrder, 'params', {})
|
|
1438
|
+
clientOrderId = self.safe_string_2(orderParams, 'clientOrderId', 'client_id')
|
|
1439
|
+
slippage = self.safe_string(orderParams, 'slippage', defaultSlippage)
|
|
1440
|
+
defaultTimeInForce = 'ioc' if (isMarket) else 'gtc'
|
|
1441
|
+
postOnly = self.safe_bool(orderParams, 'postOnly', False)
|
|
1442
|
+
if postOnly:
|
|
1443
|
+
defaultTimeInForce = 'alo'
|
|
1444
|
+
timeInForce = self.safe_string_lower(orderParams, 'timeInForce', defaultTimeInForce)
|
|
1445
|
+
timeInForce = self.capitalize(timeInForce)
|
|
1446
|
+
triggerPrice = self.safe_string_2(orderParams, 'triggerPrice', 'stopPrice')
|
|
1447
|
+
stopLossPrice = self.safe_string(orderParams, 'stopLossPrice', triggerPrice)
|
|
1448
|
+
takeProfitPrice = self.safe_string(orderParams, 'takeProfitPrice')
|
|
1449
|
+
isTrigger = (stopLossPrice or takeProfitPrice)
|
|
1450
|
+
px = None
|
|
1451
|
+
if isMarket:
|
|
1452
|
+
if price is None:
|
|
1453
|
+
raise ArgumentsRequired(self.id + ' market orders require price to calculate the max slippage price. Default slippage can be set in options(default is 5%).')
|
|
1454
|
+
px = Precise.string_mul(price, Precise.string_add('1', slippage)) if (isBuy) else Precise.string_mul(price, Precise.string_sub('1', slippage))
|
|
1455
|
+
px = self.price_to_precision(symbol, px) # round after adding slippage
|
|
1456
|
+
else:
|
|
1457
|
+
px = self.price_to_precision(symbol, price)
|
|
1458
|
+
sz = self.amount_to_precision(symbol, amount)
|
|
1459
|
+
reduceOnly = self.safe_bool(orderParams, 'reduceOnly', False)
|
|
1460
|
+
orderType: dict = {}
|
|
1461
|
+
if isTrigger:
|
|
1462
|
+
isTp = False
|
|
1463
|
+
if takeProfitPrice is not None:
|
|
1464
|
+
triggerPrice = self.price_to_precision(symbol, takeProfitPrice)
|
|
1465
|
+
isTp = True
|
|
1466
|
+
else:
|
|
1467
|
+
triggerPrice = self.price_to_precision(symbol, stopLossPrice)
|
|
1468
|
+
orderType['trigger'] = {
|
|
1469
|
+
'isMarket': isMarket,
|
|
1470
|
+
'triggerPx': triggerPrice,
|
|
1471
|
+
'tpsl': 'tp' if (isTp) else 'sl',
|
|
1472
|
+
}
|
|
1473
|
+
else:
|
|
1474
|
+
orderType['limit'] = {
|
|
1475
|
+
'tif': timeInForce,
|
|
1476
|
+
}
|
|
1477
|
+
orderParams = self.omit(orderParams, ['clientOrderId', 'slippage', 'triggerPrice', 'stopPrice', 'stopLossPrice', 'takeProfitPrice', 'timeInForce', 'client_id', 'reduceOnly', 'postOnly'])
|
|
1478
|
+
orderObj: dict = {
|
|
1479
|
+
'a': self.parse_to_int(market['baseId']),
|
|
1480
|
+
'b': isBuy,
|
|
1481
|
+
'p': px,
|
|
1482
|
+
's': sz,
|
|
1483
|
+
'r': reduceOnly,
|
|
1484
|
+
't': orderType,
|
|
1485
|
+
# 'c': clientOrderId,
|
|
1486
|
+
}
|
|
1487
|
+
if clientOrderId is not None:
|
|
1488
|
+
orderObj['c'] = clientOrderId
|
|
1489
|
+
orderReq.append(orderObj)
|
|
1490
|
+
vaultAddress = self.format_vault_address(self.safe_string(params, 'vaultAddress'))
|
|
1491
|
+
orderAction: dict = {
|
|
1492
|
+
'type': 'order',
|
|
1493
|
+
'orders': orderReq,
|
|
1494
|
+
'grouping': 'na',
|
|
1495
|
+
# 'brokerCode': 1, # cant
|
|
1496
|
+
}
|
|
1497
|
+
if vaultAddress is None:
|
|
1498
|
+
orderAction['brokerCode'] = 1
|
|
1499
|
+
signature = self.sign_l1_action(orderAction, nonce, vaultAddress)
|
|
1500
|
+
request: dict = {
|
|
1501
|
+
'action': orderAction,
|
|
1502
|
+
'nonce': nonce,
|
|
1503
|
+
'signature': signature,
|
|
1504
|
+
# 'vaultAddress': vaultAddress,
|
|
1505
|
+
}
|
|
1506
|
+
if vaultAddress is not None:
|
|
1507
|
+
params = self.omit(params, 'vaultAddress')
|
|
1508
|
+
request['vaultAddress'] = vaultAddress
|
|
1509
|
+
return request
|
|
1510
|
+
|
|
1511
|
+
async def cancel_order(self, id: str, symbol: Str = None, params={}):
|
|
1512
|
+
"""
|
|
1513
|
+
cancels an open order
|
|
1514
|
+
|
|
1515
|
+
https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#cancel-order-s
|
|
1516
|
+
https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#cancel-order-s-by-cloid
|
|
1517
|
+
|
|
1518
|
+
:param str id: order id
|
|
1519
|
+
:param str symbol: unified symbol of the market the order was made in
|
|
1520
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
|
1521
|
+
:param str [params.clientOrderId]: client order id,(optional 128 bit hex string e.g. 0x1234567890abcdef1234567890abcdef)
|
|
1522
|
+
:param str [params.vaultAddress]: the vault address for order
|
|
1523
|
+
:returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
|
|
1524
|
+
"""
|
|
1525
|
+
orders = await self.cancel_orders([id], symbol, params)
|
|
1526
|
+
return self.safe_dict(orders, 0)
|
|
1527
|
+
|
|
1528
|
+
async def cancel_orders(self, ids: List[str], symbol: Str = None, params={}):
|
|
1529
|
+
"""
|
|
1530
|
+
cancel multiple orders
|
|
1531
|
+
|
|
1532
|
+
https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#cancel-order-s
|
|
1533
|
+
https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#cancel-order-s-by-cloid
|
|
1534
|
+
|
|
1535
|
+
:param str[] ids: order ids
|
|
1536
|
+
:param str [symbol]: unified market symbol
|
|
1537
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
|
1538
|
+
:param string|str[] [params.clientOrderId]: client order ids,(optional 128 bit hex string e.g. 0x1234567890abcdef1234567890abcdef)
|
|
1539
|
+
:param str [params.vaultAddress]: the vault address
|
|
1540
|
+
:returns dict: an list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
|
|
1541
|
+
"""
|
|
1542
|
+
self.check_required_credentials()
|
|
1543
|
+
if symbol is None:
|
|
1544
|
+
raise ArgumentsRequired(self.id + ' cancelOrders() requires a symbol argument')
|
|
1545
|
+
await self.load_markets()
|
|
1546
|
+
market = self.market(symbol)
|
|
1547
|
+
clientOrderId = self.safe_value_2(params, 'clientOrderId', 'client_id')
|
|
1548
|
+
params = self.omit(params, ['clientOrderId', 'client_id'])
|
|
1549
|
+
nonce = self.milliseconds()
|
|
1550
|
+
request: dict = {
|
|
1551
|
+
'nonce': nonce,
|
|
1552
|
+
# 'vaultAddress': vaultAddress,
|
|
1553
|
+
}
|
|
1554
|
+
cancelReq = []
|
|
1555
|
+
cancelAction: dict = {
|
|
1556
|
+
'type': '',
|
|
1557
|
+
'cancels': [],
|
|
1558
|
+
}
|
|
1559
|
+
baseId = self.parse_to_numeric(market['baseId'])
|
|
1560
|
+
if clientOrderId is not None:
|
|
1561
|
+
if not isinstance(clientOrderId, list):
|
|
1562
|
+
clientOrderId = [clientOrderId]
|
|
1563
|
+
cancelAction['type'] = 'cancelByCloid'
|
|
1564
|
+
for i in range(0, len(clientOrderId)):
|
|
1565
|
+
cancelReq.append({
|
|
1566
|
+
'asset': baseId,
|
|
1567
|
+
'cloid': clientOrderId[i],
|
|
1568
|
+
})
|
|
1569
|
+
else:
|
|
1570
|
+
cancelAction['type'] = 'cancel'
|
|
1571
|
+
for i in range(0, len(ids)):
|
|
1572
|
+
cancelReq.append({
|
|
1573
|
+
'a': baseId,
|
|
1574
|
+
'o': self.parse_to_numeric(ids[i]),
|
|
1575
|
+
})
|
|
1576
|
+
cancelAction['cancels'] = cancelReq
|
|
1577
|
+
vaultAddress = self.format_vault_address(self.safe_string(params, 'vaultAddress'))
|
|
1578
|
+
signature = self.sign_l1_action(cancelAction, nonce, vaultAddress)
|
|
1579
|
+
request['action'] = cancelAction
|
|
1580
|
+
request['signature'] = signature
|
|
1581
|
+
if vaultAddress is not None:
|
|
1582
|
+
params = self.omit(params, 'vaultAddress')
|
|
1583
|
+
request['vaultAddress'] = vaultAddress
|
|
1584
|
+
response = await self.privatePostExchange(request)
|
|
1585
|
+
#
|
|
1586
|
+
# {
|
|
1587
|
+
# "status":"ok",
|
|
1588
|
+
# "response":{
|
|
1589
|
+
# "type":"cancel",
|
|
1590
|
+
# "data":{
|
|
1591
|
+
# "statuses":[
|
|
1592
|
+
# "success"
|
|
1593
|
+
# ]
|
|
1594
|
+
# }
|
|
1595
|
+
# }
|
|
1596
|
+
# }
|
|
1597
|
+
#
|
|
1598
|
+
innerResponse = self.safe_dict(response, 'response')
|
|
1599
|
+
data = self.safe_dict(innerResponse, 'data')
|
|
1600
|
+
statuses = self.safe_list(data, 'statuses')
|
|
1601
|
+
orders = []
|
|
1602
|
+
for i in range(0, len(statuses)):
|
|
1603
|
+
status = statuses[i]
|
|
1604
|
+
orders.append(self.safe_order({
|
|
1605
|
+
'info': status,
|
|
1606
|
+
'status': status,
|
|
1607
|
+
}))
|
|
1608
|
+
return orders
|
|
1609
|
+
|
|
1610
|
+
async def cancel_orders_for_symbols(self, orders: List[CancellationRequest], params={}):
|
|
1611
|
+
"""
|
|
1612
|
+
cancel multiple orders for multiple symbols
|
|
1613
|
+
|
|
1614
|
+
https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#cancel-order-s
|
|
1615
|
+
https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#cancel-order-s-by-cloid
|
|
1616
|
+
|
|
1617
|
+
: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"}]
|
|
1618
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
|
1619
|
+
:param str [params.vaultAddress]: the vault address
|
|
1620
|
+
:returns dict: an list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
|
|
1621
|
+
"""
|
|
1622
|
+
self.check_required_credentials()
|
|
1623
|
+
await self.load_markets()
|
|
1624
|
+
nonce = self.milliseconds()
|
|
1625
|
+
request: dict = {
|
|
1626
|
+
'nonce': nonce,
|
|
1627
|
+
# 'vaultAddress': vaultAddress,
|
|
1628
|
+
}
|
|
1629
|
+
cancelReq = []
|
|
1630
|
+
cancelAction: dict = {
|
|
1631
|
+
'type': '',
|
|
1632
|
+
'cancels': [],
|
|
1633
|
+
}
|
|
1634
|
+
cancelByCloid = False
|
|
1635
|
+
for i in range(0, len(orders)):
|
|
1636
|
+
order = orders[i]
|
|
1637
|
+
clientOrderId = self.safe_string(order, 'clientOrderId')
|
|
1638
|
+
if clientOrderId is not None:
|
|
1639
|
+
cancelByCloid = True
|
|
1640
|
+
id = self.safe_string(order, 'id')
|
|
1641
|
+
symbol = self.safe_string(order, 'symbol')
|
|
1642
|
+
if symbol is None:
|
|
1643
|
+
raise ArgumentsRequired(self.id + ' cancelOrdersForSymbols() requires a symbol argument in each order')
|
|
1644
|
+
if id is not None and cancelByCloid:
|
|
1645
|
+
raise BadRequest(self.id + ' cancelOrdersForSymbols() all orders must have either id or clientOrderId')
|
|
1646
|
+
assetKey = 'asset' if cancelByCloid else 'a'
|
|
1647
|
+
idKey = 'cloid' if cancelByCloid else 'o'
|
|
1648
|
+
market = self.market(symbol)
|
|
1649
|
+
cancelObj: dict = {}
|
|
1650
|
+
cancelObj[assetKey] = self.parse_to_numeric(market['baseId'])
|
|
1651
|
+
cancelObj[idKey] = clientOrderId if cancelByCloid else self.parse_to_numeric(id)
|
|
1652
|
+
cancelReq.append(cancelObj)
|
|
1653
|
+
cancelAction['type'] = 'cancelByCloid' if cancelByCloid else 'cancel'
|
|
1654
|
+
cancelAction['cancels'] = cancelReq
|
|
1655
|
+
vaultAddress = self.format_vault_address(self.safe_string(params, 'vaultAddress'))
|
|
1656
|
+
signature = self.sign_l1_action(cancelAction, nonce, vaultAddress)
|
|
1657
|
+
request['action'] = cancelAction
|
|
1658
|
+
request['signature'] = signature
|
|
1659
|
+
if vaultAddress is not None:
|
|
1660
|
+
params = self.omit(params, 'vaultAddress')
|
|
1661
|
+
request['vaultAddress'] = vaultAddress
|
|
1662
|
+
response = await self.privatePostExchange(request)
|
|
1663
|
+
#
|
|
1664
|
+
# {
|
|
1665
|
+
# "status":"ok",
|
|
1666
|
+
# "response":{
|
|
1667
|
+
# "type":"cancel",
|
|
1668
|
+
# "data":{
|
|
1669
|
+
# "statuses":[
|
|
1670
|
+
# "success"
|
|
1671
|
+
# ]
|
|
1672
|
+
# }
|
|
1673
|
+
# }
|
|
1674
|
+
# }
|
|
1675
|
+
#
|
|
1676
|
+
return response
|
|
1677
|
+
|
|
1678
|
+
async def cancel_all_orders_after(self, timeout: Int, params={}):
|
|
1679
|
+
"""
|
|
1680
|
+
dead man's switch, cancel all orders after the given timeout
|
|
1681
|
+
:param number timeout: time in milliseconds, 0 represents cancel the timer
|
|
1682
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
|
1683
|
+
:param str [params.vaultAddress]: the vault address
|
|
1684
|
+
:returns dict: the api result
|
|
1685
|
+
"""
|
|
1686
|
+
self.check_required_credentials()
|
|
1687
|
+
await self.load_markets()
|
|
1688
|
+
params = self.omit(params, ['clientOrderId', 'client_id'])
|
|
1689
|
+
nonce = self.milliseconds()
|
|
1690
|
+
request: dict = {
|
|
1691
|
+
'nonce': nonce,
|
|
1692
|
+
# 'vaultAddress': vaultAddress,
|
|
1693
|
+
}
|
|
1694
|
+
cancelAction: dict = {
|
|
1695
|
+
'type': 'scheduleCancel',
|
|
1696
|
+
'time': nonce + timeout,
|
|
1697
|
+
}
|
|
1698
|
+
vaultAddress = self.format_vault_address(self.safe_string(params, 'vaultAddress'))
|
|
1699
|
+
signature = self.sign_l1_action(cancelAction, nonce, vaultAddress)
|
|
1700
|
+
request['action'] = cancelAction
|
|
1701
|
+
request['signature'] = signature
|
|
1702
|
+
if vaultAddress is not None:
|
|
1703
|
+
params = self.omit(params, 'vaultAddress')
|
|
1704
|
+
request['vaultAddress'] = vaultAddress
|
|
1705
|
+
response = await self.privatePostExchange(request)
|
|
1706
|
+
#
|
|
1707
|
+
# {
|
|
1708
|
+
# "status":"err",
|
|
1709
|
+
# "response":"Cannot set scheduled cancel time until enough volume traded. Required: $1000000. Traded: $373.47205."
|
|
1710
|
+
# }
|
|
1711
|
+
#
|
|
1712
|
+
return response
|
|
1713
|
+
|
|
1714
|
+
def edit_orders_request(self, orders, params={}):
|
|
1715
|
+
self.check_required_credentials()
|
|
1716
|
+
hasClientOrderId = False
|
|
1717
|
+
for i in range(0, len(orders)):
|
|
1718
|
+
rawOrder = orders[i]
|
|
1719
|
+
orderParams = self.safe_dict(rawOrder, 'params', {})
|
|
1720
|
+
clientOrderId = self.safe_string_2(orderParams, 'clientOrderId', 'client_id')
|
|
1721
|
+
if clientOrderId is not None:
|
|
1722
|
+
hasClientOrderId = True
|
|
1723
|
+
if hasClientOrderId:
|
|
1724
|
+
for i in range(0, len(orders)):
|
|
1725
|
+
rawOrder = orders[i]
|
|
1726
|
+
orderParams = self.safe_dict(rawOrder, 'params', {})
|
|
1727
|
+
clientOrderId = self.safe_string_2(orderParams, 'clientOrderId', 'client_id')
|
|
1728
|
+
if clientOrderId is None:
|
|
1729
|
+
raise ArgumentsRequired(self.id + ' editOrders() all orders must have clientOrderId if at least one has a clientOrderId')
|
|
1730
|
+
params = self.omit(params, ['slippage', 'clientOrderId', 'client_id', 'slippage', 'triggerPrice', 'stopPrice', 'stopLossPrice', 'takeProfitPrice', 'timeInForce'])
|
|
1731
|
+
modifies = []
|
|
1732
|
+
for i in range(0, len(orders)):
|
|
1733
|
+
rawOrder = orders[i]
|
|
1734
|
+
id = self.safe_string(rawOrder, 'id')
|
|
1735
|
+
marketId = self.safe_string(rawOrder, 'symbol')
|
|
1736
|
+
market = self.market(marketId)
|
|
1737
|
+
symbol = market['symbol']
|
|
1738
|
+
type = self.safe_string_upper(rawOrder, 'type')
|
|
1739
|
+
isMarket = (type == 'MARKET')
|
|
1740
|
+
side = self.safe_string_upper(rawOrder, 'side')
|
|
1741
|
+
isBuy = (side == 'BUY')
|
|
1742
|
+
amount = self.safe_string(rawOrder, 'amount')
|
|
1743
|
+
price = self.safe_string(rawOrder, 'price')
|
|
1744
|
+
orderParams = self.safe_dict(rawOrder, 'params', {})
|
|
1745
|
+
defaultSlippage = self.safe_string(self.options, 'defaultSlippage')
|
|
1746
|
+
slippage = self.safe_string(orderParams, 'slippage', defaultSlippage)
|
|
1747
|
+
defaultTimeInForce = 'ioc' if (isMarket) else 'gtc'
|
|
1748
|
+
postOnly = self.safe_bool(orderParams, 'postOnly', False)
|
|
1749
|
+
if postOnly:
|
|
1750
|
+
defaultTimeInForce = 'alo'
|
|
1751
|
+
timeInForce = self.safe_string_lower(orderParams, 'timeInForce', defaultTimeInForce)
|
|
1752
|
+
timeInForce = self.capitalize(timeInForce)
|
|
1753
|
+
clientOrderId = self.safe_string_2(orderParams, 'clientOrderId', 'client_id')
|
|
1754
|
+
triggerPrice = self.safe_string_2(orderParams, 'triggerPrice', 'stopPrice')
|
|
1755
|
+
stopLossPrice = self.safe_string(orderParams, 'stopLossPrice', triggerPrice)
|
|
1756
|
+
takeProfitPrice = self.safe_string(orderParams, 'takeProfitPrice')
|
|
1757
|
+
isTrigger = (stopLossPrice or takeProfitPrice)
|
|
1758
|
+
reduceOnly = self.safe_bool(orderParams, 'reduceOnly', False)
|
|
1759
|
+
orderParams = self.omit(orderParams, ['slippage', 'timeInForce', 'triggerPrice', 'stopLossPrice', 'takeProfitPrice', 'clientOrderId', 'client_id', 'postOnly', 'reduceOnly'])
|
|
1760
|
+
px = str(price)
|
|
1761
|
+
if isMarket:
|
|
1762
|
+
px = str(Precise.string_mul(price), Precise.string_add('1', slippage)) if (isBuy) else str(Precise.string_mul(price), Precise.string_sub('1', slippage))
|
|
1763
|
+
else:
|
|
1764
|
+
px = self.price_to_precision(symbol, str(price))
|
|
1765
|
+
sz = self.amount_to_precision(symbol, amount)
|
|
1766
|
+
orderType: dict = {}
|
|
1767
|
+
if isTrigger:
|
|
1768
|
+
isTp = False
|
|
1769
|
+
if takeProfitPrice is not None:
|
|
1770
|
+
triggerPrice = self.price_to_precision(symbol, takeProfitPrice)
|
|
1771
|
+
isTp = True
|
|
1772
|
+
else:
|
|
1773
|
+
triggerPrice = self.price_to_precision(symbol, stopLossPrice)
|
|
1774
|
+
orderType['trigger'] = {
|
|
1775
|
+
'isMarket': isMarket,
|
|
1776
|
+
'triggerPx': triggerPrice,
|
|
1777
|
+
'tpsl': 'tp' if (isTp) else 'sl',
|
|
1778
|
+
}
|
|
1779
|
+
else:
|
|
1780
|
+
orderType['limit'] = {
|
|
1781
|
+
'tif': timeInForce,
|
|
1782
|
+
}
|
|
1783
|
+
if triggerPrice is None:
|
|
1784
|
+
triggerPrice = '0'
|
|
1785
|
+
orderReq: dict = {
|
|
1786
|
+
'a': self.parse_to_int(market['baseId']),
|
|
1787
|
+
'b': isBuy,
|
|
1788
|
+
'p': px,
|
|
1789
|
+
's': sz,
|
|
1790
|
+
'r': reduceOnly,
|
|
1791
|
+
't': orderType,
|
|
1792
|
+
# 'c': clientOrderId,
|
|
1793
|
+
}
|
|
1794
|
+
if clientOrderId is not None:
|
|
1795
|
+
orderReq['c'] = clientOrderId
|
|
1796
|
+
modifyReq: dict = {
|
|
1797
|
+
'oid': self.parse_to_int(id),
|
|
1798
|
+
'order': orderReq,
|
|
1799
|
+
}
|
|
1800
|
+
modifies.append(modifyReq)
|
|
1801
|
+
nonce = self.milliseconds()
|
|
1802
|
+
modifyAction: dict = {
|
|
1803
|
+
'type': 'batchModify',
|
|
1804
|
+
'modifies': modifies,
|
|
1805
|
+
}
|
|
1806
|
+
vaultAddress = self.format_vault_address(self.safe_string(params, 'vaultAddress'))
|
|
1807
|
+
signature = self.sign_l1_action(modifyAction, nonce, vaultAddress)
|
|
1808
|
+
request: dict = {
|
|
1809
|
+
'action': modifyAction,
|
|
1810
|
+
'nonce': nonce,
|
|
1811
|
+
'signature': signature,
|
|
1812
|
+
# 'vaultAddress': vaultAddress,
|
|
1813
|
+
}
|
|
1814
|
+
if vaultAddress is not None:
|
|
1815
|
+
params = self.omit(params, 'vaultAddress')
|
|
1816
|
+
request['vaultAddress'] = vaultAddress
|
|
1817
|
+
return request
|
|
1818
|
+
|
|
1819
|
+
async def edit_order(self, id: str, symbol: str, type: str, side: str, amount: Num = None, price: Num = None, params={}):
|
|
1820
|
+
"""
|
|
1821
|
+
edit a trade order
|
|
1822
|
+
|
|
1823
|
+
https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#modify-multiple-orders
|
|
1824
|
+
|
|
1825
|
+
:param str id: cancel order id
|
|
1826
|
+
:param str symbol: unified symbol of the market to create an order in
|
|
1827
|
+
:param str type: 'market' or 'limit'
|
|
1828
|
+
:param str side: 'buy' or 'sell'
|
|
1829
|
+
:param float amount: how much of currency you want to trade in units of base currency
|
|
1830
|
+
:param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
|
|
1831
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
|
1832
|
+
:param str [params.timeInForce]: 'Gtc', 'Ioc', 'Alo'
|
|
1833
|
+
:param bool [params.postOnly]: True or False whether the order is post-only
|
|
1834
|
+
:param bool [params.reduceOnly]: True or False whether the order is reduce-only
|
|
1835
|
+
:param float [params.triggerPrice]: The price at which a trigger order is triggered at
|
|
1836
|
+
:param str [params.clientOrderId]: client order id,(optional 128 bit hex string e.g. 0x1234567890abcdef1234567890abcdef)
|
|
1837
|
+
:param str [params.vaultAddress]: the vault address for order
|
|
1838
|
+
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
|
|
1839
|
+
"""
|
|
1840
|
+
await self.load_markets()
|
|
1841
|
+
if id is None:
|
|
1842
|
+
raise ArgumentsRequired(self.id + ' editOrder() requires an id argument')
|
|
1843
|
+
order, globalParams = self.parse_create_edit_order_args(id, symbol, type, side, amount, price, params)
|
|
1844
|
+
orders = await self.edit_orders([order], globalParams)
|
|
1845
|
+
return orders[0]
|
|
1846
|
+
|
|
1847
|
+
async def edit_orders(self, orders: List[OrderRequest], params={}):
|
|
1848
|
+
"""
|
|
1849
|
+
edit a list of trade orders
|
|
1850
|
+
|
|
1851
|
+
https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#modify-multiple-orders
|
|
1852
|
+
|
|
1853
|
+
: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
|
|
1854
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
|
1855
|
+
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
|
|
1856
|
+
"""
|
|
1857
|
+
await self.load_markets()
|
|
1858
|
+
request = self.edit_orders_request(orders, params)
|
|
1859
|
+
response = await self.privatePostExchange(request)
|
|
1860
|
+
#
|
|
1861
|
+
# {
|
|
1862
|
+
# "status": "ok",
|
|
1863
|
+
# "response": {
|
|
1864
|
+
# "type": "order",
|
|
1865
|
+
# "data": {
|
|
1866
|
+
# "statuses": [
|
|
1867
|
+
# {
|
|
1868
|
+
# "resting": {
|
|
1869
|
+
# "oid": 5063830287
|
|
1870
|
+
# }
|
|
1871
|
+
# }
|
|
1872
|
+
# ]
|
|
1873
|
+
# }
|
|
1874
|
+
# }
|
|
1875
|
+
# }
|
|
1876
|
+
# when the order is filled immediately
|
|
1877
|
+
# {
|
|
1878
|
+
# "status":"ok",
|
|
1879
|
+
# "response":{
|
|
1880
|
+
# "type":"order",
|
|
1881
|
+
# "data":{
|
|
1882
|
+
# "statuses":[
|
|
1883
|
+
# {
|
|
1884
|
+
# "filled":{
|
|
1885
|
+
# "totalSz":"0.1",
|
|
1886
|
+
# "avgPx":"100.84",
|
|
1887
|
+
# "oid":6195281425
|
|
1888
|
+
# }
|
|
1889
|
+
# }
|
|
1890
|
+
# ]
|
|
1891
|
+
# }
|
|
1892
|
+
# }
|
|
1893
|
+
# }
|
|
1894
|
+
#
|
|
1895
|
+
responseObject = self.safe_dict(response, 'response', {})
|
|
1896
|
+
dataObject = self.safe_dict(responseObject, 'data', {})
|
|
1897
|
+
statuses = self.safe_list(dataObject, 'statuses', [])
|
|
1898
|
+
return self.parse_orders(statuses)
|
|
1899
|
+
|
|
1900
|
+
async def fetch_funding_rate_history(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}):
|
|
1901
|
+
"""
|
|
1902
|
+
fetches historical funding rate prices
|
|
1903
|
+
|
|
1904
|
+
https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint/perpetuals#retrieve-historical-funding-rates
|
|
1905
|
+
|
|
1906
|
+
:param str symbol: unified symbol of the market to fetch the funding rate history for
|
|
1907
|
+
:param int [since]: timestamp in ms of the earliest funding rate to fetch
|
|
1908
|
+
:param int [limit]: the maximum amount of `funding rate structures <https://docs.ccxt.com/#/?id=funding-rate-history-structure>` to fetch
|
|
1909
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
|
1910
|
+
:param int [params.until]: timestamp in ms of the latest funding rate
|
|
1911
|
+
:returns dict[]: a list of `funding rate structures <https://docs.ccxt.com/#/?id=funding-rate-history-structure>`
|
|
1912
|
+
"""
|
|
1913
|
+
await self.load_markets()
|
|
1914
|
+
if symbol is None:
|
|
1915
|
+
raise ArgumentsRequired(self.id + ' fetchFundingRateHistory() requires a symbol argument')
|
|
1916
|
+
market = self.market(symbol)
|
|
1917
|
+
request: dict = {
|
|
1918
|
+
'type': 'fundingHistory',
|
|
1919
|
+
'coin': market['base'],
|
|
1920
|
+
}
|
|
1921
|
+
if since is not None:
|
|
1922
|
+
request['startTime'] = since
|
|
1923
|
+
else:
|
|
1924
|
+
maxLimit = 500 if (limit is None) else limit
|
|
1925
|
+
request['startTime'] = self.milliseconds() - maxLimit * 60 * 60 * 1000
|
|
1926
|
+
until = self.safe_integer(params, 'until')
|
|
1927
|
+
params = self.omit(params, 'until')
|
|
1928
|
+
if until is not None:
|
|
1929
|
+
request['endTime'] = until
|
|
1930
|
+
response = await self.publicPostInfo(self.extend(request, params))
|
|
1931
|
+
#
|
|
1932
|
+
# [
|
|
1933
|
+
# {
|
|
1934
|
+
# "coin": "ETH",
|
|
1935
|
+
# "fundingRate": "0.0000125",
|
|
1936
|
+
# "premium": "0.00057962",
|
|
1937
|
+
# "time": 1704290400031
|
|
1938
|
+
# }
|
|
1939
|
+
# ]
|
|
1940
|
+
#
|
|
1941
|
+
result = []
|
|
1942
|
+
for i in range(0, len(response)):
|
|
1943
|
+
entry = response[i]
|
|
1944
|
+
timestamp = self.safe_integer(entry, 'time')
|
|
1945
|
+
result.append({
|
|
1946
|
+
'info': entry,
|
|
1947
|
+
'symbol': self.safe_symbol(None, market),
|
|
1948
|
+
'fundingRate': self.safe_number(entry, 'fundingRate'),
|
|
1949
|
+
'timestamp': timestamp,
|
|
1950
|
+
'datetime': self.iso8601(timestamp),
|
|
1951
|
+
})
|
|
1952
|
+
sorted = self.sort_by(result, 'timestamp')
|
|
1953
|
+
return self.filter_by_symbol_since_limit(sorted, symbol, since, limit)
|
|
1954
|
+
|
|
1955
|
+
async def fetch_open_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Order]:
|
|
1956
|
+
"""
|
|
1957
|
+
fetch all unfilled currently open orders
|
|
1958
|
+
|
|
1959
|
+
https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint#retrieve-a-users-open-orders
|
|
1960
|
+
|
|
1961
|
+
:param str symbol: unified market symbol
|
|
1962
|
+
:param int [since]: the earliest time in ms to fetch open orders for
|
|
1963
|
+
:param int [limit]: the maximum number of open orders structures to retrieve
|
|
1964
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
|
1965
|
+
:param str [params.user]: user address, will default to self.walletAddress if not provided
|
|
1966
|
+
:param str [params.method]: 'openOrders' or 'frontendOpenOrders' default is 'frontendOpenOrders'
|
|
1967
|
+
:returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
|
|
1968
|
+
"""
|
|
1969
|
+
userAddress = None
|
|
1970
|
+
userAddress, params = self.handle_public_address('fetchOpenOrders', params)
|
|
1971
|
+
method = None
|
|
1972
|
+
method, params = self.handle_option_and_params(params, 'fetchOpenOrders', 'method', 'frontendOpenOrders')
|
|
1973
|
+
await self.load_markets()
|
|
1974
|
+
market = self.safe_market(symbol)
|
|
1975
|
+
request: dict = {
|
|
1976
|
+
'type': method,
|
|
1977
|
+
'user': userAddress,
|
|
1978
|
+
}
|
|
1979
|
+
response = await self.publicPostInfo(self.extend(request, params))
|
|
1980
|
+
#
|
|
1981
|
+
# [
|
|
1982
|
+
# {
|
|
1983
|
+
# "coin": "ETH",
|
|
1984
|
+
# "limitPx": "2000.0",
|
|
1985
|
+
# "oid": 3991946565,
|
|
1986
|
+
# "origSz": "0.1",
|
|
1987
|
+
# "side": "B",
|
|
1988
|
+
# "sz": "0.1",
|
|
1989
|
+
# "timestamp": 1704346468838
|
|
1990
|
+
# }
|
|
1991
|
+
# ]
|
|
1992
|
+
#
|
|
1993
|
+
orderWithStatus = []
|
|
1994
|
+
for i in range(0, len(response)):
|
|
1995
|
+
order = response[i]
|
|
1996
|
+
extendOrder = {}
|
|
1997
|
+
if self.safe_string(order, 'status') is None:
|
|
1998
|
+
extendOrder['ccxtStatus'] = 'open'
|
|
1999
|
+
orderWithStatus.append(self.extend(order, extendOrder))
|
|
2000
|
+
return self.parse_orders(orderWithStatus, market, since, limit)
|
|
2001
|
+
|
|
2002
|
+
async def fetch_closed_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Order]:
|
|
2003
|
+
"""
|
|
2004
|
+
fetch all unfilled currently closed orders
|
|
2005
|
+
:param str symbol: unified market symbol
|
|
2006
|
+
:param int [since]: the earliest time in ms to fetch open orders for
|
|
2007
|
+
:param int [limit]: the maximum number of open orders structures to retrieve
|
|
2008
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
|
2009
|
+
:param str [params.user]: user address, will default to self.walletAddress if not provided
|
|
2010
|
+
:returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
|
|
2011
|
+
"""
|
|
2012
|
+
await self.load_markets()
|
|
2013
|
+
orders = await self.fetch_orders(symbol, None, None, params) # don't filter here because we don't want to catch open orders
|
|
2014
|
+
closedOrders = self.filter_by_array(orders, 'status', ['closed'], False)
|
|
2015
|
+
return self.filter_by_symbol_since_limit(closedOrders, symbol, since, limit)
|
|
2016
|
+
|
|
2017
|
+
async def fetch_canceled_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Order]:
|
|
2018
|
+
"""
|
|
2019
|
+
fetch all canceled orders
|
|
2020
|
+
:param str symbol: unified market symbol
|
|
2021
|
+
:param int [since]: the earliest time in ms to fetch open orders for
|
|
2022
|
+
:param int [limit]: the maximum number of open orders structures to retrieve
|
|
2023
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
|
2024
|
+
:param str [params.user]: user address, will default to self.walletAddress if not provided
|
|
2025
|
+
:returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
|
|
2026
|
+
"""
|
|
2027
|
+
await self.load_markets()
|
|
2028
|
+
orders = await self.fetch_orders(symbol, None, None, params) # don't filter here because we don't want to catch open orders
|
|
2029
|
+
closedOrders = self.filter_by_array(orders, 'status', ['canceled'], False)
|
|
2030
|
+
return self.filter_by_symbol_since_limit(closedOrders, symbol, since, limit)
|
|
2031
|
+
|
|
2032
|
+
async def fetch_canceled_and_closed_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Order]:
|
|
2033
|
+
"""
|
|
2034
|
+
fetch all closed and canceled orders
|
|
2035
|
+
:param str symbol: unified market symbol
|
|
2036
|
+
:param int [since]: the earliest time in ms to fetch open orders for
|
|
2037
|
+
:param int [limit]: the maximum number of open orders structures to retrieve
|
|
2038
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
|
2039
|
+
:param str [params.user]: user address, will default to self.walletAddress if not provided
|
|
2040
|
+
:returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
|
|
2041
|
+
"""
|
|
2042
|
+
await self.load_markets()
|
|
2043
|
+
orders = await self.fetch_orders(symbol, None, None, params) # don't filter here because we don't want to catch open orders
|
|
2044
|
+
closedOrders = self.filter_by_array(orders, 'status', ['canceled', 'closed', 'rejected'], False)
|
|
2045
|
+
return self.filter_by_symbol_since_limit(closedOrders, symbol, since, limit)
|
|
2046
|
+
|
|
2047
|
+
async def fetch_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Order]:
|
|
2048
|
+
"""
|
|
2049
|
+
fetch all orders
|
|
2050
|
+
:param str symbol: unified market symbol
|
|
2051
|
+
:param int [since]: the earliest time in ms to fetch open orders for
|
|
2052
|
+
:param int [limit]: the maximum number of open orders structures to retrieve
|
|
2053
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
|
2054
|
+
:param str [params.user]: user address, will default to self.walletAddress if not provided
|
|
2055
|
+
:returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
|
|
2056
|
+
"""
|
|
2057
|
+
userAddress = None
|
|
2058
|
+
userAddress, params = self.handle_public_address('fetchOrders', params)
|
|
2059
|
+
await self.load_markets()
|
|
2060
|
+
market = self.safe_market(symbol)
|
|
2061
|
+
request: dict = {
|
|
2062
|
+
'type': 'historicalOrders',
|
|
2063
|
+
'user': userAddress,
|
|
2064
|
+
}
|
|
2065
|
+
response = await self.publicPostInfo(self.extend(request, params))
|
|
2066
|
+
#
|
|
2067
|
+
# [
|
|
2068
|
+
# {
|
|
2069
|
+
# "coin": "ETH",
|
|
2070
|
+
# "limitPx": "2000.0",
|
|
2071
|
+
# "oid": 3991946565,
|
|
2072
|
+
# "origSz": "0.1",
|
|
2073
|
+
# "side": "B",
|
|
2074
|
+
# "sz": "0.1",
|
|
2075
|
+
# "timestamp": 1704346468838
|
|
2076
|
+
# }
|
|
2077
|
+
# ]
|
|
2078
|
+
#
|
|
2079
|
+
return self.parse_orders(response, market, since, limit)
|
|
2080
|
+
|
|
2081
|
+
async def fetch_order(self, id: str, symbol: Str = None, params={}):
|
|
2082
|
+
"""
|
|
2083
|
+
fetches information on an order made by the user
|
|
2084
|
+
|
|
2085
|
+
https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint#query-order-status-by-oid-or-cloid
|
|
2086
|
+
|
|
2087
|
+
:param str id: order id
|
|
2088
|
+
:param str symbol: unified symbol of the market the order was made in
|
|
2089
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
|
2090
|
+
:param str [params.user]: user address, will default to self.walletAddress if not provided
|
|
2091
|
+
:returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
|
|
2092
|
+
"""
|
|
2093
|
+
userAddress = None
|
|
2094
|
+
userAddress, params = self.handle_public_address('fetchOrder', params)
|
|
2095
|
+
await self.load_markets()
|
|
2096
|
+
market = self.safe_market(symbol)
|
|
2097
|
+
isClientOrderId = len(id) >= 34
|
|
2098
|
+
request: dict = {
|
|
2099
|
+
'type': 'orderStatus',
|
|
2100
|
+
'oid': id if isClientOrderId else self.parse_to_numeric(id),
|
|
2101
|
+
'user': userAddress,
|
|
2102
|
+
}
|
|
2103
|
+
response = await self.publicPostInfo(self.extend(request, params))
|
|
2104
|
+
#
|
|
2105
|
+
# {
|
|
2106
|
+
# "order": {
|
|
2107
|
+
# "order": {
|
|
2108
|
+
# "children": [],
|
|
2109
|
+
# "cloid": null,
|
|
2110
|
+
# "coin": "ETH",
|
|
2111
|
+
# "isPositionTpsl": False,
|
|
2112
|
+
# "isTrigger": False,
|
|
2113
|
+
# "limitPx": "2000.0",
|
|
2114
|
+
# "oid": "3991946565",
|
|
2115
|
+
# "orderType": "Limit",
|
|
2116
|
+
# "origSz": "0.1",
|
|
2117
|
+
# "reduceOnly": False,
|
|
2118
|
+
# "side": "B",
|
|
2119
|
+
# "sz": "0.1",
|
|
2120
|
+
# "tif": "Gtc",
|
|
2121
|
+
# "timestamp": "1704346468838",
|
|
2122
|
+
# "triggerCondition": "N/A",
|
|
2123
|
+
# "triggerPx": "0.0"
|
|
2124
|
+
# },
|
|
2125
|
+
# "status": "open",
|
|
2126
|
+
# "statusTimestamp": "1704346468838"
|
|
2127
|
+
# },
|
|
2128
|
+
# "status": "order"
|
|
2129
|
+
# }
|
|
2130
|
+
#
|
|
2131
|
+
data = self.safe_dict(response, 'order')
|
|
2132
|
+
return self.parse_order(data, market)
|
|
2133
|
+
|
|
2134
|
+
def parse_order(self, order: dict, market: Market = None) -> Order:
|
|
2135
|
+
#
|
|
2136
|
+
# fetchOpenOrders
|
|
2137
|
+
#
|
|
2138
|
+
# {
|
|
2139
|
+
# "coin": "ETH",
|
|
2140
|
+
# "limitPx": "2000.0",
|
|
2141
|
+
# "oid": 3991946565,
|
|
2142
|
+
# "origSz": "0.1",
|
|
2143
|
+
# "side": "B",
|
|
2144
|
+
# "sz": "0.1",
|
|
2145
|
+
# "timestamp": 1704346468838
|
|
2146
|
+
# }
|
|
2147
|
+
# fetchClosedorders
|
|
2148
|
+
# {
|
|
2149
|
+
# "cloid": null,
|
|
2150
|
+
# "closedPnl": "0.0",
|
|
2151
|
+
# "coin": "SOL",
|
|
2152
|
+
# "crossed": True,
|
|
2153
|
+
# "dir": "Open Long",
|
|
2154
|
+
# "fee": "0.003879",
|
|
2155
|
+
# "hash": "0x4a2647998682b7f07bc5040ab531e1011400f9a51bfa0346a0b41ebe510e8875",
|
|
2156
|
+
# "liquidationMarkPx": null,
|
|
2157
|
+
# "oid": "6463280784",
|
|
2158
|
+
# "px": "110.83",
|
|
2159
|
+
# "side": "B",
|
|
2160
|
+
# "startPosition": "1.64",
|
|
2161
|
+
# "sz": "0.1",
|
|
2162
|
+
# "tid": "232174667018988",
|
|
2163
|
+
# "time": "1709142268394"
|
|
2164
|
+
# }
|
|
2165
|
+
#
|
|
2166
|
+
# fetchOrder
|
|
2167
|
+
#
|
|
2168
|
+
# {
|
|
2169
|
+
# "order": {
|
|
2170
|
+
# "children": [],
|
|
2171
|
+
# "cloid": null,
|
|
2172
|
+
# "coin": "ETH",
|
|
2173
|
+
# "isPositionTpsl": False,
|
|
2174
|
+
# "isTrigger": False,
|
|
2175
|
+
# "limitPx": "2000.0",
|
|
2176
|
+
# "oid": "3991946565",
|
|
2177
|
+
# "orderType": "Limit",
|
|
2178
|
+
# "origSz": "0.1",
|
|
2179
|
+
# "reduceOnly": False,
|
|
2180
|
+
# "side": "B",
|
|
2181
|
+
# "sz": "0.1",
|
|
2182
|
+
# "tif": "Gtc",
|
|
2183
|
+
# "timestamp": "1704346468838",
|
|
2184
|
+
# "triggerCondition": "N/A",
|
|
2185
|
+
# "triggerPx": "0.0"
|
|
2186
|
+
# },
|
|
2187
|
+
# "status": "open",
|
|
2188
|
+
# "statusTimestamp": "1704346468838"
|
|
2189
|
+
# }
|
|
2190
|
+
#
|
|
2191
|
+
# createOrder
|
|
2192
|
+
#
|
|
2193
|
+
# {
|
|
2194
|
+
# "resting": {
|
|
2195
|
+
# "oid": 5063830287
|
|
2196
|
+
# }
|
|
2197
|
+
# }
|
|
2198
|
+
#
|
|
2199
|
+
# {
|
|
2200
|
+
# "filled":{
|
|
2201
|
+
# "totalSz":"0.1",
|
|
2202
|
+
# "avgPx":"100.84",
|
|
2203
|
+
# "oid":6195281425
|
|
2204
|
+
# }
|
|
2205
|
+
# }
|
|
2206
|
+
# frontendOrder
|
|
2207
|
+
# {
|
|
2208
|
+
# "children": [],
|
|
2209
|
+
# "cloid": null,
|
|
2210
|
+
# "coin": "BLUR",
|
|
2211
|
+
# "isPositionTpsl": False,
|
|
2212
|
+
# "isTrigger": True,
|
|
2213
|
+
# "limitPx": "0.5",
|
|
2214
|
+
# "oid": 8670487141,
|
|
2215
|
+
# "orderType": "Stop Limit",
|
|
2216
|
+
# "origSz": "20.0",
|
|
2217
|
+
# "reduceOnly": False,
|
|
2218
|
+
# "side": "B",
|
|
2219
|
+
# "sz": "20.0",
|
|
2220
|
+
# "tif": null,
|
|
2221
|
+
# "timestamp": 1715523663687,
|
|
2222
|
+
# "triggerCondition": "Price above 0.6",
|
|
2223
|
+
# "triggerPx": "0.6"
|
|
2224
|
+
# }
|
|
2225
|
+
#
|
|
2226
|
+
entry = self.safe_dict_n(order, ['order', 'resting', 'filled'])
|
|
2227
|
+
if entry is None:
|
|
2228
|
+
entry = order
|
|
2229
|
+
coin = self.safe_string(entry, 'coin')
|
|
2230
|
+
marketId = None
|
|
2231
|
+
if coin is not None:
|
|
2232
|
+
marketId = self.coin_to_market_id(coin)
|
|
2233
|
+
if self.safe_string(entry, 'id') is None:
|
|
2234
|
+
market = self.safe_market(marketId, None)
|
|
2235
|
+
else:
|
|
2236
|
+
market = self.safe_market(marketId, market)
|
|
2237
|
+
symbol = market['symbol']
|
|
2238
|
+
timestamp = self.safe_integer(entry, 'timestamp')
|
|
2239
|
+
status = self.safe_string_2(order, 'status', 'ccxtStatus')
|
|
2240
|
+
order = self.omit(order, ['ccxtStatus'])
|
|
2241
|
+
side = self.safe_string(entry, 'side')
|
|
2242
|
+
if side is not None:
|
|
2243
|
+
side = 'sell' if (side == 'A') else 'buy'
|
|
2244
|
+
totalAmount = self.safe_string_2(entry, 'origSz', 'totalSz')
|
|
2245
|
+
remaining = self.safe_string(entry, 'sz')
|
|
2246
|
+
return self.safe_order({
|
|
2247
|
+
'info': order,
|
|
2248
|
+
'id': self.safe_string(entry, 'oid'),
|
|
2249
|
+
'clientOrderId': self.safe_string(entry, 'cloid'),
|
|
2250
|
+
'timestamp': timestamp,
|
|
2251
|
+
'datetime': self.iso8601(timestamp),
|
|
2252
|
+
'lastTradeTimestamp': None,
|
|
2253
|
+
'lastUpdateTimestamp': self.safe_integer(order, 'statusTimestamp'),
|
|
2254
|
+
'symbol': symbol,
|
|
2255
|
+
'type': self.parse_order_type(self.safe_string_lower(entry, 'orderType')),
|
|
2256
|
+
'timeInForce': self.safe_string_upper(entry, 'tif'),
|
|
2257
|
+
'postOnly': None,
|
|
2258
|
+
'reduceOnly': self.safe_bool(entry, 'reduceOnly'),
|
|
2259
|
+
'side': side,
|
|
2260
|
+
'price': self.safe_string(entry, 'limitPx'),
|
|
2261
|
+
'triggerPrice': self.safe_number(entry, 'triggerPx') if self.safe_bool(entry, 'isTrigger') else None,
|
|
2262
|
+
'amount': totalAmount,
|
|
2263
|
+
'cost': None,
|
|
2264
|
+
'average': self.safe_string(entry, 'avgPx'),
|
|
2265
|
+
'filled': Precise.string_sub(totalAmount, remaining),
|
|
2266
|
+
'remaining': remaining,
|
|
2267
|
+
'status': self.parse_order_status(status),
|
|
2268
|
+
'fee': None,
|
|
2269
|
+
'trades': None,
|
|
2270
|
+
}, market)
|
|
2271
|
+
|
|
2272
|
+
def parse_order_status(self, status: Str):
|
|
2273
|
+
statuses: dict = {
|
|
2274
|
+
'triggered': 'open',
|
|
2275
|
+
'filled': 'closed',
|
|
2276
|
+
'open': 'open',
|
|
2277
|
+
'canceled': 'canceled',
|
|
2278
|
+
'rejected': 'rejected',
|
|
2279
|
+
'marginCanceled': 'canceled',
|
|
2280
|
+
}
|
|
2281
|
+
return self.safe_string(statuses, status, status)
|
|
2282
|
+
|
|
2283
|
+
def parse_order_type(self, status):
|
|
2284
|
+
statuses: dict = {
|
|
2285
|
+
'stop limit': 'limit',
|
|
2286
|
+
'stop market': 'market',
|
|
2287
|
+
}
|
|
2288
|
+
return self.safe_string(statuses, status, status)
|
|
2289
|
+
|
|
2290
|
+
async def fetch_my_trades(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}):
|
|
2291
|
+
"""
|
|
2292
|
+
fetch all trades made by the user
|
|
2293
|
+
|
|
2294
|
+
https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint#retrieve-a-users-fills
|
|
2295
|
+
https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint#retrieve-a-users-fills-by-time
|
|
2296
|
+
|
|
2297
|
+
:param str symbol: unified market symbol
|
|
2298
|
+
:param int [since]: the earliest time in ms to fetch trades for
|
|
2299
|
+
:param int [limit]: the maximum number of trades structures to retrieve
|
|
2300
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
|
2301
|
+
:param int [params.until]: timestamp in ms of the latest trade
|
|
2302
|
+
:returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
|
|
2303
|
+
"""
|
|
2304
|
+
userAddress = None
|
|
2305
|
+
userAddress, params = self.handle_public_address('fetchMyTrades', params)
|
|
2306
|
+
await self.load_markets()
|
|
2307
|
+
market = self.safe_market(symbol)
|
|
2308
|
+
request: dict = {
|
|
2309
|
+
'user': userAddress,
|
|
2310
|
+
}
|
|
2311
|
+
if since is not None:
|
|
2312
|
+
request['type'] = 'userFillsByTime'
|
|
2313
|
+
request['startTime'] = since
|
|
2314
|
+
else:
|
|
2315
|
+
request['type'] = 'userFills'
|
|
2316
|
+
until = self.safe_integer(params, 'until')
|
|
2317
|
+
params = self.omit(params, 'until')
|
|
2318
|
+
if until is not None:
|
|
2319
|
+
request['endTime'] = until
|
|
2320
|
+
response = await self.publicPostInfo(self.extend(request, params))
|
|
2321
|
+
#
|
|
2322
|
+
# [
|
|
2323
|
+
# {
|
|
2324
|
+
# "closedPnl": "0.19343",
|
|
2325
|
+
# "coin": "ETH",
|
|
2326
|
+
# "crossed": True,
|
|
2327
|
+
# "dir": "Close Long",
|
|
2328
|
+
# "fee": "0.050062",
|
|
2329
|
+
# "feeToken": "USDC",
|
|
2330
|
+
# "hash": "0x09d77c96791e98b5775a04092584ab010d009445119c71e4005c0d634ea322bc",
|
|
2331
|
+
# "liquidationMarkPx": null,
|
|
2332
|
+
# "oid": 3929354691,
|
|
2333
|
+
# "px": "2381.1",
|
|
2334
|
+
# "side": "A",
|
|
2335
|
+
# "startPosition": "0.0841",
|
|
2336
|
+
# "sz": "0.0841",
|
|
2337
|
+
# "tid": 128423918764978,
|
|
2338
|
+
# "time": 1704262888911
|
|
2339
|
+
# }
|
|
2340
|
+
# ]
|
|
2341
|
+
#
|
|
2342
|
+
return self.parse_trades(response, market, since, limit)
|
|
2343
|
+
|
|
2344
|
+
def parse_trade(self, trade: dict, market: Market = None) -> Trade:
|
|
2345
|
+
#
|
|
2346
|
+
# {
|
|
2347
|
+
# "closedPnl": "0.19343",
|
|
2348
|
+
# "coin": "ETH",
|
|
2349
|
+
# "crossed": True,
|
|
2350
|
+
# "dir": "Close Long",
|
|
2351
|
+
# "fee": "0.050062",
|
|
2352
|
+
# "hash": "0x09d77c96791e98b5775a04092584ab010d009445119c71e4005c0d634ea322bc",
|
|
2353
|
+
# "liquidationMarkPx": null,
|
|
2354
|
+
# "oid": 3929354691,
|
|
2355
|
+
# "px": "2381.1",
|
|
2356
|
+
# "side": "A",
|
|
2357
|
+
# "startPosition": "0.0841",
|
|
2358
|
+
# "sz": "0.0841",
|
|
2359
|
+
# "tid": 128423918764978,
|
|
2360
|
+
# "time": 1704262888911
|
|
2361
|
+
# }
|
|
2362
|
+
#
|
|
2363
|
+
timestamp = self.safe_integer(trade, 'time')
|
|
2364
|
+
price = self.safe_string(trade, 'px')
|
|
2365
|
+
amount = self.safe_string(trade, 'sz')
|
|
2366
|
+
coin = self.safe_string(trade, 'coin')
|
|
2367
|
+
marketId = self.coin_to_market_id(coin)
|
|
2368
|
+
market = self.safe_market(marketId, None)
|
|
2369
|
+
symbol = market['symbol']
|
|
2370
|
+
id = self.safe_string(trade, 'tid')
|
|
2371
|
+
side = self.safe_string(trade, 'side')
|
|
2372
|
+
if side is not None:
|
|
2373
|
+
side = 'sell' if (side == 'A') else 'buy'
|
|
2374
|
+
fee = self.safe_string(trade, 'fee')
|
|
2375
|
+
return self.safe_trade({
|
|
2376
|
+
'info': trade,
|
|
2377
|
+
'timestamp': timestamp,
|
|
2378
|
+
'datetime': self.iso8601(timestamp),
|
|
2379
|
+
'symbol': symbol,
|
|
2380
|
+
'id': id,
|
|
2381
|
+
'order': self.safe_string(trade, 'oid'),
|
|
2382
|
+
'type': None,
|
|
2383
|
+
'side': side,
|
|
2384
|
+
'takerOrMaker': None,
|
|
2385
|
+
'price': price,
|
|
2386
|
+
'amount': amount,
|
|
2387
|
+
'cost': None,
|
|
2388
|
+
'fee': {
|
|
2389
|
+
'cost': fee,
|
|
2390
|
+
'currency': self.safe_string(trade, 'feeToken'),
|
|
2391
|
+
'rate': None,
|
|
2392
|
+
},
|
|
2393
|
+
}, market)
|
|
2394
|
+
|
|
2395
|
+
async def fetch_position(self, symbol: str, params={}):
|
|
2396
|
+
"""
|
|
2397
|
+
fetch data on an open position
|
|
2398
|
+
|
|
2399
|
+
https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint/perpetuals#retrieve-users-perpetuals-account-summary
|
|
2400
|
+
|
|
2401
|
+
:param str symbol: unified market symbol of the market the position is held in
|
|
2402
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
|
2403
|
+
:param str [params.user]: user address, will default to self.walletAddress if not provided
|
|
2404
|
+
:returns dict: a `position structure <https://docs.ccxt.com/#/?id=position-structure>`
|
|
2405
|
+
"""
|
|
2406
|
+
positions = await self.fetch_positions([symbol], params)
|
|
2407
|
+
return self.safe_dict(positions, 0, {})
|
|
2408
|
+
|
|
2409
|
+
async def fetch_positions(self, symbols: Strings = None, params={}):
|
|
2410
|
+
"""
|
|
2411
|
+
fetch all open positions
|
|
2412
|
+
|
|
2413
|
+
https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint/perpetuals#retrieve-users-perpetuals-account-summary
|
|
2414
|
+
|
|
2415
|
+
:param str[] [symbols]: list of unified market symbols
|
|
2416
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
|
2417
|
+
:param str [params.user]: user address, will default to self.walletAddress if not provided
|
|
2418
|
+
:returns dict[]: a list of `position structure <https://docs.ccxt.com/#/?id=position-structure>`
|
|
2419
|
+
"""
|
|
2420
|
+
await self.load_markets()
|
|
2421
|
+
userAddress = None
|
|
2422
|
+
userAddress, params = self.handle_public_address('fetchPositions', params)
|
|
2423
|
+
symbols = self.market_symbols(symbols)
|
|
2424
|
+
request: dict = {
|
|
2425
|
+
'type': 'clearinghouseState',
|
|
2426
|
+
'user': userAddress,
|
|
2427
|
+
}
|
|
2428
|
+
response = await self.publicPostInfo(self.extend(request, params))
|
|
2429
|
+
#
|
|
2430
|
+
# {
|
|
2431
|
+
# "assetPositions": [
|
|
2432
|
+
# {
|
|
2433
|
+
# "position": {
|
|
2434
|
+
# "coin": "ETH",
|
|
2435
|
+
# "cumFunding": {
|
|
2436
|
+
# "allTime": "0.0",
|
|
2437
|
+
# "sinceChange": "0.0",
|
|
2438
|
+
# "sinceOpen": "0.0"
|
|
2439
|
+
# },
|
|
2440
|
+
# "entryPx": "2213.9",
|
|
2441
|
+
# "leverage": {
|
|
2442
|
+
# "rawUsd": "-475.23904",
|
|
2443
|
+
# "type": "isolated",
|
|
2444
|
+
# "value": "20"
|
|
2445
|
+
# },
|
|
2446
|
+
# "liquidationPx": "2125.00856238",
|
|
2447
|
+
# "marginUsed": "24.88097",
|
|
2448
|
+
# "maxLeverage": "50",
|
|
2449
|
+
# "positionValue": "500.12001",
|
|
2450
|
+
# "returnOnEquity": "0.0",
|
|
2451
|
+
# "szi": "0.2259",
|
|
2452
|
+
# "unrealizedPnl": "0.0"
|
|
2453
|
+
# },
|
|
2454
|
+
# "type": "oneWay"
|
|
2455
|
+
# }
|
|
2456
|
+
# ],
|
|
2457
|
+
# "crossMaintenanceMarginUsed": "0.0",
|
|
2458
|
+
# "crossMarginSummary": {
|
|
2459
|
+
# "accountValue": "100.0",
|
|
2460
|
+
# "totalMarginUsed": "0.0",
|
|
2461
|
+
# "totalNtlPos": "0.0",
|
|
2462
|
+
# "totalRawUsd": "100.0"
|
|
2463
|
+
# },
|
|
2464
|
+
# "marginSummary": {
|
|
2465
|
+
# "accountValue": "100.0",
|
|
2466
|
+
# "totalMarginUsed": "0.0",
|
|
2467
|
+
# "totalNtlPos": "0.0",
|
|
2468
|
+
# "totalRawUsd": "100.0"
|
|
2469
|
+
# },
|
|
2470
|
+
# "time": "1704261007014",
|
|
2471
|
+
# "withdrawable": "100.0"
|
|
2472
|
+
# }
|
|
2473
|
+
#
|
|
2474
|
+
data = self.safe_list(response, 'assetPositions', [])
|
|
2475
|
+
result = []
|
|
2476
|
+
for i in range(0, len(data)):
|
|
2477
|
+
result.append(self.parse_position(data[i], None))
|
|
2478
|
+
return self.filter_by_array_positions(result, 'symbol', symbols, False)
|
|
2479
|
+
|
|
2480
|
+
def parse_position(self, position: dict, market: Market = None):
|
|
2481
|
+
#
|
|
2482
|
+
# {
|
|
2483
|
+
# "position": {
|
|
2484
|
+
# "coin": "ETH",
|
|
2485
|
+
# "cumFunding": {
|
|
2486
|
+
# "allTime": "0.0",
|
|
2487
|
+
# "sinceChange": "0.0",
|
|
2488
|
+
# "sinceOpen": "0.0"
|
|
2489
|
+
# },
|
|
2490
|
+
# "entryPx": "2213.9",
|
|
2491
|
+
# "leverage": {
|
|
2492
|
+
# "rawUsd": "-475.23904",
|
|
2493
|
+
# "type": "isolated",
|
|
2494
|
+
# "value": "20"
|
|
2495
|
+
# },
|
|
2496
|
+
# "liquidationPx": "2125.00856238",
|
|
2497
|
+
# "marginUsed": "24.88097",
|
|
2498
|
+
# "maxLeverage": "50",
|
|
2499
|
+
# "positionValue": "500.12001",
|
|
2500
|
+
# "returnOnEquity": "0.0",
|
|
2501
|
+
# "szi": "0.2259",
|
|
2502
|
+
# "unrealizedPnl": "0.0"
|
|
2503
|
+
# },
|
|
2504
|
+
# "type": "oneWay"
|
|
2505
|
+
# }
|
|
2506
|
+
#
|
|
2507
|
+
entry = self.safe_dict(position, 'position', {})
|
|
2508
|
+
coin = self.safe_string(entry, 'coin')
|
|
2509
|
+
marketId = self.coin_to_market_id(coin)
|
|
2510
|
+
market = self.safe_market(marketId, None)
|
|
2511
|
+
symbol = market['symbol']
|
|
2512
|
+
leverage = self.safe_dict(entry, 'leverage', {})
|
|
2513
|
+
marginMode = self.safe_string(leverage, 'type')
|
|
2514
|
+
isIsolated = (marginMode == 'isolated')
|
|
2515
|
+
rawSize = self.safe_string(entry, 'szi')
|
|
2516
|
+
size = rawSize
|
|
2517
|
+
side = None
|
|
2518
|
+
if size is not None:
|
|
2519
|
+
side = 'long' if Precise.string_gt(rawSize, '0') else 'short'
|
|
2520
|
+
size = Precise.string_abs(size)
|
|
2521
|
+
rawUnrealizedPnl = self.safe_string(entry, 'unrealizedPnl')
|
|
2522
|
+
absRawUnrealizedPnl = Precise.string_abs(rawUnrealizedPnl)
|
|
2523
|
+
initialMargin = self.safe_string(entry, 'marginUsed')
|
|
2524
|
+
percentage = Precise.string_mul(Precise.string_div(absRawUnrealizedPnl, initialMargin), '100')
|
|
2525
|
+
return self.safe_position({
|
|
2526
|
+
'info': position,
|
|
2527
|
+
'id': None,
|
|
2528
|
+
'symbol': symbol,
|
|
2529
|
+
'timestamp': None,
|
|
2530
|
+
'datetime': None,
|
|
2531
|
+
'isolated': isIsolated,
|
|
2532
|
+
'hedged': None,
|
|
2533
|
+
'side': side,
|
|
2534
|
+
'contracts': self.parse_number(size),
|
|
2535
|
+
'contractSize': None,
|
|
2536
|
+
'entryPrice': self.safe_number(entry, 'entryPx'),
|
|
2537
|
+
'markPrice': None,
|
|
2538
|
+
'notional': self.safe_number(entry, 'positionValue'),
|
|
2539
|
+
'leverage': self.safe_number(leverage, 'value'),
|
|
2540
|
+
'collateral': self.safe_number(entry, 'marginUsed'),
|
|
2541
|
+
'initialMargin': self.parse_number(initialMargin),
|
|
2542
|
+
'maintenanceMargin': None,
|
|
2543
|
+
'initialMarginPercentage': None,
|
|
2544
|
+
'maintenanceMarginPercentage': None,
|
|
2545
|
+
'unrealizedPnl': self.parse_number(rawUnrealizedPnl),
|
|
2546
|
+
'liquidationPrice': self.safe_number(entry, 'liquidationPx'),
|
|
2547
|
+
'marginMode': marginMode,
|
|
2548
|
+
'percentage': self.parse_number(percentage),
|
|
2549
|
+
})
|
|
2550
|
+
|
|
2551
|
+
async def set_margin_mode(self, marginMode: str, symbol: Str = None, params={}):
|
|
2552
|
+
"""
|
|
2553
|
+
set margin mode(symbol)
|
|
2554
|
+
:param str marginMode: margin mode must be either [isolated, cross]
|
|
2555
|
+
:param str symbol: unified market symbol of the market the position is held in, default is None
|
|
2556
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
|
2557
|
+
:param str [params.leverage]: the rate of leverage, is required if setting trade mode(symbol)
|
|
2558
|
+
:returns dict: response from the exchange
|
|
2559
|
+
"""
|
|
2560
|
+
if symbol is None:
|
|
2561
|
+
raise ArgumentsRequired(self.id + ' setMarginMode() requires a symbol argument')
|
|
2562
|
+
await self.load_markets()
|
|
2563
|
+
market = self.market(symbol)
|
|
2564
|
+
leverage = self.safe_integer(params, 'leverage')
|
|
2565
|
+
if leverage is None:
|
|
2566
|
+
raise ArgumentsRequired(self.id + ' setMarginMode() requires a leverage parameter')
|
|
2567
|
+
asset = self.parse_to_int(market['baseId'])
|
|
2568
|
+
isCross = (marginMode == 'cross')
|
|
2569
|
+
nonce = self.milliseconds()
|
|
2570
|
+
params = self.omit(params, ['leverage'])
|
|
2571
|
+
updateAction: dict = {
|
|
2572
|
+
'type': 'updateLeverage',
|
|
2573
|
+
'asset': asset,
|
|
2574
|
+
'isCross': isCross,
|
|
2575
|
+
'leverage': leverage,
|
|
2576
|
+
}
|
|
2577
|
+
vaultAddress = self.safe_string(params, 'vaultAddress')
|
|
2578
|
+
if vaultAddress is not None:
|
|
2579
|
+
params = self.omit(params, 'vaultAddress')
|
|
2580
|
+
if vaultAddress.startswith('0x'):
|
|
2581
|
+
vaultAddress = vaultAddress.replace('0x', '')
|
|
2582
|
+
signature = self.sign_l1_action(updateAction, nonce, vaultAddress)
|
|
2583
|
+
request: dict = {
|
|
2584
|
+
'action': updateAction,
|
|
2585
|
+
'nonce': nonce,
|
|
2586
|
+
'signature': signature,
|
|
2587
|
+
# 'vaultAddress': vaultAddress,
|
|
2588
|
+
}
|
|
2589
|
+
if vaultAddress is not None:
|
|
2590
|
+
request['vaultAddress'] = vaultAddress
|
|
2591
|
+
response = await self.privatePostExchange(request)
|
|
2592
|
+
#
|
|
2593
|
+
# {
|
|
2594
|
+
# 'response': {
|
|
2595
|
+
# 'type': 'default'
|
|
2596
|
+
# },
|
|
2597
|
+
# 'status': 'ok'
|
|
2598
|
+
# }
|
|
2599
|
+
#
|
|
2600
|
+
return response
|
|
2601
|
+
|
|
2602
|
+
async def set_leverage(self, leverage: Int, symbol: Str = None, params={}):
|
|
2603
|
+
"""
|
|
2604
|
+
set the level of leverage for a market
|
|
2605
|
+
:param float leverage: the rate of leverage
|
|
2606
|
+
:param str symbol: unified market symbol
|
|
2607
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
|
2608
|
+
:param str [params.marginMode]: margin mode must be either [isolated, cross], default is cross
|
|
2609
|
+
:returns dict: response from the exchange
|
|
2610
|
+
"""
|
|
2611
|
+
if symbol is None:
|
|
2612
|
+
raise ArgumentsRequired(self.id + ' setLeverage() requires a symbol argument')
|
|
2613
|
+
await self.load_markets()
|
|
2614
|
+
market = self.market(symbol)
|
|
2615
|
+
marginMode = self.safe_string(params, 'marginMode', 'cross')
|
|
2616
|
+
isCross = (marginMode == 'cross')
|
|
2617
|
+
asset = self.parse_to_int(market['baseId'])
|
|
2618
|
+
nonce = self.milliseconds()
|
|
2619
|
+
params = self.omit(params, 'marginMode')
|
|
2620
|
+
updateAction: dict = {
|
|
2621
|
+
'type': 'updateLeverage',
|
|
2622
|
+
'asset': asset,
|
|
2623
|
+
'isCross': isCross,
|
|
2624
|
+
'leverage': leverage,
|
|
2625
|
+
}
|
|
2626
|
+
vaultAddress = self.format_vault_address(self.safe_string(params, 'vaultAddress'))
|
|
2627
|
+
signature = self.sign_l1_action(updateAction, nonce, vaultAddress)
|
|
2628
|
+
request: dict = {
|
|
2629
|
+
'action': updateAction,
|
|
2630
|
+
'nonce': nonce,
|
|
2631
|
+
'signature': signature,
|
|
2632
|
+
# 'vaultAddress': vaultAddress,
|
|
2633
|
+
}
|
|
2634
|
+
if vaultAddress is not None:
|
|
2635
|
+
params = self.omit(params, 'vaultAddress')
|
|
2636
|
+
request['vaultAddress'] = vaultAddress
|
|
2637
|
+
response = await self.privatePostExchange(request)
|
|
2638
|
+
#
|
|
2639
|
+
# {
|
|
2640
|
+
# 'response': {
|
|
2641
|
+
# 'type': 'default'
|
|
2642
|
+
# },
|
|
2643
|
+
# 'status': 'ok'
|
|
2644
|
+
# }
|
|
2645
|
+
#
|
|
2646
|
+
return response
|
|
2647
|
+
|
|
2648
|
+
async def add_margin(self, symbol: str, amount: float, params={}) -> MarginModification:
|
|
2649
|
+
"""
|
|
2650
|
+
add margin
|
|
2651
|
+
|
|
2652
|
+
https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#update-isolated-margin
|
|
2653
|
+
|
|
2654
|
+
:param str symbol: unified market symbol
|
|
2655
|
+
:param float amount: amount of margin to add
|
|
2656
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
|
2657
|
+
:returns dict: a `margin structure <https://docs.ccxt.com/#/?id=add-margin-structure>`
|
|
2658
|
+
"""
|
|
2659
|
+
return await self.modify_margin_helper(symbol, amount, 'add', params)
|
|
2660
|
+
|
|
2661
|
+
async def reduce_margin(self, symbol: str, amount: float, params={}) -> MarginModification:
|
|
2662
|
+
"""
|
|
2663
|
+
|
|
2664
|
+
https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#update-isolated-margin
|
|
2665
|
+
|
|
2666
|
+
remove margin from a position
|
|
2667
|
+
:param str symbol: unified market symbol
|
|
2668
|
+
:param float amount: the amount of margin to remove
|
|
2669
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
|
2670
|
+
:returns dict: a `margin structure <https://docs.ccxt.com/#/?id=reduce-margin-structure>`
|
|
2671
|
+
"""
|
|
2672
|
+
return await self.modify_margin_helper(symbol, amount, 'reduce', params)
|
|
2673
|
+
|
|
2674
|
+
async def modify_margin_helper(self, symbol: str, amount, type, params={}) -> MarginModification:
|
|
2675
|
+
await self.load_markets()
|
|
2676
|
+
market = self.market(symbol)
|
|
2677
|
+
asset = self.parse_to_int(market['baseId'])
|
|
2678
|
+
sz = self.parse_to_int(Precise.string_mul(self.amount_to_precision(symbol, amount), '1000000'))
|
|
2679
|
+
if type == 'reduce':
|
|
2680
|
+
sz = -sz
|
|
2681
|
+
nonce = self.milliseconds()
|
|
2682
|
+
updateAction: dict = {
|
|
2683
|
+
'type': 'updateIsolatedMargin',
|
|
2684
|
+
'asset': asset,
|
|
2685
|
+
'isBuy': True,
|
|
2686
|
+
'ntli': sz,
|
|
2687
|
+
}
|
|
2688
|
+
vaultAddress = self.format_vault_address(self.safe_string(params, 'vaultAddress'))
|
|
2689
|
+
signature = self.sign_l1_action(updateAction, nonce, vaultAddress)
|
|
2690
|
+
request: dict = {
|
|
2691
|
+
'action': updateAction,
|
|
2692
|
+
'nonce': nonce,
|
|
2693
|
+
'signature': signature,
|
|
2694
|
+
# 'vaultAddress': vaultAddress,
|
|
2695
|
+
}
|
|
2696
|
+
if vaultAddress is not None:
|
|
2697
|
+
params = self.omit(params, 'vaultAddress')
|
|
2698
|
+
request['vaultAddress'] = vaultAddress
|
|
2699
|
+
response = await self.privatePostExchange(request)
|
|
2700
|
+
#
|
|
2701
|
+
# {
|
|
2702
|
+
# 'response': {
|
|
2703
|
+
# 'type': 'default'
|
|
2704
|
+
# },
|
|
2705
|
+
# 'status': 'ok'
|
|
2706
|
+
# }
|
|
2707
|
+
#
|
|
2708
|
+
return self.extend(self.parse_margin_modification(response, market), {
|
|
2709
|
+
'code': self.safe_string(response, 'status'),
|
|
2710
|
+
})
|
|
2711
|
+
|
|
2712
|
+
def parse_margin_modification(self, data: dict, market: Market = None) -> MarginModification:
|
|
2713
|
+
#
|
|
2714
|
+
# {
|
|
2715
|
+
# 'type': 'default'
|
|
2716
|
+
# }
|
|
2717
|
+
#
|
|
2718
|
+
return {
|
|
2719
|
+
'info': data,
|
|
2720
|
+
'symbol': self.safe_symbol(None, market),
|
|
2721
|
+
'type': None,
|
|
2722
|
+
'marginMode': 'isolated',
|
|
2723
|
+
'amount': None,
|
|
2724
|
+
'total': None,
|
|
2725
|
+
'code': self.safe_string(market, 'settle'),
|
|
2726
|
+
'status': None,
|
|
2727
|
+
'timestamp': None,
|
|
2728
|
+
'datetime': None,
|
|
2729
|
+
}
|
|
2730
|
+
|
|
2731
|
+
async def transfer(self, code: str, amount: float, fromAccount: str, toAccount: str, params={}) -> TransferEntry:
|
|
2732
|
+
"""
|
|
2733
|
+
transfer currency internally between wallets on the same account
|
|
2734
|
+
|
|
2735
|
+
https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#l1-usdc-transfer
|
|
2736
|
+
|
|
2737
|
+
:param str code: unified currency code
|
|
2738
|
+
:param float amount: amount to transfer
|
|
2739
|
+
:param str fromAccount: account to transfer from *spot, swap*
|
|
2740
|
+
:param str toAccount: account to transfer to *swap, spot or address*
|
|
2741
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
|
2742
|
+
:param str [params.vaultAddress]: the vault address for order
|
|
2743
|
+
:returns dict: a `transfer structure <https://docs.ccxt.com/#/?id=transfer-structure>`
|
|
2744
|
+
"""
|
|
2745
|
+
self.check_required_credentials()
|
|
2746
|
+
await self.load_markets()
|
|
2747
|
+
isSandboxMode = self.safe_bool(self.options, 'sandboxMode')
|
|
2748
|
+
nonce = self.milliseconds()
|
|
2749
|
+
if self.in_array(fromAccount, ['spot', 'swap', 'perp']):
|
|
2750
|
+
# handle swap <> spot account transfer
|
|
2751
|
+
if not self.in_array(toAccount, ['spot', 'swap', 'perp']):
|
|
2752
|
+
raise NotSupported(self.id + ' transfer() only support spot <> swap transfer')
|
|
2753
|
+
strAmount = self.number_to_string(amount)
|
|
2754
|
+
vaultAddress = self.format_vault_address(self.safe_string(params, 'vaultAddress'))
|
|
2755
|
+
params = self.omit(params, 'vaultAddress')
|
|
2756
|
+
if vaultAddress is not None:
|
|
2757
|
+
strAmount = strAmount + ' subaccount:' + vaultAddress
|
|
2758
|
+
toPerp = (toAccount == 'perp') or (toAccount == 'swap')
|
|
2759
|
+
transferPayload: dict = {
|
|
2760
|
+
'hyperliquidChain': 'Testnet' if isSandboxMode else 'Mainnet',
|
|
2761
|
+
'amount': strAmount,
|
|
2762
|
+
'toPerp': toPerp,
|
|
2763
|
+
'nonce': nonce,
|
|
2764
|
+
}
|
|
2765
|
+
transferSig = self.build_usd_class_send_sig(transferPayload)
|
|
2766
|
+
transferRequest: dict = {
|
|
2767
|
+
'action': {
|
|
2768
|
+
'hyperliquidChain': transferPayload['hyperliquidChain'],
|
|
2769
|
+
'signatureChainId': '0x66eee',
|
|
2770
|
+
'type': 'usdClassTransfer',
|
|
2771
|
+
'amount': strAmount,
|
|
2772
|
+
'toPerp': toPerp,
|
|
2773
|
+
'nonce': nonce,
|
|
2774
|
+
},
|
|
2775
|
+
'nonce': nonce,
|
|
2776
|
+
'signature': transferSig,
|
|
2777
|
+
}
|
|
2778
|
+
if vaultAddress is not None:
|
|
2779
|
+
transferRequest['vaultAddress'] = vaultAddress
|
|
2780
|
+
transferResponse = await self.privatePostExchange(transferRequest)
|
|
2781
|
+
return transferResponse
|
|
2782
|
+
# handle sub-account/different account transfer
|
|
2783
|
+
self.check_address(toAccount)
|
|
2784
|
+
if code is not None:
|
|
2785
|
+
code = code.upper()
|
|
2786
|
+
if code != 'USDC':
|
|
2787
|
+
raise NotSupported(self.id + ' transfer() only support USDC')
|
|
2788
|
+
payload: dict = {
|
|
2789
|
+
'hyperliquidChain': 'Testnet' if isSandboxMode else 'Mainnet',
|
|
2790
|
+
'destination': toAccount,
|
|
2791
|
+
'amount': self.number_to_string(amount),
|
|
2792
|
+
'time': nonce,
|
|
2793
|
+
}
|
|
2794
|
+
sig = self.build_usd_send_sig(payload)
|
|
2795
|
+
request: dict = {
|
|
2796
|
+
'action': {
|
|
2797
|
+
'hyperliquidChain': payload['hyperliquidChain'],
|
|
2798
|
+
'signatureChainId': '0x66eee', # check self out
|
|
2799
|
+
'destination': toAccount,
|
|
2800
|
+
'amount': str(amount),
|
|
2801
|
+
'time': nonce,
|
|
2802
|
+
'type': 'usdSend',
|
|
2803
|
+
},
|
|
2804
|
+
'nonce': nonce,
|
|
2805
|
+
'signature': sig,
|
|
2806
|
+
}
|
|
2807
|
+
response = await self.privatePostExchange(request)
|
|
2808
|
+
#
|
|
2809
|
+
# {'response': {'type': 'default'}, 'status': 'ok'}
|
|
2810
|
+
#
|
|
2811
|
+
return self.parse_transfer(response)
|
|
2812
|
+
|
|
2813
|
+
def parse_transfer(self, transfer: dict, currency: Currency = None) -> TransferEntry:
|
|
2814
|
+
#
|
|
2815
|
+
# {'response': {'type': 'default'}, 'status': 'ok'}
|
|
2816
|
+
#
|
|
2817
|
+
return {
|
|
2818
|
+
'info': transfer,
|
|
2819
|
+
'id': None,
|
|
2820
|
+
'timestamp': None,
|
|
2821
|
+
'datetime': None,
|
|
2822
|
+
'currency': None,
|
|
2823
|
+
'amount': None,
|
|
2824
|
+
'fromAccount': None,
|
|
2825
|
+
'toAccount': None,
|
|
2826
|
+
'status': 'ok',
|
|
2827
|
+
}
|
|
2828
|
+
|
|
2829
|
+
async def withdraw(self, code: str, amount: float, address: str, tag=None, params={}) -> Transaction:
|
|
2830
|
+
"""
|
|
2831
|
+
make a withdrawal(only support USDC)
|
|
2832
|
+
|
|
2833
|
+
https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#initiate-a-withdrawal-request
|
|
2834
|
+
https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#deposit-or-withdraw-from-a-vault
|
|
2835
|
+
|
|
2836
|
+
:param str code: unified currency code
|
|
2837
|
+
:param float amount: the amount to withdraw
|
|
2838
|
+
:param str address: the address to withdraw to
|
|
2839
|
+
:param str tag:
|
|
2840
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
|
2841
|
+
:param str [params.vaultAddress]: vault address withdraw from
|
|
2842
|
+
:returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
|
|
2843
|
+
"""
|
|
2844
|
+
self.check_required_credentials()
|
|
2845
|
+
await self.load_markets()
|
|
2846
|
+
self.check_address(address)
|
|
2847
|
+
if code is not None:
|
|
2848
|
+
code = code.upper()
|
|
2849
|
+
if code != 'USDC':
|
|
2850
|
+
raise NotSupported(self.id + ' withdraw() only support USDC')
|
|
2851
|
+
vaultAddress = self.format_vault_address(self.safe_string(params, 'vaultAddress'))
|
|
2852
|
+
params = self.omit(params, 'vaultAddress')
|
|
2853
|
+
nonce = self.milliseconds()
|
|
2854
|
+
action: dict = {}
|
|
2855
|
+
sig = None
|
|
2856
|
+
if vaultAddress is not None:
|
|
2857
|
+
action = {
|
|
2858
|
+
'type': 'vaultTransfer',
|
|
2859
|
+
'vaultAddress': '0x' + vaultAddress,
|
|
2860
|
+
'isDeposit': False,
|
|
2861
|
+
'usd': amount,
|
|
2862
|
+
}
|
|
2863
|
+
sig = self.sign_l1_action(action, nonce)
|
|
2864
|
+
else:
|
|
2865
|
+
isSandboxMode = self.safe_bool(self.options, 'sandboxMode', False)
|
|
2866
|
+
payload: dict = {
|
|
2867
|
+
'hyperliquidChain': 'Testnet' if isSandboxMode else 'Mainnet',
|
|
2868
|
+
'destination': address,
|
|
2869
|
+
'amount': str(amount),
|
|
2870
|
+
'time': nonce,
|
|
2871
|
+
}
|
|
2872
|
+
sig = self.build_withdraw_sig(payload)
|
|
2873
|
+
action = {
|
|
2874
|
+
'hyperliquidChain': payload['hyperliquidChain'],
|
|
2875
|
+
'signatureChainId': '0x66eee', # check self out
|
|
2876
|
+
'destination': address,
|
|
2877
|
+
'amount': str(amount),
|
|
2878
|
+
'time': nonce,
|
|
2879
|
+
'type': 'withdraw3',
|
|
2880
|
+
}
|
|
2881
|
+
request: dict = {
|
|
2882
|
+
'action': action,
|
|
2883
|
+
'nonce': nonce,
|
|
2884
|
+
'signature': sig,
|
|
2885
|
+
}
|
|
2886
|
+
response = await self.privatePostExchange(request)
|
|
2887
|
+
return self.parse_transaction(response)
|
|
2888
|
+
|
|
2889
|
+
def parse_transaction(self, transaction: dict, currency: Currency = None) -> Transaction:
|
|
2890
|
+
#
|
|
2891
|
+
# {status: 'ok', response: {type: 'default'}}
|
|
2892
|
+
#
|
|
2893
|
+
# fetchDeposits / fetchWithdrawals
|
|
2894
|
+
# {
|
|
2895
|
+
# "time":1724762307531,
|
|
2896
|
+
# "hash":"0x620a234a7e0eb7930575040f59482a01050058b0802163b4767bfd9033e77781",
|
|
2897
|
+
# "delta":{
|
|
2898
|
+
# "type":"accountClassTransfer",
|
|
2899
|
+
# "usdc":"50.0",
|
|
2900
|
+
# "toPerp":false
|
|
2901
|
+
# }
|
|
2902
|
+
# }
|
|
2903
|
+
#
|
|
2904
|
+
timestamp = self.safe_integer(transaction, 'time')
|
|
2905
|
+
delta = self.safe_dict(transaction, 'delta', {})
|
|
2906
|
+
fee = None
|
|
2907
|
+
feeCost = self.safe_integer(delta, 'fee')
|
|
2908
|
+
if feeCost is not None:
|
|
2909
|
+
fee = {
|
|
2910
|
+
'currency': 'USDC',
|
|
2911
|
+
'cost': feeCost,
|
|
2912
|
+
}
|
|
2913
|
+
internal = None
|
|
2914
|
+
type = self.safe_string(delta, 'type')
|
|
2915
|
+
if type is not None:
|
|
2916
|
+
internal = (type == 'internalTransfer')
|
|
2917
|
+
return {
|
|
2918
|
+
'info': transaction,
|
|
2919
|
+
'id': None,
|
|
2920
|
+
'txid': self.safe_string(transaction, 'hash'),
|
|
2921
|
+
'timestamp': timestamp,
|
|
2922
|
+
'datetime': self.iso8601(timestamp),
|
|
2923
|
+
'network': None,
|
|
2924
|
+
'address': None,
|
|
2925
|
+
'addressTo': self.safe_string(delta, 'destination'),
|
|
2926
|
+
'addressFrom': self.safe_string(delta, 'user'),
|
|
2927
|
+
'tag': None,
|
|
2928
|
+
'tagTo': None,
|
|
2929
|
+
'tagFrom': None,
|
|
2930
|
+
'type': None,
|
|
2931
|
+
'amount': self.safe_integer(delta, 'usdc'),
|
|
2932
|
+
'currency': None,
|
|
2933
|
+
'status': self.safe_string(transaction, 'status'),
|
|
2934
|
+
'updated': None,
|
|
2935
|
+
'comment': None,
|
|
2936
|
+
'internal': internal,
|
|
2937
|
+
'fee': fee,
|
|
2938
|
+
}
|
|
2939
|
+
|
|
2940
|
+
async def fetch_trading_fee(self, symbol: str, params={}) -> TradingFeeInterface:
|
|
2941
|
+
"""
|
|
2942
|
+
fetch the trading fees for a market
|
|
2943
|
+
:param str symbol: unified market symbol
|
|
2944
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
|
2945
|
+
:param str [params.user]: user address, will default to self.walletAddress if not provided
|
|
2946
|
+
:returns dict: a `fee structure <https://docs.ccxt.com/#/?id=fee-structure>`
|
|
2947
|
+
"""
|
|
2948
|
+
await self.load_markets()
|
|
2949
|
+
userAddress = None
|
|
2950
|
+
userAddress, params = self.handle_public_address('fetchTradingFee', params)
|
|
2951
|
+
market = self.market(symbol)
|
|
2952
|
+
request: dict = {
|
|
2953
|
+
'type': 'userFees',
|
|
2954
|
+
'user': userAddress,
|
|
2955
|
+
}
|
|
2956
|
+
response = await self.publicPostInfo(self.extend(request, params))
|
|
2957
|
+
#
|
|
2958
|
+
# {
|
|
2959
|
+
# "dailyUserVlm": [
|
|
2960
|
+
# {
|
|
2961
|
+
# "date": "2024-07-08",
|
|
2962
|
+
# "userCross": "0.0",
|
|
2963
|
+
# "userAdd": "0.0",
|
|
2964
|
+
# "exchange": "90597185.23639999"
|
|
2965
|
+
# }
|
|
2966
|
+
# ],
|
|
2967
|
+
# "feeSchedule": {
|
|
2968
|
+
# "cross": "0.00035",
|
|
2969
|
+
# "add": "0.0001",
|
|
2970
|
+
# "tiers": {
|
|
2971
|
+
# "vip": [
|
|
2972
|
+
# {
|
|
2973
|
+
# "ntlCutoff": "5000000.0",
|
|
2974
|
+
# "cross": "0.0003",
|
|
2975
|
+
# "add": "0.00005"
|
|
2976
|
+
# }
|
|
2977
|
+
# ],
|
|
2978
|
+
# "mm": [
|
|
2979
|
+
# {
|
|
2980
|
+
# "makerFractionCutoff": "0.005",
|
|
2981
|
+
# "add": "-0.00001"
|
|
2982
|
+
# }
|
|
2983
|
+
# ]
|
|
2984
|
+
# },
|
|
2985
|
+
# "referralDiscount": "0.04"
|
|
2986
|
+
# },
|
|
2987
|
+
# "userCrossRate": "0.00035",
|
|
2988
|
+
# "userAddRate": "0.0001",
|
|
2989
|
+
# "activeReferralDiscount": "0.0"
|
|
2990
|
+
# }
|
|
2991
|
+
#
|
|
2992
|
+
data: dict = {
|
|
2993
|
+
'userCrossRate': self.safe_string(response, 'userCrossRate'),
|
|
2994
|
+
'userAddRate': self.safe_string(response, 'userAddRate'),
|
|
2995
|
+
}
|
|
2996
|
+
return self.parse_trading_fee(data, market)
|
|
2997
|
+
|
|
2998
|
+
def parse_trading_fee(self, fee: dict, market: Market = None) -> TradingFeeInterface:
|
|
2999
|
+
#
|
|
3000
|
+
# {
|
|
3001
|
+
# "dailyUserVlm": [
|
|
3002
|
+
# {
|
|
3003
|
+
# "date": "2024-07-08",
|
|
3004
|
+
# "userCross": "0.0",
|
|
3005
|
+
# "userAdd": "0.0",
|
|
3006
|
+
# "exchange": "90597185.23639999"
|
|
3007
|
+
# }
|
|
3008
|
+
# ],
|
|
3009
|
+
# "feeSchedule": {
|
|
3010
|
+
# "cross": "0.00035",
|
|
3011
|
+
# "add": "0.0001",
|
|
3012
|
+
# "tiers": {
|
|
3013
|
+
# "vip": [
|
|
3014
|
+
# {
|
|
3015
|
+
# "ntlCutoff": "5000000.0",
|
|
3016
|
+
# "cross": "0.0003",
|
|
3017
|
+
# "add": "0.00005"
|
|
3018
|
+
# }
|
|
3019
|
+
# ],
|
|
3020
|
+
# "mm": [
|
|
3021
|
+
# {
|
|
3022
|
+
# "makerFractionCutoff": "0.005",
|
|
3023
|
+
# "add": "-0.00001"
|
|
3024
|
+
# }
|
|
3025
|
+
# ]
|
|
3026
|
+
# },
|
|
3027
|
+
# "referralDiscount": "0.04"
|
|
3028
|
+
# },
|
|
3029
|
+
# "userCrossRate": "0.00035",
|
|
3030
|
+
# "userAddRate": "0.0001",
|
|
3031
|
+
# "activeReferralDiscount": "0.0"
|
|
3032
|
+
# }
|
|
3033
|
+
#
|
|
3034
|
+
symbol = self.safe_symbol(None, market)
|
|
3035
|
+
return {
|
|
3036
|
+
'info': fee,
|
|
3037
|
+
'symbol': symbol,
|
|
3038
|
+
'maker': self.safe_number(fee, 'userAddRate'),
|
|
3039
|
+
'taker': self.safe_number(fee, 'userCrossRate'),
|
|
3040
|
+
'percentage': None,
|
|
3041
|
+
'tierBased': None,
|
|
3042
|
+
}
|
|
3043
|
+
|
|
3044
|
+
async def fetch_ledger(self, code: Str = None, since: Int = None, limit: Int = None, params={}) -> List[LedgerEntry]:
|
|
3045
|
+
"""
|
|
3046
|
+
fetch the history of changes, actions done by the user or operations that altered the balance of the user
|
|
3047
|
+
:param str [code]: unified currency code
|
|
3048
|
+
:param int [since]: timestamp in ms of the earliest ledger entry
|
|
3049
|
+
:param int [limit]: max number of ledger entries to return
|
|
3050
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
|
3051
|
+
:param int [params.until]: timestamp in ms of the latest ledger entry
|
|
3052
|
+
:returns dict: a `ledger structure <https://docs.ccxt.com/#/?id=ledger>`
|
|
3053
|
+
"""
|
|
3054
|
+
await self.load_markets()
|
|
3055
|
+
userAddress = None
|
|
3056
|
+
userAddress, params = self.handle_public_address('fetchLedger', params)
|
|
3057
|
+
request: dict = {
|
|
3058
|
+
'type': 'userNonFundingLedgerUpdates',
|
|
3059
|
+
'user': userAddress,
|
|
3060
|
+
}
|
|
3061
|
+
if since is not None:
|
|
3062
|
+
request['startTime'] = since
|
|
3063
|
+
until = self.safe_integer(params, 'until')
|
|
3064
|
+
if until is not None:
|
|
3065
|
+
request['endTime'] = until
|
|
3066
|
+
params = self.omit(params, ['until'])
|
|
3067
|
+
response = await self.publicPostInfo(self.extend(request, params))
|
|
3068
|
+
#
|
|
3069
|
+
# [
|
|
3070
|
+
# {
|
|
3071
|
+
# "time":1724762307531,
|
|
3072
|
+
# "hash":"0x620a234a7e0eb7930575040f59482a01050058b0802163b4767bfd9033e77781",
|
|
3073
|
+
# "delta":{
|
|
3074
|
+
# "type":"accountClassTransfer",
|
|
3075
|
+
# "usdc":"50.0",
|
|
3076
|
+
# "toPerp":false
|
|
3077
|
+
# }
|
|
3078
|
+
# }
|
|
3079
|
+
# ]
|
|
3080
|
+
#
|
|
3081
|
+
return self.parse_ledger(response, None, since, limit)
|
|
3082
|
+
|
|
3083
|
+
def parse_ledger_entry(self, item: dict, currency: Currency = None) -> LedgerEntry:
|
|
3084
|
+
#
|
|
3085
|
+
# {
|
|
3086
|
+
# "time":1724762307531,
|
|
3087
|
+
# "hash":"0x620a234a7e0eb7930575040f59482a01050058b0802163b4767bfd9033e77781",
|
|
3088
|
+
# "delta":{
|
|
3089
|
+
# "type":"accountClassTransfer",
|
|
3090
|
+
# "usdc":"50.0",
|
|
3091
|
+
# "toPerp":false
|
|
3092
|
+
# }
|
|
3093
|
+
# }
|
|
3094
|
+
#
|
|
3095
|
+
timestamp = self.safe_integer(item, 'time')
|
|
3096
|
+
delta = self.safe_dict(item, 'delta', {})
|
|
3097
|
+
fee = None
|
|
3098
|
+
feeCost = self.safe_integer(delta, 'fee')
|
|
3099
|
+
if feeCost is not None:
|
|
3100
|
+
fee = {
|
|
3101
|
+
'currency': 'USDC',
|
|
3102
|
+
'cost': feeCost,
|
|
3103
|
+
}
|
|
3104
|
+
type = self.safe_string(delta, 'type')
|
|
3105
|
+
amount = self.safe_string(delta, 'usdc')
|
|
3106
|
+
return self.safe_ledger_entry({
|
|
3107
|
+
'info': item,
|
|
3108
|
+
'id': self.safe_string(item, 'hash'),
|
|
3109
|
+
'direction': None,
|
|
3110
|
+
'account': None,
|
|
3111
|
+
'referenceAccount': self.safe_string(delta, 'user'),
|
|
3112
|
+
'referenceId': self.safe_string(item, 'hash'),
|
|
3113
|
+
'type': self.parse_ledger_entry_type(type),
|
|
3114
|
+
'currency': None,
|
|
3115
|
+
'amount': self.parse_number(amount),
|
|
3116
|
+
'timestamp': timestamp,
|
|
3117
|
+
'datetime': self.iso8601(timestamp),
|
|
3118
|
+
'before': None,
|
|
3119
|
+
'after': None,
|
|
3120
|
+
'status': None,
|
|
3121
|
+
'fee': fee,
|
|
3122
|
+
}, currency)
|
|
3123
|
+
|
|
3124
|
+
def parse_ledger_entry_type(self, type):
|
|
3125
|
+
ledgerType: dict = {
|
|
3126
|
+
'internalTransfer': 'transfer',
|
|
3127
|
+
'accountClassTransfer': 'transfer',
|
|
3128
|
+
}
|
|
3129
|
+
return self.safe_string(ledgerType, type, type)
|
|
3130
|
+
|
|
3131
|
+
async def fetch_deposits(self, code: Str = None, since: Int = None, limit: Int = None, params={}):
|
|
3132
|
+
"""
|
|
3133
|
+
fetch all deposits made to an account
|
|
3134
|
+
:param str code: unified currency code
|
|
3135
|
+
:param int [since]: the earliest time in ms to fetch deposits for
|
|
3136
|
+
:param int [limit]: the maximum number of deposits structures to retrieve
|
|
3137
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
|
3138
|
+
:param int [params.until]: the latest time in ms to fetch withdrawals for
|
|
3139
|
+
:returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
|
|
3140
|
+
"""
|
|
3141
|
+
await self.load_markets()
|
|
3142
|
+
userAddress = None
|
|
3143
|
+
userAddress, params = self.handle_public_address('fetchDepositsWithdrawals', params)
|
|
3144
|
+
request: dict = {
|
|
3145
|
+
'type': 'userNonFundingLedgerUpdates',
|
|
3146
|
+
'user': userAddress,
|
|
3147
|
+
}
|
|
3148
|
+
if since is not None:
|
|
3149
|
+
request['startTime'] = since
|
|
3150
|
+
until = self.safe_integer(params, 'until')
|
|
3151
|
+
if until is not None:
|
|
3152
|
+
request['endTime'] = until
|
|
3153
|
+
params = self.omit(params, ['until'])
|
|
3154
|
+
response = await self.publicPostInfo(self.extend(request, params))
|
|
3155
|
+
#
|
|
3156
|
+
# [
|
|
3157
|
+
# {
|
|
3158
|
+
# "time":1724762307531,
|
|
3159
|
+
# "hash":"0x620a234a7e0eb7930575040f59482a01050058b0802163b4767bfd9033e77781",
|
|
3160
|
+
# "delta":{
|
|
3161
|
+
# "type":"accountClassTransfer",
|
|
3162
|
+
# "usdc":"50.0",
|
|
3163
|
+
# "toPerp":false
|
|
3164
|
+
# }
|
|
3165
|
+
# }
|
|
3166
|
+
# ]
|
|
3167
|
+
#
|
|
3168
|
+
records = self.extract_type_from_delta(response)
|
|
3169
|
+
deposits = self.filter_by_array(records, 'type', ['deposit'], False)
|
|
3170
|
+
return self.parse_transactions(deposits, None, since, limit)
|
|
3171
|
+
|
|
3172
|
+
async def fetch_withdrawals(self, code: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Transaction]:
|
|
3173
|
+
"""
|
|
3174
|
+
fetch all withdrawals made from an account
|
|
3175
|
+
:param str code: unified currency code
|
|
3176
|
+
:param int [since]: the earliest time in ms to fetch withdrawals for
|
|
3177
|
+
:param int [limit]: the maximum number of withdrawals structures to retrieve
|
|
3178
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
|
3179
|
+
:param int [params.until]: the latest time in ms to fetch withdrawals for
|
|
3180
|
+
:returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
|
|
3181
|
+
"""
|
|
3182
|
+
await self.load_markets()
|
|
3183
|
+
userAddress = None
|
|
3184
|
+
userAddress, params = self.handle_public_address('fetchDepositsWithdrawals', params)
|
|
3185
|
+
request: dict = {
|
|
3186
|
+
'type': 'userNonFundingLedgerUpdates',
|
|
3187
|
+
'user': userAddress,
|
|
3188
|
+
}
|
|
3189
|
+
if since is not None:
|
|
3190
|
+
request['startTime'] = since
|
|
3191
|
+
until = self.safe_integer(params, 'until')
|
|
3192
|
+
if until is not None:
|
|
3193
|
+
request['endTime'] = until
|
|
3194
|
+
params = self.omit(params, ['until'])
|
|
3195
|
+
response = await self.publicPostInfo(self.extend(request, params))
|
|
3196
|
+
#
|
|
3197
|
+
# [
|
|
3198
|
+
# {
|
|
3199
|
+
# "time":1724762307531,
|
|
3200
|
+
# "hash":"0x620a234a7e0eb7930575040f59482a01050058b0802163b4767bfd9033e77781",
|
|
3201
|
+
# "delta":{
|
|
3202
|
+
# "type":"accountClassTransfer",
|
|
3203
|
+
# "usdc":"50.0",
|
|
3204
|
+
# "toPerp":false
|
|
3205
|
+
# }
|
|
3206
|
+
# }
|
|
3207
|
+
# ]
|
|
3208
|
+
#
|
|
3209
|
+
records = self.extract_type_from_delta(response)
|
|
3210
|
+
withdrawals = self.filter_by_array(records, 'type', ['withdraw'], False)
|
|
3211
|
+
return self.parse_transactions(withdrawals, None, since, limit)
|
|
3212
|
+
|
|
3213
|
+
async def fetch_open_interests(self, symbols: Strings = None, params={}):
|
|
3214
|
+
"""
|
|
3215
|
+
Retrieves the open interest for a list of symbols
|
|
3216
|
+
:param str[] [symbols]: Unified CCXT market symbol
|
|
3217
|
+
:param dict [params]: exchange specific parameters
|
|
3218
|
+
:returns dict} an open interest structure{@link https://docs.ccxt.com/#/?id=open-interest-structure:
|
|
3219
|
+
"""
|
|
3220
|
+
await self.load_markets()
|
|
3221
|
+
symbols = self.market_symbols(symbols)
|
|
3222
|
+
swapMarkets = await self.fetch_swap_markets()
|
|
3223
|
+
return self.parse_open_interests(swapMarkets, symbols)
|
|
3224
|
+
|
|
3225
|
+
async def fetch_open_interest(self, symbol: str, params={}):
|
|
3226
|
+
"""
|
|
3227
|
+
retrieves the open interest of a contract trading pair
|
|
3228
|
+
:param str symbol: unified CCXT market symbol
|
|
3229
|
+
:param dict [params]: exchange specific parameters
|
|
3230
|
+
:returns dict: an `open interest structure <https://docs.ccxt.com/#/?id=open-interest-structure>`
|
|
3231
|
+
"""
|
|
3232
|
+
symbol = self.symbol(symbol)
|
|
3233
|
+
await self.load_markets()
|
|
3234
|
+
ois = await self.fetch_open_interests([symbol], params)
|
|
3235
|
+
return ois[symbol]
|
|
3236
|
+
|
|
3237
|
+
def parse_open_interest(self, interest, market: Market = None):
|
|
3238
|
+
#
|
|
3239
|
+
# {
|
|
3240
|
+
# szDecimals: '2',
|
|
3241
|
+
# name: 'HYPE',
|
|
3242
|
+
# maxLeverage: '3',
|
|
3243
|
+
# funding: '0.00014735',
|
|
3244
|
+
# openInterest: '14677900.74',
|
|
3245
|
+
# prevDayPx: '26.145',
|
|
3246
|
+
# dayNtlVlm: '299643445.12560016',
|
|
3247
|
+
# premium: '0.00081613',
|
|
3248
|
+
# oraclePx: '27.569',
|
|
3249
|
+
# markPx: '27.63',
|
|
3250
|
+
# midPx: '27.599',
|
|
3251
|
+
# impactPxs: ['27.5915', '27.6319'],
|
|
3252
|
+
# dayBaseVlm: '10790652.83',
|
|
3253
|
+
# baseId: 159
|
|
3254
|
+
# }
|
|
3255
|
+
#
|
|
3256
|
+
interest = self.safe_dict(interest, 'info', {})
|
|
3257
|
+
coin = self.safe_string(interest, 'name')
|
|
3258
|
+
marketId = None
|
|
3259
|
+
if coin is not None:
|
|
3260
|
+
marketId = self.coin_to_market_id(coin)
|
|
3261
|
+
return self.safe_open_interest({
|
|
3262
|
+
'symbol': self.safe_symbol(marketId),
|
|
3263
|
+
'openInterestAmount': self.safe_number(interest, 'openInterest'),
|
|
3264
|
+
'openInterestValue': None,
|
|
3265
|
+
'timestamp': None,
|
|
3266
|
+
'datetime': None,
|
|
3267
|
+
'info': interest,
|
|
3268
|
+
}, market)
|
|
3269
|
+
|
|
3270
|
+
async def fetch_funding_history(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}):
|
|
3271
|
+
"""
|
|
3272
|
+
fetch the history of funding payments paid and received on self account
|
|
3273
|
+
:param str [symbol]: unified market symbol
|
|
3274
|
+
:param int [since]: the earliest time in ms to fetch funding history for
|
|
3275
|
+
:param int [limit]: the maximum number of funding history structures to retrieve
|
|
3276
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
|
3277
|
+
:returns dict: a `funding history structure <https://docs.ccxt.com/#/?id=funding-history-structure>`
|
|
3278
|
+
"""
|
|
3279
|
+
await self.load_markets()
|
|
3280
|
+
market = None
|
|
3281
|
+
if symbol is not None:
|
|
3282
|
+
market = self.market(symbol)
|
|
3283
|
+
userAddress = None
|
|
3284
|
+
userAddress, params = self.handle_public_address('fetchFundingHistory', params)
|
|
3285
|
+
request: dict = {
|
|
3286
|
+
'user': userAddress,
|
|
3287
|
+
'type': 'userFunding',
|
|
3288
|
+
}
|
|
3289
|
+
if since is not None:
|
|
3290
|
+
request['startTime'] = since
|
|
3291
|
+
until = self.safe_integer(params, 'until')
|
|
3292
|
+
params = self.omit(params, 'until')
|
|
3293
|
+
if until is not None:
|
|
3294
|
+
request['endTime'] = until
|
|
3295
|
+
response = await self.publicPostInfo(self.extend(request, params))
|
|
3296
|
+
#
|
|
3297
|
+
# [
|
|
3298
|
+
# {
|
|
3299
|
+
# "time": 1734026400057,
|
|
3300
|
+
# "hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
|
|
3301
|
+
# "delta": {
|
|
3302
|
+
# "type": "funding",
|
|
3303
|
+
# "coin": "SOL",
|
|
3304
|
+
# "usdc": "75.635093",
|
|
3305
|
+
# "szi": "-7375.9",
|
|
3306
|
+
# "fundingRate": "0.00004381",
|
|
3307
|
+
# "nSamples": null
|
|
3308
|
+
# }
|
|
3309
|
+
# }
|
|
3310
|
+
# ]
|
|
3311
|
+
#
|
|
3312
|
+
return self.parse_incomes(response, market, since, limit)
|
|
3313
|
+
|
|
3314
|
+
def parse_income(self, income, market: Market = None):
|
|
3315
|
+
#
|
|
3316
|
+
# {
|
|
3317
|
+
# "time": 1734026400057,
|
|
3318
|
+
# "hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
|
|
3319
|
+
# "delta": {
|
|
3320
|
+
# "type": "funding",
|
|
3321
|
+
# "coin": "SOL",
|
|
3322
|
+
# "usdc": "75.635093",
|
|
3323
|
+
# "szi": "-7375.9",
|
|
3324
|
+
# "fundingRate": "0.00004381",
|
|
3325
|
+
# "nSamples": null
|
|
3326
|
+
# }
|
|
3327
|
+
# }
|
|
3328
|
+
#
|
|
3329
|
+
id = self.safe_string(income, 'hash')
|
|
3330
|
+
timestamp = self.safe_integer(income, 'time')
|
|
3331
|
+
delta = self.safe_dict(income, 'delta')
|
|
3332
|
+
baseId = self.safe_string(delta, 'coin')
|
|
3333
|
+
marketSymbol = baseId + '/USDC:USDC'
|
|
3334
|
+
market = self.safe_market(marketSymbol)
|
|
3335
|
+
symbol = market['symbol']
|
|
3336
|
+
amount = self.safe_string(delta, 'usdc')
|
|
3337
|
+
code = self.safe_currency_code('USDC')
|
|
3338
|
+
rate = self.safe_number(delta, 'fundingRate')
|
|
3339
|
+
return {
|
|
3340
|
+
'info': income,
|
|
3341
|
+
'symbol': symbol,
|
|
3342
|
+
'code': code,
|
|
3343
|
+
'timestamp': timestamp,
|
|
3344
|
+
'datetime': self.iso8601(timestamp),
|
|
3345
|
+
'id': id,
|
|
3346
|
+
'amount': self.parse_number(amount),
|
|
3347
|
+
'rate': rate,
|
|
3348
|
+
}
|
|
3349
|
+
|
|
3350
|
+
def extract_type_from_delta(self, data=[]):
|
|
3351
|
+
records = []
|
|
3352
|
+
for i in range(0, len(data)):
|
|
3353
|
+
record = data[i]
|
|
3354
|
+
record['type'] = record['delta']['type']
|
|
3355
|
+
records.append(record)
|
|
3356
|
+
return records
|
|
3357
|
+
|
|
3358
|
+
def format_vault_address(self, address: Str = None):
|
|
3359
|
+
if address is None:
|
|
3360
|
+
return None
|
|
3361
|
+
if address.startswith('0x'):
|
|
3362
|
+
return address.replace('0x', '')
|
|
3363
|
+
return address
|
|
3364
|
+
|
|
3365
|
+
def handle_public_address(self, methodName: str, params: dict):
|
|
3366
|
+
userAux = None
|
|
3367
|
+
userAux, params = self.handle_option_and_params(params, methodName, 'user')
|
|
3368
|
+
user = userAux
|
|
3369
|
+
user, params = self.handle_option_and_params(params, methodName, 'address', userAux)
|
|
3370
|
+
if (user is not None) and (user != ''):
|
|
3371
|
+
return [user, params]
|
|
3372
|
+
if (self.walletAddress is not None) and (self.walletAddress != ''):
|
|
3373
|
+
return [self.walletAddress, params]
|
|
3374
|
+
raise ArgumentsRequired(self.id + ' ' + methodName + '() requires a user parameter inside \'params\' or the wallet address set')
|
|
3375
|
+
|
|
3376
|
+
def coin_to_market_id(self, coin: Str):
|
|
3377
|
+
if coin.find('/') > -1 or coin.find('@') > -1:
|
|
3378
|
+
return coin # spot
|
|
3379
|
+
return coin + '/USDC:USDC'
|
|
3380
|
+
|
|
3381
|
+
def handle_errors(self, code: int, reason: str, url: str, method: str, headers: dict, body: str, response, requestHeaders, requestBody):
|
|
3382
|
+
if not response:
|
|
3383
|
+
return None # fallback to default error handler
|
|
3384
|
+
# {"status":"err","response":"User or API Wallet 0xb8a6f8b26223de27c31938d56e470a5b832703a5 does not exist."}
|
|
3385
|
+
#
|
|
3386
|
+
# {
|
|
3387
|
+
# status: 'ok',
|
|
3388
|
+
# response: {type: 'order', data: {statuses: [{error: 'Insufficient margin to place order. asset=4'}]}}
|
|
3389
|
+
# }
|
|
3390
|
+
# {"status":"ok","response":{"type":"order","data":{"statuses":[{"error":"Insufficient margin to place order. asset=84"}]}}}
|
|
3391
|
+
#
|
|
3392
|
+
status = self.safe_string(response, 'status', '')
|
|
3393
|
+
message = None
|
|
3394
|
+
if status == 'err':
|
|
3395
|
+
message = self.safe_string(response, 'response')
|
|
3396
|
+
else:
|
|
3397
|
+
responsePayload = self.safe_dict(response, 'response', {})
|
|
3398
|
+
data = self.safe_dict(responsePayload, 'data', {})
|
|
3399
|
+
statuses = self.safe_list(data, 'statuses', [])
|
|
3400
|
+
firstStatus = self.safe_dict(statuses, 0)
|
|
3401
|
+
message = self.safe_string(firstStatus, 'error')
|
|
3402
|
+
feedback = self.id + ' ' + body
|
|
3403
|
+
nonEmptyMessage = ((message is not None) and (message != ''))
|
|
3404
|
+
if nonEmptyMessage:
|
|
3405
|
+
self.throw_exactly_matched_exception(self.exceptions['exact'], message, feedback)
|
|
3406
|
+
self.throw_broadly_matched_exception(self.exceptions['broad'], message, feedback)
|
|
3407
|
+
if nonEmptyMessage:
|
|
3408
|
+
raise ExchangeError(feedback) # unknown message
|
|
3409
|
+
return None
|
|
3410
|
+
|
|
3411
|
+
def sign(self, path, api='public', method='GET', params={}, headers=None, body=None):
|
|
3412
|
+
url = self.implode_hostname(self.urls['api'][api]) + '/' + path
|
|
3413
|
+
if method == 'POST':
|
|
3414
|
+
headers = {
|
|
3415
|
+
'Content-Type': 'application/json',
|
|
3416
|
+
}
|
|
3417
|
+
body = self.json(params)
|
|
3418
|
+
return {'url': url, 'method': method, 'body': body, 'headers': headers}
|
|
3419
|
+
|
|
3420
|
+
def calculate_rate_limiter_cost(self, api, method, path, params, config={}):
|
|
3421
|
+
if ('byType' in config) and ('type' in params):
|
|
3422
|
+
type = params['type']
|
|
3423
|
+
byType = config['byType']
|
|
3424
|
+
if type in byType:
|
|
3425
|
+
return byType[type]
|
|
3426
|
+
return self.safe_value(config, 'cost', 1)
|
|
3427
|
+
|
|
3428
|
+
def parse_create_edit_order_args(self, id: Str, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, params={}):
|
|
3429
|
+
market = self.market(symbol)
|
|
3430
|
+
vaultAddress = self.safe_string(params, 'vaultAddress')
|
|
3431
|
+
params = self.omit(params, 'vaultAddress')
|
|
3432
|
+
symbol = market['symbol']
|
|
3433
|
+
order = {
|
|
3434
|
+
'symbol': symbol,
|
|
3435
|
+
'type': type,
|
|
3436
|
+
'side': side,
|
|
3437
|
+
'amount': amount,
|
|
3438
|
+
'price': price,
|
|
3439
|
+
'params': params,
|
|
3440
|
+
}
|
|
3441
|
+
globalParams = {}
|
|
3442
|
+
if vaultAddress is not None:
|
|
3443
|
+
globalParams['vaultAddress'] = vaultAddress
|
|
3444
|
+
if id is not None:
|
|
3445
|
+
order['id'] = id
|
|
3446
|
+
return [order, globalParams]
|