Skip to content

Commit 96cf068

Browse files
Merge pull request #146 from InjectiveLabs/f/add_load_balancer
F/add load balancer
2 parents 6e65387 + da7fe0d commit 96cf068

File tree

5 files changed

+28
-107
lines changed

5 files changed

+28
-107
lines changed

README.md

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ Note that the [sync client](https://github.com/InjectiveLabs/sdk-python/blob/mas
7878

7979

8080
### Changelogs
81+
82+
**0.5.8.2**
83+
* Add global load balancer
84+
* Refactor secure client initialization
85+
8186
**0.5.7.9**
8287
* Add support for conditional orders & order mask
8388
* Add support for custom network
@@ -127,36 +132,6 @@ Note that the [sync client](https://github.com/InjectiveLabs/sdk-python/blob/mas
127132
* Add multi-subaccount support in local order hash calculation
128133
* Re-gen ini files
129134

130-
**0.5.6.8**
131-
* Add skip & limit params to Exchange API methods
132-
* Add more methods in ExplorerRPC
133-
* Add bank balance chain queries
134-
* Remove LB endpoint and keep K8S as default
135-
* Refactored local order hash computation
136-
* Re-gen ini files
137-
138-
**0.5.6.6**
139-
* Add PO orders in local order hash computation function
140-
* Add automatic timeout height in transactions
141-
* Add automatic session renewal for K8S
142-
* Add MsgDelegate and MsgWithdrawDelegatorReward in the composer
143-
* Add typed authz support in the composer
144-
* Decouple SendToCosmos from the composer and remove web3 dependency
145-
* Re-gen ini files
146-
147-
148-
**0.5.6.5**
149-
* Add MsgRelayPriceFeedPrice in the composer
150-
* Add Post-only orders in the composer
151-
* Add OrderbooksRequest in the clients
152-
* Add support for multiple markets in StreamTrades and StreamPosition
153-
* Add support for multiple subaccounts in StreamTrades and StreamPosition
154-
* Add K8S endpoint to mainnet network options
155-
* Add MsgRegisterAsDMM to the composer
156-
* Add functions to close chain/exchange channels
157-
* Re-gen ini files
158-
159-
160135

161136
## License
162137

pyinjective/async_client.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ def __init__(
7373
self,
7474
network: Network,
7575
insecure: bool = False,
76-
credentials: grpc.ChannelCredentials = None,
76+
load_balancer: bool = False,
77+
credentials = grpc.ssl_channel_credentials(),
7778
chain_cookie_location = ".chain_cookie"
7879
):
7980

@@ -82,16 +83,17 @@ def __init__(
8283
cookie_file = open(chain_cookie_location, "a+")
8384
cookie_file.close()
8485

85-
# load root CA cert
86-
if not insecure:
87-
if network.env == 'testnet':
88-
if credentials is None:
89-
with open(os.path.join(os.path.dirname(__file__), 'cert/testnet.crt'), 'rb') as f:
90-
credentials = grpc.ssl_channel_credentials(f.read())
91-
if network.env == 'mainnet':
92-
if credentials is None:
93-
with open(os.path.join(os.path.dirname(__file__), 'cert/mainnet.crt'), 'rb') as f:
94-
credentials = grpc.ssl_channel_credentials(f.read())
86+
self.cookie_type = None
87+
self.expiration_format = None
88+
self.load_balancer = load_balancer
89+
90+
if self.load_balancer is False:
91+
self.cookie_type = "grpc-cookie"
92+
self.expiration_format = "20{}"
93+
94+
else:
95+
self.cookie_type = "GCLB"
96+
self.expiration_format = "{}"
9597

9698
# chain stubs
9799
self.chain_channel = (
@@ -183,9 +185,9 @@ async def renew_cookie(self, existing_cookie, type):
183185
# format cookie date into RFC1123 standard
184186
cookie = SimpleCookie()
185187
cookie.load(existing_cookie)
186-
expires_at = cookie.get("grpc-cookie").get("expires")
188+
expires_at = cookie.get(f"{self.cookie_type}").get("expires")
187189
expires_at = expires_at.replace("-"," ")
188-
yyyy = "20{}".format(expires_at[12:14])
190+
yyyy = f"{self.expiration_format}".format(expires_at[12:14])
189191
expires_at = expires_at[:12] + yyyy + expires_at[14:]
190192

191193
# parse expire field to unix timestamp

pyinjective/cert/mainnet.crt

Lines changed: 0 additions & 31 deletions
This file was deleted.

pyinjective/cert/testnet.crt

Lines changed: 0 additions & 31 deletions
This file was deleted.

pyinjective/constant.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ def testnet(cls):
106106
def mainnet(cls, node='k8s'):
107107
nodes = [
108108
'k8s',
109+
'lb',
109110
'sentry0', # us, prod
110111
'sentry1', # us, prod
111112
'sentry2', # us, staging
@@ -115,10 +116,15 @@ def mainnet(cls, node='k8s'):
115116
raise ValueError('Must be one of {}'.format(nodes))
116117

117118
if node == 'k8s':
118-
lcd_endpoint='https://k8s.mainnet.lcd.injective.network'
119-
tm_websocket_endpoint='wss://k8s.mainnet.tm.injective.network/websocket'
119+
lcd_endpoint='https://k8s.mainnet.lcd.injective.network:443'
120+
tm_websocket_endpoint='wss://k8s.mainnet.tm.injective.network:443/websocket'
120121
grpc_endpoint='k8s.mainnet.chain.grpc.injective.network:443'
121122
grpc_exchange_endpoint='k8s.mainnet.exchange.grpc.injective.network:443'
123+
elif node == 'lb':
124+
lcd_endpoint = 'https://k8s.global.mainnet.lcd.injective.network:443'
125+
tm_websocket_endpoint = 'wss://k8s.global.mainnet.tm.injective.network:443/websocket'
126+
grpc_endpoint = 'k8s.global.mainnet.chain.grpc.injective.network:443'
127+
grpc_exchange_endpoint = 'k8s.global.mainnet.exchange.grpc.injective.network:443'
122128
else:
123129
lcd_endpoint='https://lcd.injective.network'
124130
tm_websocket_endpoint=f'ws://{node}.injective.network:26657/websocket'

0 commit comments

Comments
 (0)