Velora Developer Docs
VeloraUser Documentation
  • API
    • Velora API
      • Velora Delta API
        • Overview
        • Contracts
        • Retrieve Delta price with fallback to Market
        • Retrieve details for creating cross-chain order
        • Build a Delta Order to Sign
        • Submit a Delta Order
        • Track Delta Order Auction Status
        • Example: Quote With Fallback
      • Velora Market API
        • Overview
        • API Versions
          • API v6.2
          • API v5
        • Retrieve a price: /prices
        • Build a transaction: /transactions
        • Get Price & Calldata: /swap
        • Example: Fetch Price & Build Transaction
    • Get Tokens List
    • Limit Orders
      • Introduction
      • Contracts
      • On chain Data Structure
      • Data structure in our centralized system
      • API References
        • Fungible tokens
          • Create a limit order
          • Create a p2p limit order
          • Get limit orders by maker
          • Get limit orders by taker
          • Get Pairs
          • Get Orderbook
          • Fill a limit order
          • Cancel a limit order
        • NFT
          • Create an order
          • Create a p2p order
          • Get NFT orders by maker
          • Get NFT orders by taker
          • Get Pairs
          • Get orderbook
          • Fill a limit order
          • Cancel a limit order
      • SDK
        • Typescript
        • Python
  • AugustusRFQ API Specification
  • Augustus Swapper
    • Augustus v6.2
    • Augustus v5
  • Subgraphs
  • Security
    • Augustus V6.2
    • Augustus V6.1
    • Augustus RFQ
    • Augustus V5
  • Help Center
Powered by GitBook
On this page
Export as PDF
  1. API
  2. Limit Orders
  3. API References
  4. Fungible tokens

Create a limit order

Last updated 1 year ago

POST /ft/orders/:chainId/

Examples

The data to be sent to the endpoint consists of limit order parameters and a signature of those parameters produced by order maker. Generating this data consists of these steps: 1. compose 2. with eth_signTypedData 3. combine order parameters with the signature.

The resulting data will be validated and accepted by the POST endpoint and will have the .

curl -X POST \
  'https://api.paraswap.io/ft/orders/137' \
  --header 'Content-Type: application/json' \
  --data-raw '{ 
    "maker": "0x05182E579FDfCf69E4390c3411D8FeA1fb6467cf",
    "taker": "0x0000000000000000000000000000000000000000",
    "nonceAndMeta": "7433034152904838547212883274543254857465784035140417181410394112",
    "expiry": 0,
    "makerAsset": "0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270",
    "takerAsset": "0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063",
    "makerAmount": "10000000000000000",
    "takerAmount": "7775870000000000",
    "signature": "0x43de8dbc8228594171d0ed3e623ca0ab5c24f46bf0575800624ae56723712f807ecaf7dc8edfcf0d4517f80f11bf016bde0a9a20e243eea2bb32e55eadbb6b0d1b"
}'
/* eslint-disable @typescript-eslint/no-unused-vars */
import axios from 'axios';
import { ethers } from 'ethers';

import {
  // swap methods
  constructPartialSDK,
  constructEthersContractCaller,
  constructAxiosFetcher,
  // limitOrders methods
  constructBuildLimitOrder,
  constructSignLimitOrder,
  constructPostLimitOrder,
  // extra types
  SignableOrderData,
  LimitOrderToSend,
} from '..';

const account = '0x1234...';

const fetcher = constructAxiosFetcher(axios);

// provider must have write access to account
// this would usually be wallet provider (Metamask)
const provider = ethers.getDefaultProvider(1);
const contractCaller = constructEthersContractCaller(
  {
    ethersProviderOrSigner: provider,
    EthersContract: ethers.Contract,
  },
  account
);

// type BuildLimitOrderFunctions
// & SignLimitOrderFunctions
// & PostLimitOrderFunctions

const paraSwapLimitOrderSDK = constructPartialSDK(
  {
    chainId: 1,
    fetcher,
    contractCaller,
  },
  constructBuildLimitOrder,
  constructSignLimitOrder,
  constructPostLimitOrder
);

const DAI = '0x6B175474E89094C44Da98b954EedeAC495271d0F';
const HEX = '0x2b591e99afe9f32eaa6214f7b7629768c40eeb39';

const orderInput = {
  nonce: 1,
  expiry: Math.floor(Date.now() / 1000) + 60 * 60 * 24 * 7, // week from now, in sec
  makerAsset: DAI,
  takerAsset: HEX,
  makerAmount: (1e18).toString(10),
  takerAmount: (8e18).toString(10),
  maker: account,
};

