Transactions

class services.perpetual.api.gateway.transactions.Transaction

Transaction

Container for the different transaction types.

class services.perpetual.api.gateway.transactions.Deposit

Deposit

Parameters
  • position_id (int) – The position ID to deposit to.

  • public_key (int) – The position ID owner’s public key.

  • amount (int) – Amount of collateral asset to be deposited; required to be >= 0.

Example

{
    "amount": "2569146471088859254",
    "position_id": "7758176404715800194",
    "public_key": "0x37ebdcde87a1613e443df789558867f5ba91faf7a024204f7c1bd874da5e70a",
    "type": "DEPOSIT"
}
class services.perpetual.api.gateway.transactions.Withdrawal

Withdrawal

Parameters
  • position_id (int) – The position ID to withdraw from.

  • public_key (int) – The position ID owner’s public key.

  • amount (int) – The amount to withdraw.

  • nonce (int) – Unique nonce issued by the caller.

  • expiration_timestamp (int) – The timestamp after which this request is no longer valid.

  • signature (Signature) – The position owner’s signature.

Example

{
    "amount": "2569146471088859254",
    "expiration_timestamp": "631194409",
    "nonce": "3433407905",
    "position_id": "7758176404715800194",
    "public_key": "0x35989d400b783796677a03aec2a321cd7e0f8e85d9e62f595209ca9b17beefc",
    "signature": {
        "r": "0x4b3b9e4934d635f6d1d015212cf773217abd65a32a804f0bd5c6cf3eab926f4",
        "s": "0x377ea02a33203f8f497ff1290e9b59c1e586134e41c3287b262f9c6e02e66c2"
    },
    "type": "WITHDRAWAL"
}
class services.perpetual.api.gateway.transactions.WithdrawalToAddress

WithdrawalToAddress

Parameters
  • position_id (int) – The position ID to withdraw from.

  • public_key (int) – The position ID owner’s public key.

  • eth_address (str) – The Ethereum address to move the funds into.

  • amount (int) – The amount to withdraw.

  • nonce (int) – Unique nonce issued by the caller.

  • expiration_timestamp (int) – The timestamp after which this request is no longer valid.

  • signature (Signature) – The position owner’s signature.

Example

{
    "amount": "1682637359498011204",
    "eth_address": "0xB6aD5EfBd6aDfa29dEfad5BC0f8cE0ad57d4c5Fb",
    "expiration_timestamp": "2101470722",
    "nonce": "4265854110",
    "position_id": "7758176404715800194",
    "public_key": "0x1b9e4c42a399f6ce069127df5ad618489aad21b1687acf4d4b09e08744084a7",
    "signature": {
        "r": "0x18326a6181a507f701968f45f56799b890374a1e329c6b9a37ec3292d92b1f8",
        "s": "0x66dd6745be06d033149a2bcb686e3ec896fc914ff2cb52dcc1d34bbe220b639"
    },
    "type": "WITHDRAWAL_TO_ADDRESS"
}
class services.perpetual.api.gateway.transactions.ForcedWithdrawal

Forced Withdrawal

Parameters
  • position_id (int) – The position ID to withdraw from.

  • public_key (int) – The position ID owner’s public key.

  • amount (int) – The amount to withdraw.

  • is_valid (bool) – A flag that specifies the validity of the forced action.

Example

{
    "amount": "653212427667887001",
    "is_valid": false,
    "position_id": "12811351868539174612",
    "public_key": "0x758e9e1803bd82196a71da4b085725b195de5d9c50908e3a6399351982ced6",
    "type": "FORCED_WITHDRAWAL"
}
class services.perpetual.api.gateway.transactions.Trade

Trade

Parameters
  • party_a_order (Order) – Represents party a’s order.

  • party_b_order (Order) – Represents party b’s order.

  • actual_collateral (int) – The collateral amount sold in the trade.

  • actual_synthetic (int) – The synthetic amount sold in the trade.

  • actual_a_fee (int) – The amount party a paid for fees out of the maximal amount they were willing to pay.

  • actual_b_fee (int) – The amount party b paid for fees of the maximal amount they were willing to pay.

Example

