How to setup
What are the api services
How to add a service
What are needed before running
Creating a Virtual Environment
Copy sudo apt update
sudo apt install python3.12-venv
python3 -m venv /home/ubuntu/myenv
Automatically Activating the Virtual Environment
Copy nano ~/.bashrc
source /home/ubuntu/myenv/bin/activate #add this code at the end of .bashrc file
source ~/.bashrc
Git Cloning the Repository under the Branch feat/standalone-signer
Ask the administrator for permission
Initiating Setup Files in the Directory /spherex-openapi-demo
Copy sudo -i
pip install .
Running Demos in the Directory /spherex-openapi-demo/tests
Substituting Your Testnet or Mainnet gRPC Path in Demo Files(ask the administrator for grpc paths)
Copy GrpcPrivate("spherex-testnet-grpc-gateway-ex-***************.elb.ap-southeast-1.amazonaws.com", 9001,)
you can find all services
Copy **grpcurl -plaintext spherex-testnet-grpc-gateway-ex-5802c5bf04e19798.elb.ap-southeast-1.amazonaws.com:9001 list**
grpcurl -plaintext [spherex-testnet-grpc-gateway-ex-5802c5bf04e19798.elb.ap-southeast-1.amazonaws.com:9001](<http://spherex-testnet-grpc-gateway-ex-5802c5bf04e19798.elb.ap-southeast-1.amazonaws.com:9001/>) describe spherex.trade.OrderServices
There are 22 services, for example
Copy spherex.quote.QuoteService
spherex.trade.OrderService
spherex.trade.TradeService
For example, OrderServices(you can create batch order and cancel orders using this service)
Quote Services(you can find market data and account position using this service)
If you want to get open/active orders by account, you can first find the catagory(Account/Order/Quote/Trade etc.) and the service, then add the service.
Copy # OrderService
rpc CreateOrderBatch ( .spherex.trade.CreateOrderBatchRequest ) returns ( .spherex.trade.CreateOrderBatchResponse ) {
option (.spherex.common.rpc_method_ext_opt) = { is_write_operation:true };
}
Copy # /spherex-openapi-demo/spherex/grpc_private.py
def order_batch_create(self, **kwargs):
resp = grpc_client.call_method("OrderService", "CreateOrderBatch", **kwargs)
return resp
Copy # /spherex-openapi-demo/spherex/order.py
class SpherexOrder:
def __init__(self, grpc_client):
self.grpc_client = grpc_client
def create_batch_order(self, order_params_list):
...
return create_order_batch_resp
What needs to be prepared before running
A permission for a github repo
An valid grpc path with a whitelisted ip
Batch order demo
Copy order_params_list = []
for order in orders:
side = order['side']
size = str(order['quantity'])
price = str(order['price'])
limit_fee = "0.0300000"
type = "LIMIT"
time_in_force = "GOOD_TIL_CANCEL"
reduce_only = False
is_position_tpsl = False
is_set_open_tp = False
is_set_open_sl = False
contract_id = 10000001
order_params = OrderParam(
market,
register_account_id,
contract_id,
side,
size,
price,
limit_fee,
position_id,
synthetic_resolution,
quote_resolution,
synthetic_id,
collateral_id,
type,
time_in_force,
reduce_only,
is_position_tpsl,
is_set_open_tp,
is_set_open_sl,
)
order_params_list.append(order_params)
order_resp = self.spherexOrder.create_batch_order(order_params_list)
print(order_resp)