async function run() {
  const signableOrderData: SignableOrderData =
    await paraSwapLimitOrderSDK.buildLimitOrder(orderInput);

  const signature: string = await paraSwapLimitOrderSDK.signLimitOrder(
    signableOrderData
  );

  const orderToPostToApi: LimitOrderToSend = {
    ...signableOrderData.data,
    signature,
  };

  const newOrder = await paraSwapLimitOrderSDK.postLimitOrder(orderToPostToApi);
  console.log(newOrder);
}

run();
MAKER_ASSET = "0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270"
TAKER_ASSET = "0x8f3cf7ad23cd3cadbd9735aff958023239c6a063"

network = Network.Polygon

# initialize http rpc provider
provider = HTTPProvider("YOUR RPC PROVIDER")

# initialize web3
web3 = Web3(provider)

# create web3 account with pk1
account1 = web3.eth.account.from_key("your pk")

# hack to make PoA work (for example polygon)
web3.middleware_onion.inject(geth_poa_middleware, layer=0)

# create order helper object, TODO: maybe rename it to augustusRFQ helper
# orderHelper is an helper for the augustusRFQ contract
orderHelper = OrderHelper(
    network,
    web3,
)

# get ftApi object instance
# fungible api is a wrapper to our limit orders api
ftApi = create_fungible_api(network, api_url)

# create_managed_order is used to createa a limit order that our backend track fillability
# and also using for pricing inside paraswap protocol
order = create_managed_order(
    expiry=0,  # 0 means the order never expire
    maker=account1.address,  # account1 is the maker of the order
    maker_asset=MAKER_ASSET,  # account1 is selling maker_asset
    taker_asset=TAKER_ASSET,  # account1 is buying taker_asset
    maker_amount=1000000000000,  # amount of maker_asset that account1 is selling
    taker_amount=845718000000,  # amount of taker_asset that account1 is buying
)

# The created order needs to be sign with an account to be valid
orderWithSignature = orderHelper.sign_order(account1, order)

# send this signed order to our centralised api.
# It means that the order will be use in pricing
print("Order created")
print(res

Query parameters:

  • chainId:network id (Ethereum Mainnet = 1)

Body parameters

{ 
    "maker": "0x05182E579FDfCf69E4390c3411D8FeA1fb6467cf",
    "taker": "0x0000000000000000000000000000000000000000",
    "nonceAndMeta": "7433034152904838547212883274543254857465784035140417181410394112",
    "expiry": 0,
    "makerAsset": "0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270",
    "takerAsset": "0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063",
    "makerAmount": "10000000000000000",
    "takerAmount": "7775870000000000",
    "signature": "0x43de8dbc8228594171d0ed3e623ca0ab5c24f46bf0575800624ae56723712f807ecaf7dc8edfcf0d4517f80f11bf016bde0a9a20e243eea2bb32e55eadbb6b0d1b"
}

Important notice:

  • nonceAndMeta: needs to be encoded as described in:

Response

Understand the response by checking our dedicated page:

{
	"order": {
		"expiry": 0,
		"createdAt": 1661165141,
		"updatedAt": 1661165141,
		"transactionHash": null,
		"chainId": 137,
		"nonceAndMeta": "7433034152904838547212883274543254857465784035140417181410394112",
		"maker": "0x05182e579fdfcf69e4390c3411d8fea1fb6467cf",
		"taker": "0xdef171fe48cf0115b1d80b88dc8eab59176fee57",
		"takerFromMeta": "0x0000000000000000000000000000000000000000",
		"makerAsset": "0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270",
		"takerAsset": "0x8f3cf7ad23cd3cadbd9735aff958023239c6a063",
		"makerAmount": "10000000000000000",
		"fillableBalance": "10000000000000000",
		"swappableBalance": "10000000000000000",
		"makerBalance": "10000000000000000",
		"takerAmount": "7775870000000000",
		"signature": "0x43dd8dbc8228594171d0ed3e633ca0eb5c24f46bf0575100623ae56723712f807ecaf7dc8edfcf0d4517f80f11bf016bde0a9a20e243eea2bb32e55eadbb6b0d1b",
		"orderHash": "0xdef400fd95d028d8caaba2c4887d2694563e0bc7f73c17d747feac2e24ed411d",
		"permitMakerAsset": null,
		"type": "LIMIT",
		"state": "PENDING"
	}
}
order parameters
sign an object with these parameters
specified shape
Data structure in our centralized system
Data structure in our centralized system