{
    "actual_a_fee": "8791662011684601223",
    "actual_b_fee": "9309829342914403545",
    "actual_collateral": "7758176404715800194",
    "actual_synthetic": "15308084094301570617",
    "party_a_order": {
        "amount_collateral": "15334874138764573096",
        "amount_fee": "17677494534592486883",
        "amount_synthetic": "15460142528840632302",
        "asset_id_collateral": "0x57d05d11b570fd197b55746070ee051c731ee109b07255eab3c9cf8b6c579d",
        "asset_id_synthetic": "0x2",
        "expiration_timestamp": "3608164305",
        "is_buying_synthetic": true,
        "nonce": "1210484339",
        "order_type": "LIMIT_ORDER_WITH_FEES",
        "position_id": "4805234989534244506",
        "public_key": "0x6b974202431eb8c0692c9c8111528d947bc7e70f7ffefaffbab7455dfa5d4f7",
        "signature": {
            "r": "0x54730fcf60f37072926ba182d17e55e21104fbc22886d876a7e8b191b2d456f",
            "s": "0x1f32f41a809b2f2b888bddc2bdbf5ef709403a00d4e5e23dbaef09e55130464"
        }
    },
    "party_b_order": {
        "amount_collateral": "7800133567066683830",
        "amount_fee": "10547508580746848044",
        "amount_synthetic": "17015053283814123498",
        "asset_id_collateral": "0x57d05d11b570fd197b55746070ee051c731ee109b07255eab3c9cf8b6c579d",
        "asset_id_synthetic": "0x2",
        "expiration_timestamp": "3407305306",
        "is_buying_synthetic": false,
        "nonce": "2046685052",
        "order_type": "LIMIT_ORDER_WITH_FEES",
        "position_id": "5076743434755564658",
        "public_key": "0x7784139b0eee3f6fd937bba714acc2b199af2877565ba7c926d3f10d0bca378",
        "signature": {
            "r": "0x929a5a30bb98b23d0fcfcc75a1ff5f0f5a437edac75002cb6ebca78173ffd3",
            "s": "0x2abbf077eb504ae44b2cf1ca81c1aa73489a38aead87600a7dadf82bd39efcc"
        }
    },
    "type": "TRADE"
}
class services.perpetual.api.gateway.transactions.ForcedTrade

Forced Trade

Parameters
  • public_key_party_a (int) – Party a’s public key.

  • public_key_party_b (int) – Party b’s public key.

  • position_id_party_a (int) – The position ID of party a.

  • position_id_party_b (int) – The position ID of party b.

  • collateral_asset_id (int) – The collateral unique asset ID (as registered on the contract).

  • synthetic_asset_id (int) – The unique asset ID of the synthetic asset that is traded.

  • amount_collateral (int) – The amount of collateral asset traded.

  • amount_synthetic (int) – The amount of synthetic asset traded.

  • is_party_a_buying_synthetic (bool) – Specifies if party A is buying the synthetic asset.

  • nonce (int) – Unique nonce issued by the caller.

  • is_valid (bool) – A flag that specifies the validity of the forced action.

Example

{
    "amount_collateral": "7838377020387924882",
    "amount_synthetic": "11113581968013062307",
    "collateral_asset_id": "0x57d05d11b570fd197b55746070ee051c731ee109b07255eab3c9cf8b6c579d",
    "is_party_a_buying_synthetic": false,
    "is_valid": false,
    "nonce": "1284389859",
    "position_id_party_a": "9276979549170356654",
    "position_id_party_b": "18112525187809919137",
    "public_key_party_a": "0x3db6c6e82fab496fa87fbeed99848903a92a7ba339dbcda84663f3baa2a666a",
    "public_key_party_b": "0x7ad4c47197cceaf20de795ef88c7b1b7e5f27191fcda85c69c512e3326f23d7",
    "synthetic_asset_id": "0x1",
    "type": "FORCED_TRADE"
}
class services.perpetual.api.gateway.transactions.Transfer

Transfer

Parameters
  • amount (int) – The amount to transfer.

  • nonce (int) – Unique nonce issued by the caller.

  • sender_public_key (int) – The sender’s public key.

  • sender_position_id (int) – The position ID to transfer from.

  • receiver_public_key (int) – The receiver’s public key.

  • receiver_position_id (int) – The position ID to transfer to.

  • asset_id (int) – The unique asset ID (as registered on the contract) to transfer. Currently only the collateral asset is supported.

  • expiration_timestamp (int) – The timestamp after which this request is no longer valid.

  • signature (Signature) – The sender’s signature.

Example

{
    "amount": "7758176404715800194",
    "asset_id": "0x57d05d11b570fd197b55746070ee051c731ee109b07255eab3c9cf8b6c579d",
    "expiration_timestamp": "2404381470",
    "nonce": "2195908194",
    "receiver_position_id": "6091063652223914538",
    "receiver_public_key": "0x259f432e6f4590b9a164106cf6a659eb4862b21fb97d43588561712e8e5216b",
    "sender_position_id": "9309829342914403545",
    "sender_public_key": "0x463ef5fbed3a0b89e1fd1d630544c4cb2a358e93f5305c5d04ea919810633c7",
    "signature": {
        "r": "0x9ae426da12f9084cabb23793249439b1580e2fa794130b99a35d051af4e3e6",
        "s": "0x1aab922485eb0df5ef6856d0fcbdadad0acea652b5a0ec24bcabb5385ddc0a3"
    },
    "type": "TRANSFER"
}
class services.perpetual.api.gateway.transactions.ConditionalTransfer

