crypticorn-utils 0.1.0rc1__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.
@@ -0,0 +1,175 @@
1
+ """Defines common enumerations used throughout the codebase for type safety and consistency."""
2
+
3
+ try:
4
+ from enum import StrEnum
5
+ except ImportError:
6
+ from strenum import StrEnum
7
+
8
+ import warnings
9
+
10
+ from crypticorn_utils.mixins import ValidateEnumMixin
11
+ from crypticorn_utils.warnings import CrypticornDeprecatedSince215
12
+
13
+
14
+ class Scope(StrEnum):
15
+ """
16
+ The permission scopes for the API.
17
+ """
18
+
19
+ # If you update anything here, also update the scopes in the auth-service repository
20
+
21
+ WRITE_ADMIN = "write:admin"
22
+ READ_ADMIN = "read:admin"
23
+
24
+ # Scopes that can be purchased - these actually exist in the jwt token
25
+ READ_PREDICTIONS = "read:predictions"
26
+ READ_DEX_SIGNALS = "read:dex:signals"
27
+
28
+ # Hive scopes
29
+ READ_HIVE_MODEL = "read:hive:model"
30
+ READ_HIVE_DATA = "read:hive:data"
31
+ WRITE_HIVE_MODEL = "write:hive:model"
32
+
33
+ # Trade scopes
34
+ READ_TRADE_BOTS = "read:trade:bots"
35
+ WRITE_TRADE_BOTS = "write:trade:bots"
36
+ READ_TRADE_EXCHANGEKEYS = "read:trade:exchangekeys"
37
+ WRITE_TRADE_EXCHANGEKEYS = "write:trade:exchangekeys"
38
+ READ_TRADE_ORDERS = "read:trade:orders"
39
+ READ_TRADE_ACTIONS = "read:trade:actions"
40
+ WRITE_TRADE_ACTIONS = "write:trade:actions"
41
+ READ_TRADE_EXCHANGES = "read:trade:exchanges"
42
+ READ_TRADE_FUTURES = "read:trade:futures"
43
+ WRITE_TRADE_FUTURES = "write:trade:futures"
44
+ READ_TRADE_NOTIFICATIONS = "read:trade:notifications"
45
+ WRITE_TRADE_NOTIFICATIONS = "write:trade:notifications"
46
+ READ_TRADE_STRATEGIES = "read:trade:strategies"
47
+ WRITE_TRADE_STRATEGIES = "write:trade:strategies"
48
+
49
+ # Payment scopes
50
+ READ_PAY_PAYMENTS = "read:pay:payments"
51
+ READ_PAY_PRODUCTS = "read:pay:products"
52
+ WRITE_PAY_PRODUCTS = "write:pay:products"
53
+ READ_PAY_NOW = "read:pay:now"
54
+ WRITE_PAY_NOW = "write:pay:now"
55
+ WRITE_PAY_COUPONS = "write:pay:coupons"
56
+ READ_PAY_COUPONS = "read:pay:coupons"
57
+
58
+ # Metrics scopes
59
+ READ_METRICS_MARKETCAP = "read:metrics:marketcap"
60
+ READ_METRICS_INDICATORS = "read:metrics:indicators"
61
+ READ_METRICS_EXCHANGES = "read:metrics:exchanges"
62
+ READ_METRICS_TOKENS = "read:metrics:tokens"
63
+ READ_METRICS_MARKETS = "read:metrics:markets"
64
+
65
+ # Sentiment scopes
66
+ READ_SENTIMENT = "read:sentiment"
67
+
68
+ # Klines scopes
69
+ READ_KLINES = "read:klines"
70
+
71
+ @classmethod
72
+ def admin_scopes(cls) -> list["Scope"]:
73
+ """Scopes that are only available to admins."""
74
+ return [
75
+ cls.WRITE_TRADE_STRATEGIES,
76
+ cls.WRITE_PAY_PRODUCTS,
77
+ cls.WRITE_PAY_COUPONS,
78
+ cls.READ_PAY_COUPONS,
79
+ cls.WRITE_ADMIN,
80
+ cls.READ_ADMIN,
81
+ ]
82
+
83
+ @classmethod
84
+ def internal_scopes(cls) -> list["Scope"]:
85
+ """Scopes that are only available to internal services."""
86
+ return [
87
+ cls.WRITE_TRADE_ACTIONS,
88
+ ]
89
+
90
+ @classmethod
91
+ def purchaseable_scopes(cls) -> list["Scope"]:
92
+ """Scopes that can be purchased."""
93
+ return [
94
+ cls.READ_PREDICTIONS,
95
+ cls.READ_METRICS_MARKETCAP,
96
+ cls.READ_METRICS_INDICATORS,
97
+ cls.READ_METRICS_EXCHANGES,
98
+ cls.READ_METRICS_TOKENS,
99
+ cls.READ_METRICS_MARKETS,
100
+ cls.READ_KLINES,
101
+ cls.READ_SENTIMENT,
102
+ cls.READ_DEX_SIGNALS,
103
+ ]
104
+
105
+
106
+ class Exchange(ValidateEnumMixin, StrEnum):
107
+ """All exchanges used in the crypticorn ecosystem. Refer to the APIs for support for a specific usecase (data, trading, etc.)."""
108
+
109
+ KUCOIN = "kucoin"
110
+ BINGX = "bingx"
111
+ BINANCE = "binance"
112
+ BYBIT = "bybit"
113
+ HYPERLIQUID = "hyperliquid"
114
+ BITGET = "bitget"
115
+ GATEIO = "gateio"
116
+ BITSTAMP = "bitstamp"
117
+
118
+
119
+ class InternalExchange(ValidateEnumMixin, StrEnum):
120
+ """All exchanges we are using, including public (Exchange)"""
121
+
122
+ KUCOIN = "kucoin"
123
+ BINGX = "bingx"
124
+ BINANCE = "binance"
125
+ BYBIT = "bybit"
126
+ HYPERLIQUID = "hyperliquid"
127
+ BITGET = "bitget"
128
+
129
+ @classmethod
130
+ def __getattr__(cls, name):
131
+ warnings.warn(
132
+ "The `InternalExchange` enum is deprecated; use `Exchange` instead.",
133
+ category=CrypticornDeprecatedSince215,
134
+ )
135
+ return super().__getattr__(name)
136
+
137
+
138
+ class MarketType(ValidateEnumMixin, StrEnum):
139
+ """
140
+ Market types
141
+ """
142
+
143
+ SPOT = "spot"
144
+ FUTURES = "futures"
145
+
146
+
147
+ class ApiEnv(StrEnum):
148
+ """The environment the API is being used with."""
149
+
150
+ PROD = "prod"
151
+ DEV = "dev"
152
+ LOCAL = "local"
153
+ DOCKER = "docker"
154
+
155
+
156
+ class BaseUrl(StrEnum):
157
+ """The base URL to connect to the API."""
158
+
159
+ PROD = "https://api.crypticorn.com"
160
+ DEV = "https://api.crypticorn.dev"
161
+ LOCAL = "http://localhost"
162
+ DOCKER = "http://host.docker.internal"
163
+
164
+ @classmethod
165
+ def from_env(cls, env: ApiEnv) -> "BaseUrl":
166
+ """Load the base URL from the API environment."""
167
+ if env == ApiEnv.PROD:
168
+ return cls.PROD
169
+ elif env == ApiEnv.DEV:
170
+ return cls.DEV
171
+ elif env == ApiEnv.LOCAL:
172
+ return cls.LOCAL
173
+ elif env == ApiEnv.DOCKER:
174
+ return cls.DOCKER
175
+