Authenticated Client - authenticated_client
¶
Table of Contents
Description:
Authenticated Client Class for interacting with the Tradehub network. This client performs the actions on the tradehub network by submitting transaction on-chain. This class is designed to use public nodes for the API and WS clients to use.
Usage:
from tradehub.authenticated_client import AuthenticatedClient
Classes:
|
This class uses a private key to interact with the Tradehub network of validators. |
-
class
tradehub.authenticated_client.
AuthenticatedClient
(wallet: tradehub.wallet.Wallet, trusted_ips: Optional[list] = None, trusted_uris: Optional[list] = None, network: str = 'testnet')[source]¶ Bases:
tradehub.transactions.Transactions
This class uses a private key to interact with the Tradehub network of validators.
Execution of this function is as follows:
AuthenticatedClient(network='mainnet', wallet=Wallet(mnemonic='', network='mainnet') trusted_ips=None, trusted_uris=None)
Methods:
activate_sub_account
(message[, fee])add_liquidity
(message[, fee])broadcast_transactions
(transactions)Now that messages are standardized we need to sign the transaction and broadcast it.
cancel_all
(message[, fee])Function to cancel all orders for a specific market on the Tradehub network.
cancel_order
(message[, fee])Function to cancel an order on the Tradehub network.
cancel_orders
(messages[, fee])Function to cancel multiple order on the Tradehub network.
check_username
(username)- param username
claim_all_staking_rewards
([message, fee])Function to claim rewards generated from all validators a wallet is staking with on the Tradehub network.
claim_pool_rewards
(message[, fee])claim_staking_rewards
([message, fee])Function to claim rewards generated from staking with a Switcheo validator on the Tradehub network.
construct_complete_transaction
(transaction)construct_concrete_messages
(messages, …)The first step to building a transaction is merging the messages with the transaction types for each.
construct_signatures
(signature)construct_transaction
(message, signatures, fees)create_order
(message[, fee])Function to create an order on the Tradehub network.
create_orders
(messages[, fee])Function to create multiple orders on the Tradehub network.
create_sub_account
(message[, fee])create_validator
(message[, fee])create_withdraw
(message, blockchain[, fee])Function to withdraw tokens from the Tradehub network onto the desired blockchain.
edit_order
(message[, fee])Function to edit an open order on the Tradehub network.
edit_orders
(messages[, fee])Function to edit open orders on the Tradehub network.
get_account
(swth_address)Request account information about swth wallet.
Retrieve Wallet account details required for submitting transactions on Tradehub.
get_active_wallets
(token)- param token
get_address
(username)Request swth1 tradehub address which is represented by a username.
get_address_trades
([limit, pagination, address])Get all validators.
get_balance
(swth_address)Get balance which includes available, in open orders and open positions.
get_block
([block_nbr])Get the block time in format HH:MM:SS.ZZZZZZ.
get_blocks
([before_id, after_id, order_by, …])Get latest blocks or request specific blocks.
get_candlesticks
(market, granularity, …)Get candlesticks for a market.
get_delegation_rewards
(swth_address)Request delegation rewards made by a tradehub wallet.
get_external_transfers
(swth_address)Get external transfers(withdraws or deposits) from other blockchains.
get_leverage
(swth_address, market)get_liquidations
(before_id, after_id, …)get_market
(market)Get information about a market.
get_market_stats
([market])Get statistics about one or all markets.
get_markets
([market_type, is_active, is_settled])Get all markets or filter markets.
get_oracle_result
(oracle_id)get_order
(order_id)Get a specific order by id.
get_orderbook
(market[, limit])Get the orderbook from a market.
get_orders
([swth_address, before_id, …])Request last orders or filter them.
get_position
(swth_address, market)get_positions
(swth_address)get_positions_sorted_by_pnl
(market)get_positions_sorted_by_risk
(market)get_positions_sorted_by_size
(market)get_prices
(market)Get prices off a market.
get_profile
(swth_address)Get profile from a tradehub wallet.
get_rich_list
(token)Return cosmos RPC status endpoint.
get_token
(denom)Get information about a token.
Get all known tokens on tradehub chain.
get_top_r_profits
(market, limit)get_trades
([market, before_id, after_id, …])Get recent trades or filter trades.
get_transaction
(tx_hash)Get a transaction by providing the hash.
get_transaction_fee_type
(transaction_type)get_transaction_log
(transaction_hash)Get transaction types used by tradehub.
get_transactions
([swth_address, msg_type, …])Get latest transactions or filter them.
get_username_check
(username)Check if a username is taken or not.
get_validator_delegations
(operator_address)get_validator_signing_info
([limit])get_validators
([status])- param token
get_vaults
(swth_address)parse_validator_status
(request_json, …)Function to parse each peer’s JSON element and build information about each.
redelegate_tokens
(message[, fee])Function to move tokens from one validator to another on the Tradehub network.
remove_liquidity
(message[, fee])send_tokens
(message[, fee])Function to send tokens from your wallet to a recipient.
sentry_status_request
([uri])This function is here to ensure the nodes that have open network connections also have their persistence service running.
set_fees
(transaction_cnt, transaction_type, fee)Standardize, find, and calculate fees for the number of transactions.
set_message_standards
(messages)Standardize messages, adding an originator or takingo ut keys that don’t exist.
set_transaction_standards
(messages, …)This function sets standards for the messages in the transaction submitted to the chain.
sign_and_broadcast
(messages, …)Now that messages are standardized we need to sign the transaction and broadcast it.
sign_message
(messages[, memo, fee])Sign the messages constructed in the previous function.
sign_transaction
(messages, transaction_types)A Signature has the following sequence.
stake_pool_token
(message[, fee])stake_switcheo
([message, fee])Function to stake (or delegate) Switcheo to validators on the Tradehub network.
submit_transaction_on_chain
(messages, …)This is the function that every function in higher classes should call.
tradehub_get_request
(path[, params])This is a wrapper for the get request function to allow for retrying network calls on different available validators if a request fails.
tradehub_post_request
(path[, data, …])This is a wrapper for the post request function to allow for retrying network calls on different available validators if a request fails.
unbond_tokens
(message[, fee])Function to unbond tokens a validator on the Tradehub network.
unstake_pool_token
(message[, fee])Triggers an update to fetch current sequence number.
update_profile
(message[, fee])Function that makes the network requests to the Tradehub validators across the network.
Crawl the Tradehub Validators to test for available API endpoints.
validator_status_request
(validator_ip)Function that makes the network requests to the Tradehub validators across the network.
websocket_status_check
(ip[, port])Function to check if the websocket port is open for communication.
-
activate_sub_account
(message: tradehub.types.ActivateSubAccountMessage, fee: Optional[dict] = None)[source]¶
-
broadcast_transactions
(transactions: dict)¶ Now that messages are standardized we need to sign the transaction and broadcast it. The actual signature part will be handled by the Wallet Client to avoid leaking keys between classes.
Execution of this function is as follows:
broadcast_transactions(transactions=transactions)
The expected return result for this function is as follows:
{
‘height’: str, ‘txhash’: str, ‘raw_log’: str, ‘logs’: [{
‘msg_index’: int, ‘log’: str, ‘events’: [{
‘type’: str, ‘attributes’: [{
‘key’: str, ‘value’: str
}]
}]
}], ‘gas_wanted’: str, ‘gas_used’: str
}
- Returns
Dictionary for the transaction submitted on-chain.
-
cancel_all
(message: tradehub.types.CancelAllMessage, fee: Optional[dict] = None)[source]¶ Function to cancel all orders for a specific market on the Tradehub network.
Execution of this function is as follows:
cancel_all(message=types.CancelAllMessage(market='swth_eth1'))
- Parameters
message – CancelAllMessage Type that is a class of attributes required to make this on-chain action.
fee – Dict of the fee type, generally this can be left blank and allow the API to handle this.
- Returns
Dictionary of the transaction response sent on-chain, look in the logs to be sure it matches what was sent.
-
cancel_order
(message: tradehub.types.CancelOrderMessage, fee: Optional[dict] = None)[source]¶ Function to cancel an order on the Tradehub network.
Execution of this function is as follows:
cancel_order(message=types.CancelOrderMessage(id="D3F370A91D260DB3B1112757D8F9B66EEA1B7887FB4B247872D367F04A4C56EB"))
- Parameters
message – CancelOrderMessage Type that is a class of attributes required to make this on-chain action.
fee – Dict of the fee type, generally this can be left blank and allow the API to handle this.
- Returns
Dictionary of the transaction response sent on-chain, look in the logs to be sure it matches what was sent.
-
cancel_orders
(messages: [<class 'tradehub.types.CancelOrderMessage'>], fee: Optional[dict] = None)[source]¶ Function to cancel multiple order on the Tradehub network.
Execution of this function is as follows:
cancel_orders(message=[types.CancelOrderMessage(id="D3F370A91D260DB3B1112757D8F9B66EEA1B7887FB4B247872D367F04A4C56EB")])
- Parameters
message – List of CancelOrderMessage Type that is a class of attributes required to make this on-chain action.
fee – Dict of the fee type, generally this can be left blank and allow the API to handle this.
- Returns
Dictionary of the transaction response sent on-chain, look in the logs to be sure it matches what was sent.
-
check_username
(username: str) → dict¶ - Parameters
username –
- Returns
-
claim_all_staking_rewards
(message=<class 'tradehub.types.WithdrawAllDelegatorRewardsParams'>, fee: Optional[dict] = None)[source]¶ Function to claim rewards generated from all validators a wallet is staking with on the Tradehub network.
Execution of this function is as follows:
claim_all_staking_rewards(message=types.WithdrawAllDelegatorRewardsParams(delegator_address=self._wallet.address, validator_addresses=['tswthvaloper1hn0spc9plh5ker8lrtzyz9uqfe3xk2yn0c6nyf', 'tswthvaloper10229tj7kh2mzwsn9cnfxuq3sqjuph860dlezpr']))
- Parameters
message – WithdrawAllDelegatorRewardsMessage Type that is a class of attributes required to make this on-chain action.
fee – Dict of the fee type, generally this can be left blank and allow the API to handle this.
- Returns
Dictionary of the transaction response sent on-chain, look in the logs to be sure it matches what was sent.
-
claim_pool_rewards
(message: tradehub.types.ClaimPoolRewardsMessage, fee: Optional[dict] = None)[source]¶
-
claim_staking_rewards
(message=<class 'tradehub.types.WithdrawDelegatorRewardsMessage'>, fee: Optional[dict] = None)[source]¶ Function to claim rewards generated from staking with a Switcheo validator on the Tradehub network.
Execution of this function is as follows:
claim_staking_rewards(message=types.WithdrawDelegatorRewardsMessage(delegator_address=self._wallet.address, validator_address='tswthvaloper10229tj7kh2mzwsn9cnfxuq3sqjuph860dlezpr'))
- Parameters
message – WithdrawDelegatorRewardsMessage Type that is a class of attributes required to make this on-chain action.
fee – Dict of the fee type, generally this can be left blank and allow the API to handle this.
- Returns
Dictionary of the transaction response sent on-chain, look in the logs to be sure it matches what was sent.
-
construct_complete_transaction
(transaction: dict, mode: Optional[str] = None)¶
-
construct_concrete_messages
(messages: list, transaction_types: list)¶ The first step to building a transaction is merging the messages with the transaction types for each. Once constructed then each message can be sent off for signature.
Execution of this function is as follows:
construct_concrete_messages(messages=messages_list, transaction_types=transactions_list)
- Returns
List of dictionaries of messages with transaction types.
-
construct_signatures
(signature: str)¶
-
construct_transaction
(message: list, signatures: list, fees: dict, memo: Optional[str] = None)¶
-
create_order
(message: tradehub.types.CreateOrderMessage, fee: Optional[dict] = None)[source]¶ Function to create an order on the Tradehub network.
Execution of this function is as follows:
create_order(message=types.CreateOrderMessage(market="swth_eth1", side="sell", quantity="200", price="0.00002", type="limit"))
- Parameters
message – CreateOrderMessage Type that is a class of attributes required to make this on-chain action.
fee – Dict of the fee type, generally this can be left blank and allow the API to handle this.
- Returns
Dictionary of the transaction response sent on-chain, look in the logs to be sure it matches what was sent.
-
create_orders
(messages: [<class 'tradehub.types.CreateOrderMessage'>], fee: Optional[dict] = None)[source]¶ Function to create multiple orders on the Tradehub network.
Execution of this function is as follows:
create_orders([message=types.CreateOrderMessage(market="swth_eth1", side="sell", quantity="200", price="0.00002", type="limit")])
- Parameters
message – List of CreateOrderMessage Type that is a class of attributes required to make this on-chain action.
fee – Dict of the fee type, generally this can be left blank and allow the API to handle this.
- Returns
Dictionary of the transaction response sent on-chain, look in the logs to be sure it matches what was sent.
-
create_sub_account
(message: tradehub.types.CreateSubAccountMessage, fee: Optional[dict] = None)[source]¶
-
create_validator
(message: tradehub.types.CreateValidatorMessage, fee: Optional[dict] = None)[source]¶
-
create_withdraw
(message: tradehub.types.CreateWithdrawMessage, blockchain: str, fee: Optional[dict] = None)[source]¶ Function to withdraw tokens from the Tradehub network onto the desired blockchain.
Execution of this function is as follows:
create_withdraw(message=types.CreateWithdrawMessage(to_address=NEO_ADDRESS, denom='swth-n', amount='87', fee_amount="1"), blockchain='NEO')
- Parameters
message – CreateWithdrawMessage Type that is a class of attributes required to make this on-chain action.
blockchain – String to specify if the withdraw is going to the NEO or Ethereum network.
fee – Dict of the fee type, generally this can be left blank and allow the API to handle this.
- Returns
Dictionary of the transaction response sent on-chain, look in the logs to be sure it matches what was sent.
-
edit_order
(message: tradehub.types.EditOrderMessage, fee: Optional[dict] = None)[source]¶ Function to edit an open order on the Tradehub network.
Execution of this function is as follows:
edit_order(message=types.EditOrderMessage(id="816F6D321F696EA81EB9961BE51DB5CB31520217DAF75FA569446BDD85A21E96", quantity="220", stop_price="0.0000175"))
- Parameters
message – EditOrderMessage Type that is a class of attributes required to make this on-chain action.
fee – Dict of the fee type, generally this can be left blank and allow the API to handle this.
- Returns
Dictionary of the transaction response sent on-chain, look in the logs to be sure it matches what was sent.
-
edit_orders
(messages: [<class 'tradehub.types.EditOrderMessage'>], fee: Optional[dict] = None)[source]¶ Function to edit open orders on the Tradehub network.
Execution of this function is as follows:
edit_orders(message=[types.EditOrderMessage(id="816F6D321F696EA81EB9961BE51DB5CB31520217DAF75FA569446BDD85A21E96", quantity="220", stop_price="0.0000175")])
- Parameters
message – List of EditOrderMessage Type that is a class of attributes required to make this on-chain action.
fee – Dict of the fee type, generally this can be left blank and allow the API to handle this.
- Returns
Dictionary of the transaction response sent on-chain, look in the logs to be sure it matches what was sent.
-
get_account
(swth_address: str) → dict¶ Request account information about swth wallet.
Example:
# wallet behind Devel And Co validator public_client.get_account("swth1vwges9p847l9csj8ehrlgzajhmt4fcq4sd7gzl")
The expected return result for this function is as follows:
{ "height": "6102489", "result": { "type": "cosmos-sdk/Account", "value": { "address": "swth1vwges9p847l9csj8ehrlgzajhmt4fcq4sd7gzl", "coins": [ { "denom": "cel1", "amount": "7" }, { "denom": "eth1", "amount": "64752601707981" }, { "denom": "nex1", "amount": "12289" }, { "denom": "nneo2", "amount": "31555" }, { "denom": "swth", "amount": "4113439708" }, { "denom": "usdc1", "amount": "45376" }, { "denom": "wbtc1", "amount": "29" } ], "public_key": { "type": "tendermint/PubKeySecp256k1", "value": "AtCcJkRx1VhzZkOV06yrxKMZ9IvdRxqv5S4gJSQI/aCB" }, "account_number": "1756", "sequence": "55" } } }
- Parameters
swth_address – tradehub switcheo address starting with ‘swth1’ on mainnet and ‘tswth1’ on testnet.
- Returns
json response
-
get_account_details
()¶ Retrieve Wallet account details required for submitting transactions on Tradehub.
Execution of this function is as follows:
get_account_details()
The expected return result for this function is as follows:
{ 'height': '1950991', 'result': { 'type': 'cosmos-sdk/Account', 'value': { 'address': 'tswth1urfldmcspc9nk4w8vcfakxdf2rc5ee4fr2dn76', 'coins': [{ 'denom': 'btc', 'amount': '99033160' }, { ... }], 'public_key': { 'type': 'tendermint/PubKeySecp256k1', 'value': 'Ao8h4bhZr1/m8ZEwPaOizNCcIMDX/yqwQh7LXhI77FLW' }, 'account_number': '56', 'sequence': '3195' } } }
- Returns
Dictionary for the current state of the wallet, including sequence number and balances.
-
get_active_wallets
(token: str) → int¶ - Parameters
token –
- Return active_wallet_cnt
-
get_address
(username: str) → str¶ Request swth1 tradehub address which is represented by a username.
Example:
public_client.get_address("devel484")
The expected return result for this function is as follows:
"swth1qlue2pat9cxx2s5xqrv0ashs475n9va963h4hz"
Warning
This endpoint returns only a string if address is found. If no address is found an exception with status code 404 will be raised.
Note
Usernames are in lowercase and can only be 15 characters long.
- Parameters
username – Username is lower case.
- Returns
swth1 address if found
-
get_address_trades
(limit: int = 200, pagination: Optional[bool] = None, address: Optional[str] = None)¶
-
get_all_validators
() → List[dict]¶ Get all validators. This includes active, unbonding and unbonded validators.
Example:
public_client.get_all_validators()
The expected return result for this function is as follows:
[ { "OperatorAddress":"swthvaloper1vwges9p847l9csj8ehrlgzajhmt4fcq4dmg8x0", "ConsPubKey":"swthvalconspub1zcjduepqcufdssqqfycjwz2srp42tytrs7gtdkkry9cpspea3zqsjzqd2tps73pr63", "Jailed":false, "Status":2, "Tokens":"22414566.55131922", "DelegatorShares":"22414566.55131922", "Description":{ "moniker":"Devel & Co", "identity":"c572aef1818379c38996878357c321398165fcf0", "website":"https://gitlab.com/switcheo-utils", "security_contact":"", "details":"..."}, "UnbondingHeight":0, "UnbondingCompletionTime":"1970-01-01T00:00:00Z", "Commission":{ "commission_rates":{ "rate":"0.004200000000000000", "max_rate":"0.200000000000000000", "max_change_rate":"0.010000000000000000" }, "update_time":"2020-11-27T20:25:33.45991154Z" }, "MinSelfDelegation":"1", "ConsAddress":"swthvalcons1pqnlj0na6k8u9y27j3elrx584mt3380dal0j9s", "ConsAddressByte":"0827F93E7DD58FC2915E9473F19A87AED7189DED", "WalletAddress":"swth1vwges9p847l9csj8ehrlgzajhmt4fcq4sd7gzl", "BondStatus":"bonded" }, ... ]
Warning
The response from this endpoint uses different types off name conventions! For example ‘MinSelfDelegation’ and ‘max_change_rate’.
Warning
This endpoint returns numbers as string(eg. “volume”:”2100”) or integer(eg. “resolution”:5)
- Returns
list with validators.
-
get_balance
(swth_address: str) → dict¶ Get balance which includes available, in open orders and open positions.
Example:
# wallet behind Devel And Co validator public_client.get_balance("swth1vwges9p847l9csj8ehrlgzajhmt4fcq4sd7gzl")
The expected return result for this function is as follows:
{ "cel1":{ "available":"0.0007", "order":"0", "position":"0", "denom":"cel1" }, "eth1":{ "available":"0.000064752601707981", "order":"0", "position":"0", "denom":"eth1" }, "nex1":{ "available":"0.00012289", "order":"0", "position":"0", "denom":"nex1" }, "nneo2":{ "available":"0.00031555", "order":"0", "position":"0", "denom":"nneo2" }, "swth":{ "available":"41.13439708", "order":"0", "position":"0", "denom":"swth" }, "usdc1":{ "available":"0.045376", "order":"0", "position":"0", "denom":"usdc1" }, "wbtc1":{ "available":"0.00000029", "order":"0", "position":"0", "denom":"wbtc1" } }
Note
Only non zero balances are returned.
Note
Values are already in human readable format.
- Parameters
swth_address – tradehub switcheo address starting with ‘swth1’ on mainnet and ‘tswth1’ on testnet.
- Returns
dict with currently holding tokens.
-
get_block
(block_nbr: int = 1)¶
-
get_block_time
() → str¶ Get the block time in format HH:MM:SS.ZZZZZZ.
Example:
public_client.get_block_time()
The expected return result for this function is as follows:
"00:00:02.190211"
Warning
This endpoint returns only a string.
- Returns
block time as string.
-
get_blocks
(before_id: Optional[int] = None, after_id: Optional[int] = None, order_by: Optional[str] = None, swth_valcons: Optional[str] = None, limit: Optional[int] = None) → List[dict]¶ Get latest blocks or request specific blocks.
Example:
public_client.get_blocks()
The expected return result for this function is as follows:
[ { "block_height":"6103923", "time":"2021-01-09T14:15:53.071509+01:00", "count":"1", "proposer_address":"swthvalcons17m2ueqqqt8u0jz4rv5kvk4kg0teel4sckytjlc" }, { "block_height":"6103922", "time":"2021-01-09T14:15:50.824548+01:00", "count":"0", "proposer_address":"swthvalcons1zecfdrf22f6syz8xj4vn8jsvsalxdhwl9tlflk" }, ... ]
Warning
This endpoint is not well documented in official documents. The parameters are NOT required.
- Parameters
before_id – Before block height(exclusive).
after_id – After block height(exclusive).
order_by – Not specified yet.
swth_valcons – Switcheo tradehub validator consensus starting with ‘swthvalcons1’ on mainnet and ‘tswthvalcons1’ on testnet.
limit – Limit the responded result. Values greater than 200 have no effect and a maximum off 200 results are returned.
- Returns
List with found blocks matching the requested parameters. Can be empty list [].
-
get_candlesticks
(market: str, granularity: int, from_epoch: int, to_epoch: int) → List[dict]¶ Get candlesticks for a market.
Example:
public_client.get_candlesticks("swth_eth1", 5, 1610203000, 1610203090)
The expected return result for this function is as follows:
[ { "id":38648, "market":"swth_eth1", "time":"2021-01-09T15:35:00+01:00", "resolution":5, "open":"0.0000212", "close":"0.0000212", "high":"0.0000212", "low":"0.0000212", "volume":"2100", "quote_volume":"0.04452" }, ... ]
Warning
This endpoint is not well documented in official documents. The example market swth_eth does not exist on mainnet. The correct market ticker is ‘swth_eth1’. See get_markets() for correct tickers.
Warning
If any off the required parameters is not provided or incorrect the server responses with 500 status codes.
Warning
Responses are marked as ‘plain’ and not as ‘text/json’.
Warning
This endpoint returns numbers as string(ex. “volume”:”2100”) or integer(ex. “resolution”:5)
- Raises
ValueError – If ‘granularity’ is not 1, 5, 30, 60, 360 or 1440.
- Parameters
market – Market ticker used by blockchain (eg. swth_eth1).
granularity – Candlestick period in minutes, possible values are: 1, 5, 30, 60, 360 or 1440.
from_epoch – Start of time range for data in epoch seconds.
to_epoch – End of time range for data in epoch seconds.
- Returns
List with candles as dict.
-
get_commitment_curve
()¶
-
get_delegation_rewards
(swth_address: str) → dict¶ Request delegation rewards made by a tradehub wallet.
Example:
# wallet behind Devel And Co validator public_client.get_delegation_rewards("swth1vwges9p847l9csj8ehrlgzajhmt4fcq4sd7gzl")
The expected return result for this function is as follows:
{ "height": "6104998", "result": { "rewards": [ { "validator_address": "swthvaloper1vwges9p847l9csj8ehrlgzajhmt4fcq4dmg8x0", "reward": [ { "denom": "swth", "amount": "7928468882.342780820000000000" }, ... ] }, ... ], "total": [ { "denom": "cel1", "amount": "0.032116540000000000" }, ... ] } }
Warning
Only non zero balances are returned.
Warning
Values are NOT in human readable format even if the values contain a decimal separator.
Warning
This endpoint returns amounts which are NOT human readable values. Consider ‘base_precision’ and ‘quote_precision’ to calculate a multiplication factor = 10 ^ (‘base_precision’ - ‘quote_precision’)
Note
This endpoint does not include unclaimed commissions off a validator. If a validator wallet is requested only the rewards earned by delegation are returned.
- Parameters
swth_address – tradehub switcheo address starting with ‘swth1’ on mainnet and ‘tswth1’ on testnet.
- Returns
return dict with generated unclaimed rewards.
-
get_distribution_parameters
()¶
-
get_external_transfers
(swth_address: str) → List[dict]¶ Get external transfers(withdraws or deposits) from other blockchains.
Example:
# wallet Devel public_client.get_delegation_rewards("swth1qlue2pat9cxx2s5xqrv0ashs475n9va963h4hz")
The expected return result for this function is as follows:
[ { "address":"swth1qlue2pat9cxx2s5xqrv0ashs475n9va963h4hz", "amount":"0.9826", "block_height":5937838, "blockchain":"eth", "contract_hash":"9a016ce184a22dbf6c17daa59eb7d3140dbd1c54", "denom":"eth1", "fee_address":"swth1prv0t8j8tqcdngdmjlt59pwy6dxxmtqgycy2h7", "fee_amount":"0.0174", "id":"12853", "status":"success", "symbol":"ETH", "timestamp":1609839309, "token_name":"Ethereum", "transaction_hash":"", "transfer_type":"deposit" }, ... ]
Warning
This endpoint returns numbers as string(eg. “id”:”12853”) or integer(eg. “timestamp”:1609839309)
Note
This endpoint return amounts in human readable format.
- Parameters
swth_address – tradehub switcheo address starting with ‘swth1’ on mainnet and ‘tswth1’ on testnet.
- Returns
List with external transfers
-
get_inflation_start_time
()¶
-
get_insurance_fund_balance
()¶ Warning
This endpoint is not working yet.
- Returns
-
get_latest_blocks
()¶
-
get_leverage
(swth_address: str, market: str)¶ Warning
This endpoint is not working yet.
- Parameters
swth_address –
market –
- Returns
-
get_liquidations
(before_id: int, after_id: int, order_by: str, limit: int)¶ Warning
This endpoint is not working yet.
- Parameters
before_id –
after_id –
order_by –
limit –
- Returns
-
get_liquidity_pools
()¶
-
get_market
(market: str) → dict¶ Get information about a market.
Example:
public_client.get_market("swth_eth1")
The expected return result for this function is as follows:
{ "type":"", "name":"swth_eth1", "display_name":"SWTH_ETH", "description":"SWTH/ETH Spot Market", "market_type":"spot", "base":"swth", "base_name":"Switcheo", "base_precision":8, "quote":"eth1", "quote_name":"Ethereum", "quote_precision":18, "lot_size":"1", "tick_size":"0.0000001", "min_quantity":"200", "maker_fee":"-0.0005", "taker_fee":"0.0025", "risk_step_size":"0", "initial_margin_base":"1", "initial_margin_step":"0", "maintenance_margin_ratio":"0", "max_liquidation_order_ticket":"0", "max_liquidation_order_duration":0, "impact_size":"0", "mark_price_band":0, "last_price_protected_band":0, "index_oracle_id":"", "expiry_time":"1970-01-01T01:00:00+01:00", "is_active":true, "is_settled":false, "closed_block_height":0, "created_block_height":0 }
Warning
This endpoint is not well documented in official documents. The example market swth_eth does not exist on mainnet. The correct market ticker is ‘swth_eth1’. See get_markets() for correct tickers.
Warning
This endpoint returns numbers as string(eg. “lot_size”:”1”) or integer(eg. “base_precision”:8).
Warning
This endpoint returns the same dict structure even the market does not exist with default values!
- Parameters
market – Market ticker used by blockchain (eg. swth_eth1).
- Returns
-
get_market_stats
(market: Optional[str] = None) → List[dict]¶ Get statistics about one or all markets.
Example:
public_client.get_market_stats()
The expected return result for this function is as follows:
[ { "day_high":"0.0000215", "day_low":"0.000021", "day_open":"0.0000211", "day_close":"0.0000212", "day_volume":"436030", "day_quote_volume":"9.2787298", "index_price":"0", "mark_price":"0", "last_price":"0.00212000", "market":"swth_eth1", "market_type":"spot", "open_interest":"0" } ... ]
- Parameters
market – Market ticker used by blockchain (eg. swth_eth1).
- Returns
List with market stats as dict
-
get_markets
(market_type: Optional[str] = None, is_active: Optional[bool] = None, is_settled: Optional[bool] = None) → List[dict]¶ Get all markets or filter markets.
Example:
public_client.get_markets()
The expected return result for this function is as follows:
[ { "type":"", "name":"swth_eth1", "display_name":"SWTH_ETH", "description":"SWTH/ETH Spot Market", "market_type":"spot", "base":"swth", "base_name":"Switcheo", "base_precision":8, "quote":"eth1", "quote_name":"Ethereum", "quote_precision":18, "lot_size":"1", "tick_size":"0.0000001", "min_quantity":"200", "maker_fee":"-0.0005", "taker_fee":"0.0025", "risk_step_size":"0", "initial_margin_base":"1", "initial_margin_step":"0", "maintenance_margin_ratio":"0", "max_liquidation_order_ticket":"0", "max_liquidation_order_duration":0, "impact_size":"0", "mark_price_band":0, "last_price_protected_band":0, "index_oracle_id":"", "expiry_time":"1970-01-01T01:00:00+01:00", "is_active":true, "is_settled":false, "closed_block_height":0, "created_block_height":0 }, ... ]
Warning
This endpoint returns numbers as string(eg. “lot_size”:”1”) or integer(eg. “base_precision”:8)
- Parameters
market_type – type of the market can be ‘futures’ or ‘spot’
is_active – if only active markets should be returned
is_settled – if only settled markets should be returned
- Returns
List with returned market stats as dict
-
get_nodes
() → dict¶
-
get_oracle_result
(oracle_id: str)¶ Warning
This endpoint is not working yet.
- Parameters
oracle_id –
- Returns
-
get_oracle_results
()¶ Warning
This endpoint is not working yet.
- Returns
-
get_order
(order_id: str) → dict¶ Get a specific order by id.
Example:
public_client.get_order("4F54D2AE0D793F833806109B4278335BF3D392D4096B682B9A27AF9F8A8BCA58")
The expected return result for this function is as follows:
{ "order_id":"4F54D2AE0D793F833806109B4278335BF3D392D4096B682B9A27AF9F8A8BCA58", "block_height":6117321, "triggered_block_height":0, "address":"swth1wmcj8gmz4tszy5v8c0d9lxnmguqcdkw22275w5", "market":"eth1_usdc1", "side":"buy", "price":"1255.68", "quantity":"0.01", "available":"0.01", "filled":"0", "order_status":"open", "order_type":"limit", "initiator":"amm", "time_in_force":"gtc", "stop_price":"0", "trigger_type":"", "allocated_margin_denom":"usdc1", "allocated_margin_amount":"0", "is_liquidation":false, "is_post_only":false, "is_reduce_only":false, "type":"", "block_created_at":"2021-01-09T22:13:34.711571+01:00", "username":"", "id":"990817" }
- Parameters
order_id – Order identified by id
- Returns
Order as dict
-
get_orderbook
(market: str, limit: Optional[int] = None)¶ Get the orderbook from a market.
Example:
public_client.get_orderbook("swth_eth1")
The expected return result for this function is as follows:
{ "asks": [ { "price":"0.0000214", "quantity":"49863" }, { "price":"0.0000215", "quantity":"49446" }, ... ], "bids": [ { "price":"0.0000212", "quantity":"50248" }, { "price":"0.0000211", "quantity":"50295" }, ... ] }
Warning
This endpoint returns an empty ‘asks’ and ‘bids’ list if the market is not known.
- Parameters
market – Market ticker used by blockchain (eg. swth_eth1).
limit – Number off returned orders per side(asks, bids).
- Returns
Orderbook as ‘asks’ and ‘bids’ list
-
get_orders
(swth_address: Optional[str] = None, before_id: Optional[int] = None, after_id: Optional[int] = None, market: Optional[str] = None, order_type: Optional[str] = None, initiator: Optional[str] = None, order_status: Optional[str] = None, limit: Optional[int] = None) → List[dict]¶ Request last orders or filter them.
Example:
public_client.get_orders()
The expected return result for this function is as follows:
[ { "order_id":"4F54D2AE0D793F833806109B4278335BF3D392D4096B682B9A27AF9F8A8BCA58", "block_height":6117321, "triggered_block_height":0, "address":"swth1wmcj8gmz4tszy5v8c0d9lxnmguqcdkw22275w5", "market":"eth1_usdc1", "side":"buy", "price":"1255.68", "quantity":"0.01", "available":"0.01", "filled":"0", "order_status":"open", "order_type":"limit", "initiator":"amm", "time_in_force":"gtc", "stop_price":"0", "trigger_type":"", "allocated_margin_denom":"usdc1", "allocated_margin_amount":"0", "is_liquidation":false, "is_post_only":false, "is_reduce_only":false, "type":"", "block_created_at":"2021-01-09T22:13:34.711571+01:00", "username":"", "id":"990817" }, ... ]
Warning
This endpoint is not well documented in official documents. Parameter account is NOT required! It is possible to provide more parameters, known ones are documented here.
Warning
This endpoint returns numbers as string(eg. “id”:”990817”) or integer(eg. “block_height”:6117321)
- Parameters
swth_address – tradehub switcheo address starting with ‘swth1’ on mainnet and ‘tswth1’ on testnet.
before_id – return orders before id(exclusive).
after_id – return orders after id(exclusive).
market – Market ticker used by blockchain (eg. swth_eth1).
order_type – Return specific orders, allowed values: ‘limit’, ‘market’, ‘stop-market’ or ‘stop-limit’.
initiator – Filter by user or automated market maker orders, allowed values: ‘user’ or ‘amm’.
order_status – Filter by order status, allowed values: ‘open’ or ‘closed’.
limit – Limit response, values above 200 have no effect.
- Returns
List off orders as dict
-
get_position
(swth_address: str, market: str)¶ Warning
This endpoint is not working yet.
- Parameters
swth_address –
market –
- Returns
-
get_positions
(swth_address: str)¶ Warning
This endpoint is not working yet.
- Parameters
swth_address –
- Returns
-
get_positions_sorted_by_pnl
(market)¶ Warning
This endpoint is not working yet.
- Parameters
market –
- Returns
-
get_positions_sorted_by_risk
(market)¶ Warning
This endpoint is not working yet.
- Parameters
market –
- Returns
-
get_positions_sorted_by_size
(market)¶ Warning
This endpoint is not working yet.
- Parameters
market –
- Returns
-
get_prices
(market: Optional[str]) → dict¶ Get prices off a market.
Example:
public_client.get_prices("swth_eth1")
The expected return result for this function is as follows:
{ "last":"207000", "index":"0", "fair":"0", "mark":"0", "mark_avg":"0", "settlement":"0", "fair_index_delta_avg":"0", "market":"", "marking_strategy":"", "index_updated_at":"0001-01-01T00:00:00Z", "last_updated_at":"2021-01-09T22:50:59.068526+01:00", "block_height":0 }
Warning
This endpoint is not well documented in official documents. Parameter ‘market’ is NOT required, but strongly recommended. The return result has an empty ‘market’ field.
Warning
This endpoint returns amounts which are NOT human readable values. Consider ‘base_precision’ and ‘quote_precision’ to calculate a multiplication factor = 10 ^ (‘base_precision’ - ‘quote_precision’)
Warning
This endpoint returns numbers as string(eg. “last”:”207000”) or integer(eg. “block_height”:0)
Warning
This endpoint returns a result even if the market is not known. Result contains default values.
- Parameters
market – Market ticker used by blockchain (eg. swth_eth1).
- Returns
Prices as dict
-
get_profile
(swth_address: str) → dict¶ Get profile from a tradehub wallet.
Example:
public_client.get_profile("swth1qlue2pat9cxx2s5xqrv0ashs475n9va963h4hz")
The expected return result for this function is as follows:
{ "address":"swth1qlue2pat9cxx2s5xqrv0ashs475n9va963h4hz", "last_seen_block":"6036318", "last_seen_time":"2021-01-07T21:47:14.593249+01:00", "twitter":"", "username":"devel484" }
- Parameters
swth_address – tradehub switcheo address starting with ‘swth1’ on mainnet and ‘tswth1’ on testnet.
- Returns
Profile as dict
-
get_reward_curve
()¶
-
get_rich_list
(token: str)¶ Warning
This endpoint is not working yet.
- Parameters
token –
- Returns
-
get_staking_pool
()¶
-
get_status
() → dict¶ Return cosmos RPC status endpoint.
Example:
public_client.get_status()
The expected return result for this function is as follows:
{ "jsonrpc": "2.0", "id": -1, "result": { "node_info": { "protocol_version": { "p2p": "7", "block": "10", "app": "0" }, "id": "f4cee80e4dec5a686139cb82729118e15f7ce19c", "listen_addr": "tcp://0.0.0.0:26656", "network": "switcheo-tradehub-1", "version": "0.33.7", "channels": "4020212223303800", "moniker": "Devel Sentry Node 2", "other": { "tx_index": "on", "rpc_address": "tcp://0.0.0.0:26659" } }, "sync_info": { "latest_block_hash": "4A2C89C105D7864AA74C9DE4752AF5B59E96045EBAF984C69DD447C4524EC36F", "latest_app_hash": "773651392EEDBFF6AEE088F76E7D75F2932B4D9F74CA27D568F706ADFC12B174", "latest_block_height": "6119142", "latest_block_time": "2021-01-09T22:18:52.722611018Z", "earliest_block_hash": "B4AF1F3D3D3FD5795BDDB7A6A2E6CA4E34D06338505D6EC46DD8F99E72ADCDAB", "earliest_app_hash": "", "earliest_block_height": "1", "earliest_block_time": "2020-08-14T07:32:27.856700491Z", "catching_up": false }, "validator_info": { "address": "DCB03C204B7F94765B4ADCE1D8BEE88AA43AE811", "pub_key": { "type": "tendermint/PubKeyEd25519", "value": "1GmDSymN6jTqQlZA2KeyzqknIncGMMrwnnas/DWGNOI=" }, "voting_power": "0" } } }
- Returns
Status as dict
-
get_token
(denom) → dict¶ Get information about a token.
Example:
public_client.get_token("swth")
The expected return result for this function is as follows:
{ "name":"Switcheo", "symbol":"swth", "denom":"swth", "decimals":8, "blockchain":"neo", "chain_id":4, "asset_id":"32e125258b7db0a0dffde5bd03b2b859253538ab", "is_active":true, "is_collateral":false, "lock_proxy_hash":"17d0f66eca7fcbfddc8d9706f20513bf5d7419cd", "delegated_supply":"100000000000000000", "originator":"swth1mw90en8tcqnvdjhp64qmyhuq4qasvhy25dpmvw" }
Warning
This endpoint returns numbers as string(eg. “delegated_supply”:”100000000000000000”) or integer(eg. “decimals”:8)
- Parameters
denom – Denom used by tradehub.
- Returns
Information about token as dict.
-
get_token_details
() → dict¶
-
get_tokens
() → List[dict]¶ Get all known tokens on tradehub chain.
Example:
public_client.get_tokens()
The expected return result for this function is as follows:
[ { "name":"Switcheo", "symbol":"swth", "denom":"swth", "decimals":8, "blockchain":"neo", "chain_id":4, "asset_id":"32e125258b7db0a0dffde5bd03b2b859253538ab", "is_active":true, "is_collateral":false, "lock_proxy_hash":"17d0f66eca7fcbfddc8d9706f20513bf5d7419cd", "delegated_supply":"100000000000000000", "originator":"swth1mw90en8tcqnvdjhp64qmyhuq4qasvhy25dpmvw" }, ... ]
Warning
This endpoint returns numbers as string(eg. “delegated_supply”:”100000000000000000”) or integer(eg. “decimals”:8)
- Returns
List with tokens as dict
-
get_top_r_profits
(market: str, limit: int)¶ Warning
This endpoint is not working yet.
- Parameters
market –
limit –
- Returns
-
get_total_balances
()¶ Warning
This endpoint is not working yet.
- Returns
-
get_trades
(market: Optional[str] = None, before_id: Optional[int] = None, after_id: Optional[int] = None, order_by: Optional[str] = None, limit: Optional[int] = None, swth_address: Optional[str] = None) → List[dict]¶ Get recent trades or filter trades.
Example:
public_client.get_trades()
The expected return result for this function is as follows:
[ { "id":"103965", "block_created_at":"2021-01-10T21:59:53.563633+01:00", "taker_id":"11DCD0B7B0A0021476B8C801FD627B297EBDBBE7436BFEEC5ADB734DCF3C9291", "taker_address":"swth1qlue2pat9cxx2s5xqrv0ashs475n9va963h4hz", "taker_fee_amount":"0.000007", "taker_fee_denom":"eth1", "taker_side":"buy", "maker_id":"A59962E7A61F361F7DE5BF00D7A6A8225668F449D73301FB9D3787E4C13DEE60", "maker_address":"swth1wmcj8gmz4tszy5v8c0d9lxnmguqcdkw22275w5", "maker_fee_amount":"-0.0000035", "maker_fee_denom":"eth1", "maker_side":"sell", "market":"eth1_usdc1", "price":"1251.51", "quantity":"0.007", "liquidation":"", "taker_username":"devel484", "maker_username":"", "block_height":"6156871" }, ... ]
- Parameters
market – Market ticker used by blockchain (eg. swth_eth1).
before_id – get orders before id(exclusive).
after_id – get orders after id(exclusive).
order_by – TODO no official documentation.
limit – limit the responded result, values above 200 have no effect.
swth_address – tradehub switcheo address starting with ‘swth1’ on mainnet and ‘tswth1’ on testnet.
- Returns
List off trades as dict
-
get_transaction
(tx_hash: str)¶ Get a transaction by providing the hash.
Example:
public_client.get_transaction("A93BEAC075562D4B6031262BDDE8B9A720346A54D8570A881E3671FEB6E6EFD4")
The expected return result for this function is as follows:
{ "id":"311003", "hash":"A93BEAC075562D4B6031262BDDE8B9A720346A54D8570A881E3671FEB6E6EFD4", "address":"swth1vwges9p847l9csj8ehrlgzajhmt4fcq4sd7gzl", "username":"", "msgs": [ { "msg_type":"vote", "msg":"{"proposal_id":10,"voter":"swth1vwges9p847l9csj8ehrlgzajhmt4fcq4sd7gzl","option":"Yes"}" }, ... ], "code":"0", "gas_used":"64818", "gas_limit":"200000", "memo":"", "height":"6034329", "block_time":"2021-01-07T20:35:08.526914+01:00" }
Warning
This endpoint returns the same dict structure even if the transaction does not exist with default values!
Note
The field ‘msg’ contain a escaped JSON string.
- Parameters
tx_hash – Transaction hash for a specific transaction.
- Returns
-
get_transaction_fee_type
(transaction_type: str)¶
-
get_transaction_log
(transaction_hash: str)¶
-
get_transaction_types
() → List[str]¶ Get transaction types used by tradehub.
Example:
public_client.get_transaction_types()
The expected return result for this function is as follows:
[ "submit_proposal", "create_pool", "set_reward_curve", "send", ... ]
- Returns
List with transaction types as strings.
-
get_transactions
(swth_address: Optional[str] = None, msg_type: Optional[str] = None, height: Optional[int] = None, start_block: Optional[int] = None, end_block: Optional[int] = None, before_id: Optional[int] = None, after_id: Optional[int] = None, order_by: Optional[str] = None, limit: Optional[int] = None) → List[dict]¶ Get latest transactions or filter them.
Example:
public_client.get_transactions()
The expected return result for this function is as follows:
[ { "id":"322811", "hash":"9742B27016F08484D8FADFD361C34563F3FDA92A36A8DD3B844A2F86E3552451", "address":"swth1xkahzn8ymps6xdu6feulutawu42fkyqz5fgvhx", "username":"", "msg_type":"create_order", "msg":'{"market":"eth1_usdc1","side":"buy","quantity":"0.019","type":"limit","price":"1283.98","is_post_only":false,"is_reduce_only":false,"originator":"swth1xkahzn8ymps6xdu6feulutawu42fkyqz5fgvhx"}', "code":"0", "gas_used":"140666", "gas_limit":"100000000000", "memo":"", "height":"6119373", "block_time":"2021-01-09T23:27:10.247711+01:00" }, ... ]
Note
The field ‘msg’ contain a escaped JSON string.
- Parameters
swth_address – tradehub switcheo address starting with ‘swth1’ on mainnet and ‘tswth1’ on testnet.
msg_type – filter by msg_type, allowed values can be fetch with ‘get_transaction_types’
height – get order at a specific height
start_block – get orders after block(exclusive)
end_block – get orders before block(exclusive)
before_id – get orders before id(exclusive)
after_id – get orders after id(exclusive)
order_by – TODO no official documentation
limit – limit the responded result, values above 200 have no effect
- Returns
List with transactions as dict
-
get_transactions_fees
()¶
-
get_username_check
(username: str) → bool¶ Check if a username is taken or not.
Example:
public_client.get_username_check("devel484")
The expected return result for this function is as follows:
true
Warning
This endpoint do not return a JSON response, only true or false
- Parameters
username – name to check
- Returns
True if is taken and false if free
-
get_validator_delegations
(operator_address)¶
-
get_validator_missed_blocks
()¶
-
get_validator_public_node_ips
()¶
-
get_validator_public_nodes
()¶
-
get_validator_signing_info
(limit: int = 100)¶
-
get_validators
(status: Optional[str] = None)¶
-
get_vault_types
() → list¶ - Parameters
token –
:return :
-
get_vaults
(swth_address: str) → dict¶
-
parse_validator_status
(request_json: dict, validator_ip: str)¶ Function to parse each peer’s JSON element and build information about each.
Execution of this function is as follows:
parse_validator_status(request_json='/status', validator_ip='54.255.5.46')
The expected return result for this function is as follows:
{ 'moniker': 'spock', 'id': 'ca1189045e84d2be5db0a1ed326ce7cd56015f11', 'ip': '54.255.5.46', 'version': '0.33.7', 'network': 'switcheo-tradehub-1', 'latest_block_hash': 'DF194D43058D3CD89DD98A7DA28164B239B9693C822A1DB16CCC27FB49CA587B', 'latest_block_height': '7995864', 'latest_block_time': '2021-02-27T19:51:00.162091183Z', 'earliest_block_height': '1', 'earliest_block_time': '2020-08-14T07:32:27.856700491Z', 'catching_up': False, 'validator_address': '7091A72888509B3F3069231081621DC988D63542', 'validator_pub_key_type': 'tendermint/PubKeyEd25519', 'validator_pub_key': 'epMp0h65WflL7r8tPGQwusVMbCHgy7ucRg8eDlEJPW0=', 'validator_voting_power': '0' }
- Parameters
request_json – Dictionary of the return response from the validator status request.
validator_ip – String of the IP address to connect to.
- Returns
Dictionary of validator information.
-
redelegate_tokens
(message: tradehub.types.BeginRedelegatingTokensMessage, fee: Optional[dict] = None)[source]¶ Function to move tokens from one validator to another on the Tradehub network.
Execution of this function is as follows:
redelegate_tokens(message=types.BeginRedelegatingTokensMessage(delegator_address=self._wallet.address, validator_src_address='tswthvaloper1hn0spc9plh5ker8lrtzyz9uqfe3xk2yn0c6nyf', validator_dst_address='tswthvaloper10229tj7kh2mzwsn9cnfxuq3sqjuph860dlezpr', amount=types.AmountMessage(amount='0.1', denom='swth'))
- Parameters
message – BeginRedelegatingTokensMessage Type that is a class of attributes required to make this on-chain action.
fee – Dict of the fee type, generally this can be left blank and allow the API to handle this.
- Returns
Dictionary of the transaction response sent on-chain, look in the logs to be sure it matches what was sent.
-
remove_liquidity
(message: tradehub.types.RemoveLiquidityMessage, fee: Optional[dict] = None)[source]¶
-
send_tokens
(message: tradehub.types.SendTokensMessage, fee: Optional[dict] = None)[source]¶ Function to send tokens from your wallet to a recipient.
Execution of this function is as follows:
sent_tokens(message=types.SendTokensMessage(to_address=send_address, amount=types.SendTokensAmount(amount='10.1', denom='swth')))
- Parameters
message – SendTokensMessage Type that is a class of attributes required to make this on-chain action.
fee – Dict of the fee type, generally this can be left blank and allow the API to handle this.
- Returns
Dictionary of the transaction response sent on-chain, look in the logs to be sure it matches what was sent.
-
sentry_status_request
(uri: bool = False)¶ This function is here to ensure the nodes that have open network connections also have their persistence service running. Many times the network connection is open for communication but the persistence service will not be on.
Execution of this function is as follows:
sentry_status_request(uri=True)
- Parameters
uri – Bool value for a URI or IP address.
-
set_fees
(transaction_cnt: int, transaction_type: str, fee: dict)¶ Standardize, find, and calculate fees for the number of transactions.
Execution of this function is as follows:
set_fees(transaction_cnt=1, transaction_type="UPDATE_PROFILE_MSG_TYPE", fee=None)
- Returns
Dictionary for the fee’s that will be needed for this transaction.
-
set_message_standards
(messages: list)¶ Standardize messages, adding an originator or takingo ut keys that don’t exist.
Execution of this function is as follows:
set_message_standards(messages=[message])
- Returns
Three return variables, 1 for each input but run through standardizations.
-
set_transaction_standards
(messages: list, transaction_type: str, fee: dict)¶ This function sets standards for the messages in the transaction submitted to the chain. Fees, Integer precision as string, and Transaction messages are required.
Execution of this function is as follows:
submit_transaction_standards(messages=[message], transaction_type="UPDATE_PROFILE_MSG_TYPE", fee=None)
- Returns
Three return variables, 1 for each input but run through standardizations.
-
sign_and_broadcast
(messages: list, transaction_types: list, fee: dict)¶ Now that messages are standardized we need to sign the transaction and broadcast it. The actual signature part will be handled by the Wallet Client to avoid leaking keys between classes.
Execution of this function is as follows:
sign_and_broadcast(messages=messages_list, transaction_types=transactions_list, fee=fee_dict)
- Returns
Dictionary for the transaction submitted on-chain.
-
sign_message
(messages: list, memo: Optional[str] = None, fee: Optional[dict] = None)¶ Sign the messages constructed in the previous function.
Execution of this function is as follows:
sign_message(messages=messages_list, memo=None, fee=None)
- Returns
String as a result of the signed messages.
-
sign_transaction
(messages: list, transaction_types: list, memo: Optional[str] = None, fee: Optional[dict] = None)¶ A Signature has the following sequence. https://docs.switcheo.org/#/?id=authentication (1) Construct a list of dictionaries combining message and message types together. <- construct_concrete_messages (2) Sign the list of messages generated in step (1). <- sign_message (3) Take the signature from step (2) and create a signature JSON message. <- construct_signatures (4) Take the signature JSON from step (3) and wrape it in a transaction JSON message. <- construct_transaction (5) Take the transaction JSON from step (4) and create the final layer of the transaction JSON message. <- construct_complete_transaction
Execution of this function is as follows:
sign_transaction(messages=messages_list, transaction_types=transactions_list, fee=fee_dict)
- Returns
Dictionary for a complete transaction message.
-
stake_pool_token
(message: tradehub.types.StakePoolTokenMessage, fee: Optional[dict] = None)[source]¶
-
stake_switcheo
(message=<class 'tradehub.types.DelegateTokensMessage'>, fee: Optional[dict] = None)[source]¶ Function to stake (or delegate) Switcheo to validators on the Tradehub network.
Execution of this function is as follows:
stake_switcheo(message=types.DelegateTokensMessage(delegator_address=self._wallet.address, validator_address='tswthvaloper1hn0spc9plh5ker8lrtzyz9uqfe3xk2yn0c6nyf', amount=types.DelegateTokensAmount(amount = '10.1', denom = 'swth')))
- Parameters
message – DelegateTokensMessage Type that is a class of attributes required to make this on-chain action.
fee – Dict of the fee type, generally this can be left blank and allow the API to handle this.
- Returns
Dictionary of the transaction response sent on-chain, look in the logs to be sure it matches what was sent.
-
submit_transaction_on_chain
(messages: list, transaction_type: str, fee: dict)¶ This is the function that every function in higher classes should call. Every function in the authenticated_client calls this function. It standardizes the transaction construction and the signing and broadcasting.
Execution of this function is as follows:
submit_transaction_on_chain(messages=[message], transaction_type="UPDATE_PROFILE_MSG_TYPE", fee=None)
- Returns
Dictionary for the transaction submitted on-chain.
-
tradehub_get_request
(path: str, params: Optional[dict] = None)¶ This is a wrapper for the get request function to allow for retrying network calls on different available validators if a request fails.
Execution of this function is as follows:
tradehub_get_request(path='/txs')
- Parameters
path – String of the path being used for the network request that is going to be made.
params – Dict values that will added to the get request.
- Returns
Dictionary of the return request based on the network path sent.
-
tradehub_post_request
(path: str, data: Optional[dict] = None, json_data: Optional[dict] = None, params: Optional[dict] = None)¶ This is a wrapper for the post request function to allow for retrying network calls on different available validators if a request fails.
Execution of this function is as follows:
tradehub_post_request(path='/txs')
- Parameters
path – String of the path being used for the network request that is going to be made.
data – Dict values that will added to the post request.
json_data – Dict values that will added to the post request.
params – Dict values that will added to the post request.
- Returns
Dictionary of the return request based on the network path sent.
-
unbond_tokens
(message: tradehub.types.BeginUnbondingTokensMessage, fee: Optional[dict] = None)[source]¶ Function to unbond tokens a validator on the Tradehub network.
Execution of this function is as follows:
unbond_tokens(message=types.BeginUnbondingTokensMessage(delegator_address=self._wallet.address, validator_address='tswthvaloper1hn0spc9plh5ker8lrtzyz9uqfe3xk2yn0c6nyf', amount=types.AmountMessage(amount='0.1', denom='swth')))
- Parameters
message – BeginUnbondingTokensMessage Type that is a class of attributes required to make this on-chain action.
fee – Dict of the fee type, generally this can be left blank and allow the API to handle this.
- Returns
Dictionary of the transaction response sent on-chain, look in the logs to be sure it matches what was sent.
-
unstake_pool_token
(message: tradehub.types.UnstakePoolTokenMessage, fee: Optional[dict] = None)[source]¶
-
update_account_details
() → None¶ Triggers an update to fetch current sequence number.
- Returns
None
-
update_profile
(message: tradehub.types.UpdateProfileMessage, fee: Optional[dict] = None)[source]¶ Function that makes the network requests to the Tradehub validators across the network.
Execution of this function is as follows:
update_profile(message=types.UpdateProfileMessage(username='PythonCICD', twitter='PythonCICD'))
The expected return result for this function is as follows:
{ 'height': '1927295', 'txhash': 'C6AF947EE35EE5282BD140F9F51614FA1C7ACADAB263B921621097C786C06977', 'raw_log': ..., 'logs': ..., 'gas_wanted': '100000000000', 'gas_used': '68345' }
- Parameters
message – UpdateProfileMessage Type that is a class of attributes required to make this on-chain action.
fee – Dict of the fee type, generally this can be left blank and allow the API to handle this.
- Returns
Dictionary of the transaction response sent on-chain.
-
validator_crawler_mp
()¶ Crawl the Tradehub Validators to test for available API endpoints.
Execution of this function is as follows:
validator_crawler_mp()
-
validator_status_request
(validator_ip: str)¶ Function that makes the network requests to the Tradehub validators across the network.
Execution of this function is as follows:
validator_status_request(validator_ip='54.255.5.46')
The expected return result for this function is as follows:
{ 'moniker': 'spock', 'id': 'ca1189045e84d2be5db0a1ed326ce7cd56015f11', 'ip': '54.255.5.46', 'version': '0.33.7', 'network': 'switcheo-tradehub-1', 'latest_block_hash': 'DF194D43058D3CD89DD98A7DA28164B239B9693C822A1DB16CCC27FB49CA587B', 'latest_block_height': '7995864', 'latest_block_time': '2021-02-27T19:51:00.162091183Z', 'earliest_block_height': '1', 'earliest_block_time': '2020-08-14T07:32:27.856700491Z', 'catching_up': False, 'validator_address': '7091A72888509B3F3069231081621DC988D63542', 'validator_pub_key_type': 'tendermint/PubKeyEd25519', 'validator_pub_key': 'epMp0h65WflL7r8tPGQwusVMbCHgy7ucRg8eDlEJPW0=', 'validator_voting_power': '0', 'validator_status': 'Active', 'connected_nodes': [ { 'node_id': 'd57a64f41487b5e421e91b71dceb0784cae57733', 'node_ip': '195.201.82.228', 'node_full': 'd57a64f41487b5e421e91b71dceb0784cae57733@195.201.82.228' }, ... ] }
- Parameters
validator_ip – String of the IP address to connect to.
- Returns
Dictionary of validators that the crawler has found with the status.
-
websocket_status_check
(ip: str, port: int = 5000)¶ Function to check if the websocket port is open for communication. This is called as part of the sentry check because calling the websocket also requires the persistence service to be available.
Execution of this function is as follows:
websocket_status_check(ip='54.255.5.46', port=5000)
- Parameters
ip – String of the IP address to connect to.
port – Int value for the port to be checked.