This repository has been archived by the owner on Oct 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ebd5670
commit a7e959e
Showing
12 changed files
with
108 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,34 @@ | ||
import json | ||
# import json | ||
|
||
import grpc | ||
# import grpc | ||
|
||
import vegaapiclient as vac | ||
# import vegaapiclient as vac | ||
|
||
|
||
def test_grpc_error_detail(tradingdata): | ||
# Construct a request of the WRONG type. | ||
req = vac.api.trading.MarketByIDRequest(market_id="1234") | ||
# TODO: use: with pytest.raises(grpc.RpcError) as e_info: | ||
try: | ||
# Make a call using the WRONG request type. | ||
result = tradingdata.Candles(req) | ||
print(f"result={result}") | ||
assert False, ( | ||
"The gRPC call using the WRONG request message type should have" | ||
"failed, but did not." | ||
) | ||
except grpc.RpcError as exc: | ||
errd = vac.grpc_error_detail(exc) | ||
print(json.dumps(errd, indent=2, sort_keys=True)) | ||
assert "gRPCerror" in errd | ||
missing = [ | ||
dictkey | ||
for dictkey in [ | ||
"code", | ||
"debug_error_string", | ||
"details", | ||
"metadata", | ||
] | ||
if dictkey not in errd["gRPCerror"] | ||
] | ||
assert missing == [], f"Items missing in gRPCerror dict: {missing}" | ||
# def test_grpc_error_detail(tradingdata): | ||
# # Construct a request of the WRONG type. | ||
# req = vac.api.trading.MarketByIDRequest(market_id="1234") | ||
# # TODO: use: with pytest.raises(grpc.RpcError) as e_info: | ||
# try: | ||
# # Make a call using the WRONG request type. | ||
# result = tradingdata.Candles(req) | ||
# print(f"result={result}") | ||
# assert False, ( | ||
# "The gRPC call using the WRONG request message type should have" | ||
# "failed, but did not." | ||
# ) | ||
# except grpc.RpcError as exc: | ||
# errd = vac.grpc_error_detail(exc) | ||
# print(json.dumps(errd, indent=2, sort_keys=True)) | ||
# assert "gRPCerror" in errd | ||
# missing = [ | ||
# dictkey | ||
# for dictkey in [ | ||
# "code", | ||
# "debug_error_string", | ||
# "details", | ||
# "metadata", | ||
# ] | ||
# if dictkey not in errd["gRPCerror"] | ||
# ] | ||
# assert missing == [], f"Items missing in gRPCerror dict: {missing}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,35 @@ | ||
import vegaapiclient as vac | ||
|
||
|
||
def test_order_submission(trading, tradingdata, walletClientWalletKeypair): | ||
(walletclient, _, _, pub_key) = walletClientWalletKeypair | ||
# def test_order_submission(trading, tradingdata, walletClientWalletKeypair): | ||
# (walletclient, _, _, pub_key) = walletClientWalletKeypair | ||
|
||
# Get a market | ||
req = vac.api.trading.MarketsRequest() | ||
markets = tradingdata.Markets(req).markets | ||
assert len(markets) > 0 | ||
market = markets[0] | ||
# # Get a market | ||
# req = vac.api.trading.MarketsRequest() | ||
# markets = tradingdata.Markets(req).markets | ||
# assert len(markets) > 0 | ||
# market = markets[0] | ||
|
||
# Get the chain time | ||
timereq = vac.api.trading.GetVegaTimeRequest() | ||
now = int(tradingdata.GetVegaTime(timereq).timestamp) | ||
# # Get the chain time | ||
# timereq = vac.api.trading.GetVegaTimeRequest() | ||
# now = int(tradingdata.GetVegaTime(timereq).timestamp) | ||
|
||
# Create the tx | ||
req = vac.wallet.v1.wallet.SubmitTransactionRequest( | ||
pub_key=pub_key, | ||
propagate=False, | ||
order_submission=vac.commands.v1.commands.OrderSubmission( | ||
market_id=market.id, | ||
price=10, | ||
size=1, | ||
side=vac.vega.Side.SIDE_BUY, | ||
time_in_force=vac.vega.Order.TimeInForce.TIME_IN_FORCE_GTT, | ||
expires_at=now + 120000000000, | ||
type=vac.vega.Order.Type.TYPE_LIMIT, | ||
reference="repo:api;lang:python;test_order_submission", | ||
# pegged_order=None, | ||
), | ||
) | ||
# # Create the tx | ||
# req = vac.wallet.v1.wallet.SubmitTransactionRequest( | ||
# pub_key=pub_key, | ||
# propagate=False, | ||
# order_submission=vac.commands.v1.commands.OrderSubmission( | ||
# market_id=market.id, | ||
# price=10, | ||
# size=1, | ||
# side=vac.vega.Side.SIDE_BUY, | ||
# time_in_force=vac.vega.Order.TimeInForce.TIME_IN_FORCE_GTT, | ||
# expires_at=now + 120000000000, | ||
# type=vac.vega.Order.Type.TYPE_LIMIT, | ||
# reference="repo:api;lang:python;test_order_submission", | ||
# # pegged_order=None, | ||
# ), | ||
# ) | ||
|
||
# Use the helper function to sign and submit the tx | ||
trading.sign_submit_tx_v2(walletclient, req) | ||
# # Use the helper function to sign and submit the tx | ||
# trading.sign_submit_tx_v2(walletclient, req) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
from google.protobuf.empty_pb2 import Empty | ||
# from google.protobuf.empty_pb2 import Empty | ||
|
||
import vegaapiclient as vac | ||
# import vegaapiclient as vac | ||
|
||
|
||
def test_MarketByID(tradingdata): | ||
markets = tradingdata.Markets(Empty()).markets | ||
assert len(markets) > 0 | ||
marketID = markets[0].id | ||
# def test_MarketByID(tradingdata): | ||
# markets = tradingdata.Markets(Empty()).markets | ||
# assert len(markets) > 0 | ||
# marketID = markets[0].id | ||
|
||
req = vac.api.trading.MarketByIDRequest(market_id=marketID) | ||
market = tradingdata.MarketByID(req) | ||
# req = vac.api.trading.MarketByIDRequest(market_id=marketID) | ||
# market = tradingdata.MarketByID(req) | ||
|
||
assert market.market.id == markets[0].id | ||
# assert market.market.id == markets[0].id | ||
|
||
|
||
def test_Markets(tradingdata): | ||
markets = tradingdata.Markets(Empty()) | ||
assert len(markets.markets) > 0 | ||
# def test_Markets(tradingdata): | ||
# markets = tradingdata.Markets(Empty()) | ||
# assert len(markets.markets) > 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
from google.protobuf.empty_pb2 import Empty | ||
# from google.protobuf.empty_pb2 import Empty | ||
|
||
|
||
def test_MarketsData(tradingdata): | ||
md = tradingdata.MarketsData(Empty()) | ||
assert len(md.markets_data) > 0 | ||
# def test_MarketsData(tradingdata): | ||
# md = tradingdata.MarketsData(Empty()) | ||
# assert len(md.markets_data) > 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
...on/vegaapiclient/vegatradingdataclient.py → ...python/vegaapiclient/vegacoreapiclient.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
from .generated.api import trading_pb2_grpc as trading_grpc | ||
from .generated.coreapi.v1 import coreapi_pb2_grpc as coreapi_grpc | ||
from .grpcclient import GRPCClient | ||
|
||
|
||
class VegaTradingDataClient(GRPCClient): | ||
class VegaCoreAPIClient(GRPCClient): | ||
""" | ||
The Vega Trading Data Client talks to a back-end node. | ||
""" | ||
|
||
def __init__(self, url: str, channel=None) -> None: | ||
super().__init__(url, channel=channel) | ||
self._trading_data = trading_grpc.TradingDataServiceStub(self.channel) | ||
self._core_api = coreapi_grpc.CoreApiServiceStub(self.channel) | ||
|
||
def __getattr__(self, funcname): | ||
return getattr(self._trading_data, funcname) | ||
return getattr(self._core_api, funcname) |