Conditional Transfer

Parameters
  • amount (int) – The amount to transfer.

  • nonce (int) – Unique nonce issued by the caller.

  • sender_public_key (int) – The sender’s public key.

  • sender_position_id (int) – The position ID to transfer from.

  • receiver_public_key (int) – The receiver’s public key.

  • receiver_position_id (int) – The position ID to transfer to.

  • asset_id (int) – The unique asset ID (as registered on the contract) to transfer. Currently only the collateral asset is supported.

  • expiration_timestamp (int) – The timestamp after which this request is no longer valid.

  • fact_registry_address (str) – The address of the fact registry smart contract. Should be checksummed according to Web3.isChecksumAddress.

  • fact (bytes) – The fact that should appear in the fact registry as a condition to the transfer. A 32 bytes blob.

  • signature (Signature) – The sender’s signature.

Example

{
    "amount": "7758176404715800194",
    "asset_id": "0x57d05d11b570fd197b55746070ee051c731ee109b07255eab3c9cf8b6c579d",
    "expiration_timestamp": "2404381470",
    "fact": "6461646162616461626164616461626164616261646164616261646162616461",
    "fact_registry_address": "0x599f9eC17474c2E25C9859ee34A6A02fE9738083",
    "nonce": "2195908194",
    "receiver_position_id": "6091063652223914538",
    "receiver_public_key": "0x259f432e6f4590b9a164106cf6a659eb4862b21fb97d43588561712e8e5216b",
    "sender_position_id": "9309829342914403545",
    "sender_public_key": "0x243343249edf36010f231a63f3e102c5510f6dfcb270990e15a6317c747e65",
    "signature": {
        "r": "0x8a46893fa614eba8f681843c484abe055e03462235810d3514c2266a033a89",
        "s": "0x6350cf237ca1df18700ccb72ebd74759c7249c32c92e578d684455a631e9a3e"
    },
    "type": "CONDITIONAL_TRANSFER"
}
class services.perpetual.api.gateway.transactions.Liquidate

Liquidate

Parameters
  • liquidator_order (Order) – Represents the liquidator order.

  • liquidated_position_id (int) – The liquidated position ID.

  • actual_collateral (int) – The collateral amount sold in the liquidation.

  • actual_synthetic (int) – The synthetic amount sold in the liquidation.

  • actual_liquidator_fee (int) – The fee the liquidator paid out of the maximal amount they were willing to pay.

Example

{
    "actual_collateral": "7758176404715800194",
    "actual_liquidator_fee": "8791662011684601223",
    "actual_synthetic": "15308084094301570617",
    "liquidated_position_id": "15419682365516802845",
    "liquidator_order": {
        "amount_collateral": "8187132600743567510",
        "amount_fee": "11081939229867047606",
        "amount_synthetic": "16558026091473266411",
        "asset_id_collateral": "0x57d05d11b570fd197b55746070ee051c731ee109b07255eab3c9cf8b6c579d",
        "asset_id_synthetic": "0x2",
        "expiration_timestamp": "1430804514",
        "is_buying_synthetic": false,
        "nonce": "3900315155",
        "order_type": "LIMIT_ORDER_WITH_FEES",
        "position_id": "11534118754833929857",
        "public_key": "0x5db665983e23607de57d6dc068797336bfdcb954238044688bec922ca296d3e",
        "signature": {
            "r": "0x4ac8a77f5863238a8bfb8a2e7f2dcc70cb8cad7b45692497b4b2c3ff06f6c94",
            "s": "0x6fd86c349a6c6266d34c11da0ff8c0cf211cafbadc39ba4a4c38124344f3bb1"
        }
    },
    "type": "LIQUIDATE"
}
class services.perpetual.api.gateway.transactions.Deleverage

Deleverage

Parameters
  • deleveraged_position_id (int) – The deleveraged position ID.

  • deleverager_position_id (int) – The position ID to which the deleveraged position is attached.

  • synthetic_asset_id (int) – The unique asset ID (as registered on the contract) being deleveraged.

  • amount_synthetic (int) – The deleveraged’s synthetic amount.

  • amount_collateral (int) – The deleveraged’s collateral amount.

  • deleverager_is_buying_synthetic (bool) – A flag which indicates if the deleverager is buying synthetic.

Example

