typed-margin-trade 0.1.0__tar.gz

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.
Files changed (116) hide show
  1. typed_margin_trade-0.1.0/LICENSE +21 -0
  2. typed_margin_trade-0.1.0/PKG-INFO +112 -0
  3. typed_margin_trade-0.1.0/README.md +86 -0
  4. typed_margin_trade-0.1.0/pyproject.toml +33 -0
  5. typed_margin_trade-0.1.0/setup.cfg +4 -0
  6. typed_margin_trade-0.1.0/src/typed_margin_trade/__init__.py +14 -0
  7. typed_margin_trade-0.1.0/src/typed_margin_trade/__init__.pyi +28 -0
  8. typed_margin_trade-0.1.0/src/typed_margin_trade/coingecko/__init__.py +31 -0
  9. typed_margin_trade-0.1.0/src/typed_margin_trade/coingecko/derivatives/__init__.py +12 -0
  10. typed_margin_trade-0.1.0/src/typed_margin_trade/coingecko/derivatives/contract_specs.py +42 -0
  11. typed_margin_trade-0.1.0/src/typed_margin_trade/coingecko/derivatives/contracts.py +79 -0
  12. typed_margin_trade-0.1.0/src/typed_margin_trade/coingecko/derivatives/orderbook.py +47 -0
  13. typed_margin_trade-0.1.0/src/typed_margin_trade/coingecko/spot/__init__.py +12 -0
  14. typed_margin_trade-0.1.0/src/typed_margin_trade/coingecko/spot/historical_trades.py +109 -0
  15. typed_margin_trade-0.1.0/src/typed_margin_trade/coingecko/spot/orderbook.py +47 -0
  16. typed_margin_trade-0.1.0/src/typed_margin_trade/coingecko/spot/tickers.py +54 -0
  17. typed_margin_trade-0.1.0/src/typed_margin_trade/core/__init__.py +5 -0
  18. typed_margin_trade-0.1.0/src/typed_margin_trade/core/__init__.pyi +34 -0
  19. typed_margin_trade-0.1.0/src/typed_margin_trade/core/auth.py +346 -0
  20. typed_margin_trade-0.1.0/src/typed_margin_trade/core/client.py +107 -0
  21. typed_margin_trade-0.1.0/src/typed_margin_trade/core/endpoint/__init__.py +1 -0
  22. typed_margin_trade-0.1.0/src/typed_margin_trade/core/endpoint/rpc.py +236 -0
  23. typed_margin_trade-0.1.0/src/typed_margin_trade/core/endpoint/stream.py +124 -0
  24. typed_margin_trade-0.1.0/src/typed_margin_trade/core/endpoint/wire.py +38 -0
  25. typed_margin_trade-0.1.0/src/typed_margin_trade/core/envelope.py +169 -0
  26. typed_margin_trade-0.1.0/src/typed_margin_trade/core/exc.py +23 -0
  27. typed_margin_trade-0.1.0/src/typed_margin_trade/core/networks.py +38 -0
  28. typed_margin_trade-0.1.0/src/typed_margin_trade/core/transport/__init__.py +1 -0
  29. typed_margin_trade-0.1.0/src/typed_margin_trade/core/transport/http.py +111 -0
  30. typed_margin_trade-0.1.0/src/typed_margin_trade/core/transport/ws.py +374 -0
  31. typed_margin_trade-0.1.0/src/typed_margin_trade/core/types.py +29 -0
  32. typed_margin_trade-0.1.0/src/typed_margin_trade/exchange/__init__.py +34 -0
  33. typed_margin_trade-0.1.0/src/typed_margin_trade/exchange/approve_agent.py +51 -0
  34. typed_margin_trade-0.1.0/src/typed_margin_trade/exchange/approve_agent_v2.py +63 -0
  35. typed_margin_trade-0.1.0/src/typed_margin_trade/exchange/batch_modify.py +50 -0
  36. typed_margin_trade-0.1.0/src/typed_margin_trade/exchange/cancel.py +53 -0
  37. typed_margin_trade-0.1.0/src/typed_margin_trade/exchange/cancel_by_cloid.py +53 -0
  38. typed_margin_trade-0.1.0/src/typed_margin_trade/exchange/get_agents.py +46 -0
  39. typed_margin_trade-0.1.0/src/typed_margin_trade/exchange/modify.py +54 -0
  40. typed_margin_trade-0.1.0/src/typed_margin_trade/exchange/order.py +54 -0
  41. typed_margin_trade-0.1.0/src/typed_margin_trade/exchange/revoke_agent.py +34 -0
  42. typed_margin_trade-0.1.0/src/typed_margin_trade/exchange/update_leverage.py +45 -0
  43. typed_margin_trade-0.1.0/src/typed_margin_trade/exchange/usd_class_transfer.py +42 -0
  44. typed_margin_trade-0.1.0/src/typed_margin_trade/exchange/withdraw.py +55 -0
  45. typed_margin_trade-0.1.0/src/typed_margin_trade/info/__init__.py +60 -0
  46. typed_margin_trade-0.1.0/src/typed_margin_trade/info/active_asset_data.py +42 -0
  47. typed_margin_trade-0.1.0/src/typed_margin_trade/info/all_mids.py +28 -0
  48. typed_margin_trade-0.1.0/src/typed_margin_trade/info/candle_snapshot.py +94 -0
  49. typed_margin_trade-0.1.0/src/typed_margin_trade/info/clearinghouse_state.py +45 -0
  50. typed_margin_trade-0.1.0/src/typed_margin_trade/info/deposit_history.py +63 -0
  51. typed_margin_trade-0.1.0/src/typed_margin_trade/info/frontend_open_orders.py +80 -0
  52. typed_margin_trade-0.1.0/src/typed_margin_trade/info/get_liquidation_feed.py +166 -0
  53. typed_margin_trade-0.1.0/src/typed_margin_trade/info/get_liquidations.py +144 -0
  54. typed_margin_trade-0.1.0/src/typed_margin_trade/info/historical_orders.py +38 -0
  55. typed_margin_trade-0.1.0/src/typed_margin_trade/info/l2_book.py +51 -0
  56. typed_margin_trade-0.1.0/src/typed_margin_trade/info/mark_price_snapshot.py +54 -0
  57. typed_margin_trade-0.1.0/src/typed_margin_trade/info/market_metadata.py +60 -0
  58. typed_margin_trade-0.1.0/src/typed_margin_trade/info/meta.py +25 -0
  59. typed_margin_trade-0.1.0/src/typed_margin_trade/info/meta_and_asset_ctxs.py +32 -0
  60. typed_margin_trade-0.1.0/src/typed_margin_trade/info/open_orders.py +66 -0
  61. typed_margin_trade-0.1.0/src/typed_margin_trade/info/order_status.py +70 -0
  62. typed_margin_trade-0.1.0/src/typed_margin_trade/info/perp_dex_status.py +42 -0
  63. typed_margin_trade-0.1.0/src/typed_margin_trade/info/spot_clearinghouse_state.py +45 -0
  64. typed_margin_trade-0.1.0/src/typed_margin_trade/info/spot_meta.py +25 -0
  65. typed_margin_trade-0.1.0/src/typed_margin_trade/info/spot_meta_and_asset_ctxs.py +32 -0
  66. typed_margin_trade-0.1.0/src/typed_margin_trade/info/user_fees.py +85 -0
  67. typed_margin_trade-0.1.0/src/typed_margin_trade/info/user_fills.py +48 -0
  68. typed_margin_trade-0.1.0/src/typed_margin_trade/info/user_fills_by_time.py +155 -0
  69. typed_margin_trade-0.1.0/src/typed_margin_trade/info/user_funding.py +78 -0
  70. typed_margin_trade-0.1.0/src/typed_margin_trade/info/withdrawal_history.py +65 -0
  71. typed_margin_trade-0.1.0/src/typed_margin_trade/main.py +81 -0
  72. typed_margin_trade-0.1.0/src/typed_margin_trade/public/__init__.py +24 -0
  73. typed_margin_trade-0.1.0/src/typed_margin_trade/public/announcements/__init__.py +11 -0
  74. typed_margin_trade-0.1.0/src/typed_margin_trade/public/announcements/detail.py +52 -0
  75. typed_margin_trade-0.1.0/src/typed_margin_trade/public/announcements/list.py +112 -0
  76. typed_margin_trade-0.1.0/src/typed_margin_trade/public/health.py +27 -0
  77. typed_margin_trade-0.1.0/src/typed_margin_trade/public/leaderboard.py +61 -0
  78. typed_margin_trade-0.1.0/src/typed_margin_trade/public/region_availability.py +38 -0
  79. typed_margin_trade-0.1.0/src/typed_margin_trade/public/version.py +41 -0
  80. typed_margin_trade-0.1.0/src/typed_margin_trade/py.typed +0 -0
  81. typed_margin_trade-0.1.0/src/typed_margin_trade/schemas.py +563 -0
  82. typed_margin_trade-0.1.0/src/typed_margin_trade/solana/__init__.py +11 -0
  83. typed_margin_trade-0.1.0/src/typed_margin_trade/solana/get_onchain_asset.py +53 -0
  84. typed_margin_trade-0.1.0/src/typed_margin_trade/solana/send_transaction.py +79 -0
  85. typed_margin_trade-0.1.0/src/typed_margin_trade/streams/__init__.py +30 -0
  86. typed_margin_trade-0.1.0/src/typed_margin_trade/streams/active_asset_data.py +43 -0
  87. typed_margin_trade-0.1.0/src/typed_margin_trade/streams/all_mids.py +50 -0
  88. typed_margin_trade-0.1.0/src/typed_margin_trade/streams/bbo.py +54 -0
  89. typed_margin_trade-0.1.0/src/typed_margin_trade/streams/candle.py +99 -0
  90. typed_margin_trade-0.1.0/src/typed_margin_trade/streams/l2_book.py +52 -0
  91. typed_margin_trade-0.1.0/src/typed_margin_trade/streams/mark_price.py +43 -0
  92. typed_margin_trade-0.1.0/src/typed_margin_trade/streams/order_updates.py +49 -0
  93. typed_margin_trade-0.1.0/src/typed_margin_trade/streams/trades.py +65 -0
  94. typed_margin_trade-0.1.0/src/typed_margin_trade/streams/user_fills.py +61 -0
  95. typed_margin_trade-0.1.0/src/typed_margin_trade/streams/web_data3.py +136 -0
  96. typed_margin_trade-0.1.0/src/typed_margin_trade/user/__init__.py +40 -0
  97. typed_margin_trade-0.1.0/src/typed_margin_trade/user/create_invite_code.py +38 -0
  98. typed_margin_trade-0.1.0/src/typed_margin_trade/user/faucet_claim.py +36 -0
  99. typed_margin_trade-0.1.0/src/typed_margin_trade/user/get_claim_info.py +52 -0
  100. typed_margin_trade-0.1.0/src/typed_margin_trade/user/get_deposit_address.py +54 -0
  101. typed_margin_trade-0.1.0/src/typed_margin_trade/user/get_following_list.py +42 -0
  102. typed_margin_trade-0.1.0/src/typed_margin_trade/user/get_my_invite_code.py +38 -0
  103. typed_margin_trade-0.1.0/src/typed_margin_trade/user/get_performance.py +67 -0
  104. typed_margin_trade-0.1.0/src/typed_margin_trade/user/get_pnl_history.py +77 -0
  105. typed_margin_trade-0.1.0/src/typed_margin_trade/user/get_referral_details.py +115 -0
  106. typed_margin_trade-0.1.0/src/typed_margin_trade/user/get_today_data.py +46 -0
  107. typed_margin_trade-0.1.0/src/typed_margin_trade/user/get_transfer_history.py +98 -0
  108. typed_margin_trade-0.1.0/src/typed_margin_trade/user/get_user.py +50 -0
  109. typed_margin_trade-0.1.0/src/typed_margin_trade/user/get_user_trade_vol.py +45 -0
  110. typed_margin_trade-0.1.0/src/typed_margin_trade/user/redeem_invite_code.py +44 -0
  111. typed_margin_trade-0.1.0/src/typed_margin_trade/user/set_follow.py +48 -0
  112. typed_margin_trade-0.1.0/src/typed_margin_trade.egg-info/PKG-INFO +112 -0
  113. typed_margin_trade-0.1.0/src/typed_margin_trade.egg-info/SOURCES.txt +114 -0
  114. typed_margin_trade-0.1.0/src/typed_margin_trade.egg-info/dependency_links.txt +1 -0
  115. typed_margin_trade-0.1.0/src/typed_margin_trade.egg-info/requires.txt +8 -0
  116. typed_margin_trade-0.1.0/src/typed_margin_trade.egg-info/top_level.txt +1 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Tribulnation Labs
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,112 @@
1
+ Metadata-Version: 2.4
2
+ Name: typed-margin_trade
3
+ Version: 0.1.0
4
+ Summary: A fully typed, validated async client for the Margin Trade API.
5
+ Author-email: Marcel Claramunt <marcel@tribulnation.com>
6
+ License-Expression: MIT
7
+ Project-URL: Repository, https://github.com/tribulnation/typed
8
+ Project-URL: Documentation, https://tribulnation.com/typed/margin_trade
9
+ Project-URL: Website, https://tribulnation.com/typed
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Typing :: Typed
14
+ Requires-Python: >=3.10
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+ Requires-Dist: typed-core>=0.11
18
+ Requires-Dist: lazy-loader
19
+ Requires-Dist: httpx
20
+ Requires-Dist: pydantic
21
+ Requires-Dist: websockets
22
+ Requires-Dist: cryptography
23
+ Requires-Dist: base58
24
+ Requires-Dist: rfc8785
25
+ Dynamic: license-file
26
+
27
+ # Typed Margin Trade
28
+
29
+ <p align="center">
30
+ <em>A fully typed, validated async client for the Margin Trade API.</em>
31
+ </p>
32
+
33
+ <p align="center">
34
+ <a href="https://pypi.org/project/typed-margin_trade/">
35
+ <img src="https://img.shields.io/pypi/v/typed-margin_trade.svg" alt="PyPI version">
36
+ </a>
37
+ <a href="https://pypi.org/project/typed-margin_trade/">
38
+ <img src="https://img.shields.io/pypi/pyversions/typed-margin_trade.svg" alt="Python versions">
39
+ </a>
40
+ <a href="https://tribulnation.com/typed/margin_trade">
41
+ <img src="https://img.shields.io/badge/docs-live-black" alt="Docs">
42
+ </a>
43
+ <a href="LICENSE">
44
+ <img src="https://img.shields.io/pypi/l/typed-margin_trade.svg" alt="License">
45
+ </a>
46
+ </p>
47
+
48
+ ---
49
+
50
+ - **Documentation**: [https://tribulnation.com/typed/margin_trade](https://tribulnation.com/typed/margin_trade)
51
+ - **Source Code**: [https://github.com/tribulnation/typed/tree/main/packages/margin_trade](https://github.com/tribulnation/typed/tree/main/packages/margin_trade)
52
+
53
+ ---
54
+
55
+ ```python
56
+ from typed_margin_trade import MarginTrade
57
+
58
+ async with MarginTrade.new(public=True) as client:
59
+ book = await client.info.l2_book('BTC')
60
+ bids, asks = book['levels'] or ([], []) # an empty book answers `levels: []`
61
+ if bids and asks:
62
+ print(bids[0]['px'], asks[0]['px'])
63
+ ```
64
+
65
+ ## Why Typed Margin Trade?
66
+
67
+ - **🎯 Precise Types**: Typed requests and responses for every `info`, `exchange`, `user`, `solana`, `public` and CoinGecko call and WebSocket channel the client supports, not `dict`/`Any`; only a few nested lists the venue has only ever sent empty (fee tiers, order `children`) stay loosely typed.
68
+ - **✅ Runtime Validation**: Responses and stream pushes validated by default, with prices and sizes parsed to `Decimal` and timestamps to `datetime`.
69
+ - **⚡ Async First**: Async HTTP and WebSocket streaming over one shared connection each, with Ed25519 signing built in.
70
+ - **📚 Full Surface**: Market data, trading, agent wallets, transfers, withdrawals, account history, referrals and the testnet faucet, not just the popular calls.
71
+
72
+ ## Installation
73
+
74
+ ```bash
75
+ pip install typed-margin_trade
76
+ ```
77
+
78
+ ## Testnet And Mainnet
79
+
80
+ The client talks to mainnet by default. Pass `mainnet=False` for testnet: it picks the
81
+ testnet host and signs every request for testnet, so a signed request is only valid on the network you chose.
82
+ Testnet accounts can claim test USDC daily with `user.faucet_claim()`. The examples in these
83
+ docs use testnet and read the key from `MARGIN_TRADE_TESTNET_PRIVATE_KEY`; see
84
+ [Authenticated Setup](https://tribulnation.com/typed/margin_trade/authenticated-setup).
85
+
86
+ ```python
87
+ from typed_margin_trade import MarginTrade
88
+
89
+ async with MarginTrade.new(public=True, mainnet=False) as client:
90
+ mids = await client.info.all_mids() # testnet prices
91
+ ```
92
+
93
+ ## How To
94
+
95
+ - [Fetch Market Data](https://tribulnation.com/typed/margin_trade/how-to/fetch-market-data)
96
+ - [Fetch Account Data](https://tribulnation.com/typed/margin_trade/how-to/fetch-account-data)
97
+ - [Place & Manage Orders](https://tribulnation.com/typed/margin_trade/how-to/place-and-manage-orders)
98
+ - [Paginate Through Results](https://tribulnation.com/typed/margin_trade/how-to/paginate-through-results)
99
+ - [Listen To Live Streams](https://tribulnation.com/typed/margin_trade/how-to/listen-to-live-streams)
100
+ - [Manage Deposits & Withdrawals](https://tribulnation.com/typed/margin_trade/how-to/manage-deposits-withdrawals)
101
+
102
+ ## Reference
103
+
104
+ - [Authenticated Setup](https://tribulnation.com/typed/margin_trade/authenticated-setup)
105
+ - [Async Usage](https://tribulnation.com/typed/margin_trade/reference/async-usage)
106
+ - [Error Handling](https://tribulnation.com/typed/margin_trade/reference/error-handling)
107
+ - [Environment Variables](https://tribulnation.com/typed/margin_trade/reference/env-vars)
108
+ - [Timestamps](https://tribulnation.com/typed/margin_trade/reference/timestamps)
109
+
110
+ ## License
111
+
112
+ MIT — see [LICENSE](LICENSE).
@@ -0,0 +1,86 @@
1
+ # Typed Margin Trade
2
+
3
+ <p align="center">
4
+ <em>A fully typed, validated async client for the Margin Trade API.</em>
5
+ </p>
6
+
7
+ <p align="center">
8
+ <a href="https://pypi.org/project/typed-margin_trade/">
9
+ <img src="https://img.shields.io/pypi/v/typed-margin_trade.svg" alt="PyPI version">
10
+ </a>
11
+ <a href="https://pypi.org/project/typed-margin_trade/">
12
+ <img src="https://img.shields.io/pypi/pyversions/typed-margin_trade.svg" alt="Python versions">
13
+ </a>
14
+ <a href="https://tribulnation.com/typed/margin_trade">
15
+ <img src="https://img.shields.io/badge/docs-live-black" alt="Docs">
16
+ </a>
17
+ <a href="LICENSE">
18
+ <img src="https://img.shields.io/pypi/l/typed-margin_trade.svg" alt="License">
19
+ </a>
20
+ </p>
21
+
22
+ ---
23
+
24
+ - **Documentation**: [https://tribulnation.com/typed/margin_trade](https://tribulnation.com/typed/margin_trade)
25
+ - **Source Code**: [https://github.com/tribulnation/typed/tree/main/packages/margin_trade](https://github.com/tribulnation/typed/tree/main/packages/margin_trade)
26
+
27
+ ---
28
+
29
+ ```python
30
+ from typed_margin_trade import MarginTrade
31
+
32
+ async with MarginTrade.new(public=True) as client:
33
+ book = await client.info.l2_book('BTC')
34
+ bids, asks = book['levels'] or ([], []) # an empty book answers `levels: []`
35
+ if bids and asks:
36
+ print(bids[0]['px'], asks[0]['px'])
37
+ ```
38
+
39
+ ## Why Typed Margin Trade?
40
+
41
+ - **🎯 Precise Types**: Typed requests and responses for every `info`, `exchange`, `user`, `solana`, `public` and CoinGecko call and WebSocket channel the client supports, not `dict`/`Any`; only a few nested lists the venue has only ever sent empty (fee tiers, order `children`) stay loosely typed.
42
+ - **✅ Runtime Validation**: Responses and stream pushes validated by default, with prices and sizes parsed to `Decimal` and timestamps to `datetime`.
43
+ - **⚡ Async First**: Async HTTP and WebSocket streaming over one shared connection each, with Ed25519 signing built in.
44
+ - **📚 Full Surface**: Market data, trading, agent wallets, transfers, withdrawals, account history, referrals and the testnet faucet, not just the popular calls.
45
+
46
+ ## Installation
47
+
48
+ ```bash
49
+ pip install typed-margin_trade
50
+ ```
51
+
52
+ ## Testnet And Mainnet
53
+
54
+ The client talks to mainnet by default. Pass `mainnet=False` for testnet: it picks the
55
+ testnet host and signs every request for testnet, so a signed request is only valid on the network you chose.
56
+ Testnet accounts can claim test USDC daily with `user.faucet_claim()`. The examples in these
57
+ docs use testnet and read the key from `MARGIN_TRADE_TESTNET_PRIVATE_KEY`; see
58
+ [Authenticated Setup](https://tribulnation.com/typed/margin_trade/authenticated-setup).
59
+
60
+ ```python
61
+ from typed_margin_trade import MarginTrade
62
+
63
+ async with MarginTrade.new(public=True, mainnet=False) as client:
64
+ mids = await client.info.all_mids() # testnet prices
65
+ ```
66
+
67
+ ## How To
68
+
69
+ - [Fetch Market Data](https://tribulnation.com/typed/margin_trade/how-to/fetch-market-data)
70
+ - [Fetch Account Data](https://tribulnation.com/typed/margin_trade/how-to/fetch-account-data)
71
+ - [Place & Manage Orders](https://tribulnation.com/typed/margin_trade/how-to/place-and-manage-orders)
72
+ - [Paginate Through Results](https://tribulnation.com/typed/margin_trade/how-to/paginate-through-results)
73
+ - [Listen To Live Streams](https://tribulnation.com/typed/margin_trade/how-to/listen-to-live-streams)
74
+ - [Manage Deposits & Withdrawals](https://tribulnation.com/typed/margin_trade/how-to/manage-deposits-withdrawals)
75
+
76
+ ## Reference
77
+
78
+ - [Authenticated Setup](https://tribulnation.com/typed/margin_trade/authenticated-setup)
79
+ - [Async Usage](https://tribulnation.com/typed/margin_trade/reference/async-usage)
80
+ - [Error Handling](https://tribulnation.com/typed/margin_trade/reference/error-handling)
81
+ - [Environment Variables](https://tribulnation.com/typed/margin_trade/reference/env-vars)
82
+ - [Timestamps](https://tribulnation.com/typed/margin_trade/reference/timestamps)
83
+
84
+ ## License
85
+
86
+ MIT — see [LICENSE](LICENSE).
@@ -0,0 +1,33 @@
1
+ [build-system]
2
+ requires = ["setuptools", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "typed-margin_trade"
7
+ version = "0.1.0"
8
+ authors = [
9
+ {name="Marcel Claramunt", email="marcel@tribulnation.com"}
10
+ ]
11
+ description = "A fully typed, validated async client for the Margin Trade API."
12
+ license = "MIT"
13
+ license-files = ["LICENSE"]
14
+ classifiers = [
15
+ "Programming Language :: Python :: 3",
16
+ "Programming Language :: Python :: 3.10",
17
+ "Programming Language :: Python :: 3.11",
18
+ "Typing :: Typed",
19
+ ]
20
+ dependencies = [
21
+ "typed-core>=0.11", "lazy-loader", "httpx", "pydantic", "websockets",
22
+ "cryptography", "base58", "rfc8785",
23
+ ]
24
+ requires-python = ">=3.10"
25
+ readme = {file="README.md", content-type="text/markdown"}
26
+
27
+ [tool.setuptools.package-data]
28
+ "typed_margin_trade" = ["py.typed", "*.pyi", "**/*.pyi"]
29
+
30
+ [project.urls]
31
+ Repository = "https://github.com/tribulnation/typed"
32
+ Documentation = "https://tribulnation.com/typed/margin_trade"
33
+ Website = "https://tribulnation.com/typed"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,14 @@
1
+ """A fully typed, validated async client for the Margin Trade API.
2
+
3
+ Examples:
4
+ ```python
5
+ from typed_margin_trade import MarginTrade
6
+
7
+ async with MarginTrade.new(public=True) as client:
8
+ book = await client.info.l2_book('BTC')
9
+ ```
10
+ """
11
+
12
+ import lazy_loader as lazy
13
+
14
+ __getattr__, __dir__, __all__ = lazy.attach_stub(__name__, __file__)
@@ -0,0 +1,28 @@
1
+ from .main import MarginTrade
2
+ from .core import (
3
+ Error,
4
+ NetworkError,
5
+ ValidationError,
6
+ ApiError,
7
+ BadRequest,
8
+ AuthError,
9
+ RateLimited,
10
+ LogicError,
11
+ Wallet,
12
+ )
13
+ from .core.auth import AgentConsent, agent_consent
14
+
15
+ __all__ = [
16
+ 'MarginTrade',
17
+ 'Error',
18
+ 'NetworkError',
19
+ 'ValidationError',
20
+ 'ApiError',
21
+ 'BadRequest',
22
+ 'AuthError',
23
+ 'RateLimited',
24
+ 'LogicError',
25
+ 'Wallet',
26
+ 'AgentConsent',
27
+ 'agent_consent',
28
+ ]
@@ -0,0 +1,31 @@
1
+ # Generated by typed-dev — see CONTRIBUTING.md.
2
+ from functools import cached_property
3
+ from .derivatives import Derivatives
4
+ from .spot import Spot
5
+ from typed_margin_trade.core.endpoint.rpc import RpcEndpoint
6
+
7
+
8
+ class Coingecko(RpcEndpoint):
9
+ """CoinGecko-integration-standard listing endpoints: unauthenticated `GET` with snake_case query parameters, for derivatives (perpetuals) and spot pairs.
10
+
11
+ References:
12
+ - [Upstream docs](https://docs.margin.trade/api/coingecko)
13
+ """
14
+
15
+ @cached_property
16
+ def derivatives(self) -> Derivatives:
17
+ """CoinGecko-standard data for every perpetual contract: tickers with funding and open interest, contract specifications, and order books (ticker ids like `BTC-USD`).
18
+
19
+ References:
20
+ - [Upstream docs](https://docs.margin.trade/api/coingecko)
21
+ """
22
+ return Derivatives(client=self.client)
23
+
24
+ @cached_property
25
+ def spot(self) -> Spot:
26
+ """CoinGecko-standard data for spot pairs (currently `PRL_USDC`): 24h tickers, order books, and recent trades.
27
+
28
+ References:
29
+ - [Upstream docs](https://docs.margin.trade/api/coingecko)
30
+ """
31
+ return Spot(client=self.client)
@@ -0,0 +1,12 @@
1
+ # Generated by typed-dev — see CONTRIBUTING.md.
2
+ from .contract_specs import ContractSpecs
3
+ from .contracts import Contracts
4
+ from .orderbook import Orderbook
5
+
6
+
7
+ class Derivatives(ContractSpecs, Contracts, Orderbook):
8
+ """CoinGecko-standard data for every perpetual contract: tickers with funding and open interest, contract specifications, and order books (ticker ids like `BTC-USD`).
9
+
10
+ References:
11
+ - [Upstream docs](https://docs.margin.trade/api/coingecko)
12
+ """
@@ -0,0 +1,42 @@
1
+ # Generated by typed-dev — see CONTRIBUTING.md.
2
+ from decimal import Decimal
3
+ from typing_extensions import Literal, TypedDict
4
+ from typed_margin_trade.core.endpoint.rpc import RpcEndpoint
5
+
6
+
7
+ class ContractSpec(TypedDict):
8
+ """Contract specification."""
9
+
10
+ ticker_id: str
11
+ """Contract id, e.g. `BTC-USD`."""
12
+ contract_type: Literal['Vanilla']
13
+ """Contract type (linear)."""
14
+ contract_price: Decimal
15
+ """Contract price."""
16
+ contract_price_currency: Literal['USD']
17
+ """Contract price currency (`USD`)."""
18
+
19
+
20
+ Response = list[ContractSpec]
21
+
22
+
23
+ class ContractSpecs(RpcEndpoint):
24
+ """List the contract specification of every perpetual (all linear, USDC-margined, USD-priced)."""
25
+
26
+ async def contract_specs(self, *, validate: bool | None = None) -> Response:
27
+ """List the contract specification of every perpetual (all linear, USDC-margined, USD-priced).
28
+
29
+ Args:
30
+ validate: Override this call's response validation; falls back to the client-level default when omitted.
31
+
32
+ References:
33
+ - [Official docs](https://docs.margin.trade/api/coingecko)
34
+ """
35
+ return await self.request(
36
+ None,
37
+ method='GET',
38
+ path='/coingecko/derivatives/contract_specs',
39
+ meta={},
40
+ validate=validate,
41
+ response_type=Response,
42
+ )
@@ -0,0 +1,79 @@
1
+ # Generated by typed-dev — see CONTRIBUTING.md.
2
+ from decimal import Decimal
3
+ from typing_extensions import Literal, NotRequired, TypedDict
4
+ from typed_margin_trade.core import TimestampMillis
5
+ from typed_margin_trade.core.endpoint.rpc import RpcEndpoint
6
+
7
+
8
+ class DerivativeContract(TypedDict):
9
+ """One perpetual contract, in the CoinGecko integration format."""
10
+
11
+ ticker_id: str
12
+ """Contract id, e.g. `BTC-USD`."""
13
+ base_currency: str
14
+ """Base asset, e.g. `BTC`."""
15
+ target_currency: Literal['USD']
16
+ """Quote currency (`USD`)."""
17
+ product_type: Literal['Perpetual']
18
+ """Product type."""
19
+ last_price: Decimal
20
+ """Last traded price."""
21
+ base_volume: Decimal
22
+ """24h volume, base asset."""
23
+ target_volume: Decimal
24
+ """24h volume, USD."""
25
+ bid: NotRequired[Decimal]
26
+ """Best bid; absent when the book has no bids."""
27
+ ask: NotRequired[Decimal]
28
+ """Best ask; absent when the book has no asks."""
29
+ high: NotRequired[Decimal]
30
+ """24h high; absent with no trades in the last 24h."""
31
+ low: NotRequired[Decimal]
32
+ """24h low; absent with no trades in the last 24h."""
33
+ open_interest: Decimal
34
+ """Open interest, base asset."""
35
+ open_interest_usd: Decimal
36
+ """Open interest, USD."""
37
+ index_price: Decimal
38
+ """Oracle (index) price."""
39
+ index_name: str
40
+ """Index id, e.g. `BTC-USD`."""
41
+ index_currency: str
42
+ """Index currency (`USD`)."""
43
+ funding_rate: float
44
+ """Current funding rate, as a fraction (a JSON number on the wire, unlike the other values)."""
45
+ next_funding_rate: float
46
+ """Predicted next funding rate, as a fraction (a JSON number)."""
47
+ next_funding_rate_timestamp: TimestampMillis
48
+ """Next funding settlement."""
49
+ contract_type: Literal['Vanilla']
50
+ """Contract type (linear)."""
51
+ contract_price: Decimal
52
+ """Contract price."""
53
+ contract_price_currency: Literal['USD']
54
+ """Contract price currency (`USD`)."""
55
+
56
+
57
+ Response = list[DerivativeContract]
58
+
59
+
60
+ class Contracts(RpcEndpoint):
61
+ """List every active perpetual with last price, 24h volume and range, best bid/ask, open interest, index price and funding."""
62
+
63
+ async def contracts(self, *, validate: bool | None = None) -> Response:
64
+ """List every active perpetual with last price, 24h volume and range, best bid/ask, open interest, index price and funding.
65
+
66
+ Args:
67
+ validate: Override this call's response validation; falls back to the client-level default when omitted.
68
+
69
+ References:
70
+ - [Official docs](https://docs.margin.trade/api/coingecko)
71
+ """
72
+ return await self.request(
73
+ None,
74
+ method='GET',
75
+ path='/coingecko/derivatives/contracts',
76
+ meta={},
77
+ validate=validate,
78
+ response_type=Response,
79
+ )
@@ -0,0 +1,47 @@
1
+ # Generated by typed-dev — see CONTRIBUTING.md.
2
+ from typing_extensions import NotRequired, TypedDict
3
+ from typed_margin_trade.core.endpoint.rpc import RpcEndpoint
4
+ from typed_margin_trade.schemas import CoinGeckoOrderBook
5
+
6
+
7
+ class Request(TypedDict):
8
+ """Order book selection."""
9
+
10
+ ticker_id: str
11
+ """Contract id, e.g. `BTC-USD`."""
12
+ depth: NotRequired[int]
13
+ """Total number of levels across both sides, split evenly; `0` returns the full book (capped)."""
14
+
15
+
16
+ class Orderbook(RpcEndpoint):
17
+ """Fetch a perpetual's order book as `[price, size]` levels, best first."""
18
+
19
+ async def orderbook(
20
+ self,
21
+ ticker_id: str,
22
+ *,
23
+ depth: int | None = None,
24
+ validate: bool | None = None,
25
+ ) -> CoinGeckoOrderBook:
26
+ """Fetch a perpetual's order book as `[price, size]` levels, best first.
27
+
28
+ Args:
29
+ ticker_id: Contract id, e.g. `BTC-USD`.
30
+ depth: Total number of levels across both sides, split evenly; `0` returns the full book (capped).
31
+ validate: Override this call's response validation; falls back to the client-level default when omitted.
32
+
33
+ References:
34
+ - [Official docs](https://docs.margin.trade/api/coingecko)
35
+ """
36
+ request: Request = Request(ticker_id=ticker_id)
37
+ if depth is not None:
38
+ request['depth'] = depth
39
+ return await self.request(
40
+ request,
41
+ method='GET',
42
+ path='/coingecko/derivatives/orderbook',
43
+ meta={},
44
+ validate=validate,
45
+ request_type=Request,
46
+ response_type=CoinGeckoOrderBook,
47
+ )
@@ -0,0 +1,12 @@
1
+ # Generated by typed-dev — see CONTRIBUTING.md.
2
+ from .historical_trades import HistoricalTrades
3
+ from .orderbook import Orderbook
4
+ from .tickers import Tickers
5
+
6
+
7
+ class Spot(HistoricalTrades, Orderbook, Tickers):
8
+ """CoinGecko-standard data for spot pairs (currently `PRL_USDC`): 24h tickers, order books, and recent trades.
9
+
10
+ References:
11
+ - [Upstream docs](https://docs.margin.trade/api/coingecko)
12
+ """
@@ -0,0 +1,109 @@
1
+ # Generated by typed-dev — see CONTRIBUTING.md.
2
+ from decimal import Decimal
3
+ from typing_extensions import Literal, NotRequired, TypedDict
4
+ from typed_margin_trade.core import TimestampMillis
5
+ from typed_margin_trade.core.endpoint.rpc import RpcEndpoint
6
+
7
+
8
+ class BuyTrade(TypedDict):
9
+ """One buy trade."""
10
+
11
+ trade_id: int
12
+ """Trade id."""
13
+ price: Decimal
14
+ """Trade price."""
15
+ base_volume: Decimal
16
+ """Traded size, base asset."""
17
+ target_volume: Decimal
18
+ """Traded value, quote asset."""
19
+ trade_timestamp: TimestampMillis
20
+ """Trade time."""
21
+ type: Literal['buy']
22
+ """Taker side."""
23
+
24
+
25
+ class Request(TypedDict):
26
+ """Trade selection."""
27
+
28
+ ticker_id: str
29
+ """Pair id, e.g. `PRL_USDC`."""
30
+ type: NotRequired[Literal['buy', 'sell']]
31
+ """Only this side; both when omitted."""
32
+ limit: NotRequired[int]
33
+ """Maximum trades returned across both sides; larger values are capped at 1000."""
34
+ start_time: NotRequired[TimestampMillis]
35
+ """Earliest trade time."""
36
+ end_time: NotRequired[TimestampMillis]
37
+ """Latest trade time (inclusive); now when omitted."""
38
+
39
+
40
+ class SellTrade(TypedDict):
41
+ """One sell trade."""
42
+
43
+ trade_id: int
44
+ """Trade id."""
45
+ price: Decimal
46
+ """Trade price."""
47
+ base_volume: Decimal
48
+ """Traded size, base asset."""
49
+ target_volume: Decimal
50
+ """Traded value, quote asset."""
51
+ trade_timestamp: TimestampMillis
52
+ """Trade time."""
53
+ type: Literal['sell']
54
+ """Taker side."""
55
+
56
+
57
+ class SpotHistoricalTrades(TypedDict):
58
+ """Trades grouped by side."""
59
+
60
+ buy: NotRequired[list[BuyTrade]]
61
+ """Buy trades, newest first; absent when `type` is `sell`."""
62
+ sell: NotRequired[list[SellTrade]]
63
+ """Sell trades, newest first; absent when `type` is `buy`."""
64
+
65
+
66
+ class HistoricalTrades(RpcEndpoint):
67
+ """Fetch a spot pair's most recent trades in a time range, newest first, split into `buy` and `sell` lists."""
68
+
69
+ async def historical_trades(
70
+ self,
71
+ ticker_id: str,
72
+ *,
73
+ type: Literal['buy', 'sell'] | None = None,
74
+ limit: int | None = None,
75
+ start_time: TimestampMillis | None = None,
76
+ end_time: TimestampMillis | None = None,
77
+ validate: bool | None = None,
78
+ ) -> SpotHistoricalTrades:
79
+ """Fetch a spot pair's most recent trades in a time range, newest first, split into `buy` and `sell` lists.
80
+
81
+ Args:
82
+ ticker_id: Pair id, e.g. `PRL_USDC`.
83
+ type: Only this side; both when omitted.
84
+ limit: Maximum trades returned across both sides; larger values are capped at 1000.
85
+ start_time: Earliest trade time.
86
+ end_time: Latest trade time (inclusive); now when omitted.
87
+ validate: Override this call's response validation; falls back to the client-level default when omitted.
88
+
89
+ References:
90
+ - [Official docs](https://docs.margin.trade/api/coingecko)
91
+ """
92
+ request: Request = Request(ticker_id=ticker_id)
93
+ if type is not None:
94
+ request['type'] = type
95
+ if limit is not None:
96
+ request['limit'] = limit
97
+ if start_time is not None:
98
+ request['start_time'] = start_time
99
+ if end_time is not None:
100
+ request['end_time'] = end_time
101
+ return await self.request(
102
+ request,
103
+ method='GET',
104
+ path='/coingecko/spot/historical_trades',
105
+ meta={},
106
+ validate=validate,
107
+ request_type=Request,
108
+ response_type=SpotHistoricalTrades,
109
+ )