Skip to content

Commit 541b01a

Browse files
Abel ArmoaAbel Armoa
authored andcommitted
(fix) Updated examples and the run-examples.sh script to enable the execution off all examples with the new code base
1 parent 79c722e commit 541b01a

File tree

8 files changed

+28
-35
lines changed

8 files changed

+28
-35
lines changed

examples/exchange_client/spot_exchange_rpc/14_Orderbooks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ async def main() -> None:
1111
"0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe",
1212
"0x7a57e705bb4e09c88aecfc295569481dbf2fe1d5efe364651fbe72385938e9b0"
1313
]
14-
orderbooks = await client.get_spot_orderbooks(market_ids=market_ids)
14+
orderbooks = await client.get_spot_orderbooksV2(market_ids=market_ids)
1515
print(orderbooks)
1616

1717
if __name__ == '__main__':

examples/exchange_client/spot_exchange_rpc/16_OrderbooksV2.py

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

examples/exchange_client/spot_exchange_rpc/4_Orderbook.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ async def main() -> None:
88
network = Network.testnet()
99
client = AsyncClient(network, insecure=False)
1010
market_id = "0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe"
11-
orderbook = await client.get_spot_orderbook(market_id=market_id)
11+
orderbook = await client.get_spot_orderbookV2(market_id=market_id)
1212
print(orderbook)
1313

1414
if __name__ == '__main__':

pyinjective/async_client.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -675,14 +675,6 @@ async def stream_spot_markets(self, **kwargs):
675675
metadata = await self.load_cookie(type="exchange")
676676
return self.stubSpotExchange.StreamMarkets.__call__(req, metadata=metadata)
677677

678-
async def get_spot_orderbook(self, market_id: str):
679-
req = spot_exchange_rpc_pb.OrderbookRequest(market_id=market_id)
680-
return await self.stubSpotExchange.Orderbook(req)
681-
682-
async def get_spot_orderbooks(self, market_ids: List):
683-
req = spot_exchange_rpc_pb.OrderbooksRequest(market_ids=market_ids)
684-
return await self.stubSpotExchange.Orderbooks(req)
685-
686678
async def get_spot_orderbookV2(self, market_id: str):
687679
req = spot_exchange_rpc_pb.OrderbookV2Request(market_id=market_id)
688680
return await self.stubSpotExchange.OrderbookV2(req)

pyinjective/composer.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ def __init__(
6969
7070
"""
7171
self.network = network
72+
self.spot_markets = dict()
73+
self.derivative_markets = dict()
74+
self.binary_option_markets = dict()
75+
self.tokens = dict()
7276
if spot_markets is None or derivative_markets is None or binary_option_markets is None or tokens is None:
7377
self._initialize_markets_and_tokens_from_files()
7478
else:
@@ -1004,7 +1008,7 @@ def _initialize_markets_and_tokens_from_files(self):
10041008
min_price_tick_size=Decimal(str(configuration_section["min_price_tick_size"])),
10051009
min_quantity_tick_size=Decimal(str(configuration_section["min_quantity_tick_size"]))
10061010
)
1007-
spot_markets[description] = market
1011+
spot_markets[market.id] = market
10081012
else:
10091013
market = DerivativeMarket(
10101014
id=section_name,
@@ -1024,7 +1028,7 @@ def _initialize_markets_and_tokens_from_files(self):
10241028
min_quantity_tick_size=Decimal(str(configuration_section["min_quantity_tick_size"])),
10251029
)
10261030

1027-
derivative_markets[description] = market
1031+
derivative_markets[market.id] = market
10281032

10291033
elif section_name != "DEFAULT":
10301034
token = Token(
@@ -1037,8 +1041,9 @@ def _initialize_markets_and_tokens_from_files(self):
10371041
updated=-1,
10381042
)
10391043

1040-
tokens[token.symbol] = Token
1044+
tokens[token.symbol] = token
10411045

10421046
self.tokens = tokens
10431047
self.spot_markets = spot_markets
10441048
self.derivative_markets = derivative_markets
1049+
self.binary_option_markets = dict()

pyinjective/denoms_testnet.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ min_display_price_tick_size = 1e-05
5252
min_quantity_tick_size = 100000
5353
min_display_quantity_tick_size = 0.1
5454

55-
[0xe112199d9ee44ceb2697ea0edd1cd422223c105f3ed2bdf85223d3ca59f5909a]
55+
[0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6]
5656
description = 'Testnet Derivative INJ/USDT PERP'
5757
base = 0
5858
quote = 6

run-examples.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
runChainExamples(){
2-
examples=$(find -s examples/chain_client_examples -type f -mindepth 1 -name '*.py')
2+
examples=$(find -s examples/chain_client -type f -mindepth 1 -name '*.py')
33
echo "Running all chain examples..."
44
for example in $examples
55
do
@@ -10,7 +10,7 @@ runChainExamples(){
1010
}
1111

1212
runExchangeExamples(){
13-
dirs=$(find -s examples/exchange_api_examples -type d -mindepth 1)
13+
dirs=$(find -s examples/exchange_client -type d -mindepth 1)
1414
for dir in $dirs
1515
do
1616
examples=$(find -s $dir -type f -name '*.py')
@@ -26,6 +26,8 @@ runExchangeExamples(){
2626
done
2727
}
2828

29+
export PYTHONPATH=$PYTHONPATH:$(pwd)
30+
2931
TYPE=$1
3032
case $TYPE in
3133
"chain")

tests/test_composer.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,19 @@ def basic_composer(self, inj_usdt_spot_market, btc_usdt_perp_market, first_match
3838

3939
return composer
4040

41+
def test_composer_initialization_from_ini_files(self):
42+
composer = Composer(network=Network.devnet().string())
43+
44+
inj_token = composer.tokens["INJ"]
45+
inj_usdt_spot_market = next((market for market in composer.spot_markets.values() if market.ticker == "'Devnet Spot INJ/USDT'"))
46+
inj_usdt_perp_market = next((market for market in composer.derivative_markets.values() if market.ticker == "'Devnet Derivative INJ/USDT PERP'"))
47+
48+
assert (18 == inj_token.decimals)
49+
assert (18 == inj_usdt_spot_market.base_token.decimals)
50+
assert (6 == inj_usdt_spot_market.quote_token.decimals)
51+
assert (6 == inj_usdt_perp_market.quote_token.decimals)
52+
53+
4154
def test_buy_spot_order_creation(self, basic_composer: Composer, inj_usdt_spot_market: SpotMarket):
4255
fee_recipient = "inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r"
4356
price = 6.869

0 commit comments

Comments
 (0)