{
    "amount_collateral": "5721212930748269353",
    "amount_synthetic": "9309829342914403545",
    "deleveraged_position_id": "7758176404715800194",
    "deleverager_is_buying_synthetic": false,
    "deleverager_position_id": "15308084094301570617",
    "synthetic_asset_id": "0x1",
    "type": "DELEVERAGE"
}
class services.perpetual.api.gateway.transactions.FundingTick

Funding Tick

Parameters

global_funding_indices (FundingIndicesState) – Global funding indices information.

Example

{
    "global_funding_indices": {
        "indices": {
            "0x0": "-431710025170174585",
            "0x1": "6084712057446794809"
        },
        "timestamp": "3900315155"
    },
    "type": "FUNDING_TICK"
}
class services.perpetual.api.gateway.transactions.OraclePricesTick

Oracle Prices Tick

Parameters
  • oracle_prices (Mapping[int, AssetOraclePrice]) – Map between the asset ID to its median price and a collection of signed prices that generate this median.

  • timestamp (int) – Transaction generation timestamp.

Example

{
    "oracle_prices": {
        "0x0": {
            "price": "4345629098988793194",
            "signed_prices": {
                "0x2ae10445c08f66270cd8d3a71cdac5630a541b1f7d13e47ec1d0373ce3e8fd3": {
                    "external_asset_id": "0x425443555344000000000000000000004d616b6572",
                    "price": "10117956201985462554675959028152",
                    "timestamped_signature": {
                        "signature": {
                            "r": "0x6f301f84b4622bcd472a0f375469ce1118d0ce45cb8f9f089ce403981ce5154",
                            "s": "0xd17a6912b8dd4110ff9f643422448f3a9e725a07be3108aeeccf4a9e9dbdd0"
                        },
                        "timestamp": "3618339112"
                    }
                }
            }
        },
        "0x1": {
            "price": "14829673561266596382",
            "signed_prices": {
                "0x35007be34c2c3d47d2216cb3e13f61d65f4c3c76bb4c57bf1afbe7388bc3238": {
                    "external_asset_id": "0x455448555344000000000000000000004d616b6572",
                    "price": "216314955048675504460053108771",
                    "timestamped_signature": {
                        "signature": {
                            "r": "0x7272c78aab3a1d59cde4cec98630ea164ba79a7efd07dd987f0c4eb3b32d6e3",
                            "s": "0x6b86d1c1d08bb9b3bb9dde346bf76a1bf5b4c8a13cf875ba194080756312932"
                        },
                        "timestamp": "4265854110"
                    }
                },
                "0x4722c15415ba4ab0a1b3a516be64b94846e9257d25e619c6014f8af08acf90c": {
                    "external_asset_id": "0x455448555344000000000000000000004d616b6572",
                    "price": "345280244044647467828513979784",
                    "timestamped_signature": {
                        "signature": {
                            "r": "0x7912daf400f5d87299b2f9f7593f99015835b62cd15efe74f2a31a590c59773",
                            "s": "0x57eed714363fc4cae375a0adb938651d5e450fc6efaf61ce73ec64f578f0566"
                        },
                        "timestamp": "2685496293"
                    }
                }
            }
        }
    },
    "timestamp": "3485918757",
    "type": "ORACLE_PRICES_TICK"
}
class services.perpetual.api.gateway.transactions.MultiTransaction

MultiTransaction

Parameters

txs (List[Transaction]) – The list of trasactions.

Example

{
    "txs": [
        {
            "amount": "2569146471088859254",
            "position_id": "7758176404715800194",
            "public_key": "0x37ebdcde87a1613e443df789558867f5ba91faf7a024204f7c1bd874da5e70a",
            "type": "DEPOSIT"
        },
        {
            "amount": "13942126818862981423",
            "asset_id": "0x57d05d11b570fd197b55746070ee051c731ee109b07255eab3c9cf8b6c579d",
            "expiration_timestamp": "2628077981",
            "nonce": "3874773259",
            "receiver_position_id": "11534118754833929857",
            "receiver_public_key": "0x66194cbd71037d1b83e90ec17e0aa3c03983ca8ea7e9d498c778ea6eb2083e7",
            "sender_position_id": "10326739782786242647",
            "sender_public_key": "0x6306fae7e23046b2fc9763011b703ae8dae5099180c96125bddd421d30b048a",
            "signature": {
                "r": "0x399bbab600b27b983c7807c32caadf38bb897f412055d9989c63661416d56e4",
                "s": "0x73bae1a10349372ca04487d2271f3e3c0733c327b4114238de8cf0c5ded3b1b"
            },
            "type": "TRANSFER"
        }
    ],
    "type": "MULTI_TRANSACTION"
}