Skip to content
This repository has been archived by the owner on Dec 29, 2023. It is now read-only.

Commit

Permalink
feat: update FE Script
Browse files Browse the repository at this point in the history
  • Loading branch information
politeWall committed Nov 23, 2023
1 parent 802fd91 commit 9183f98
Show file tree
Hide file tree
Showing 2 changed files with 150 additions and 6 deletions.
33 changes: 27 additions & 6 deletions front_end_script/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ cancelMarginOrder("your_order_id_here");
cancelMarginOrder("1");
```

### 8. getMarginOrder(address,id)
### 8. getMarginOrder(id)

This function retrieves information about a specific margin order by querying a CosmWasm contract on the blockchain.

Expand All @@ -232,10 +232,31 @@ getMarginOrder("your_order_id_here");
#### Exemple

```js
getMarginOrder("255");
getMarginOrder("2");
```

### 9. getMarginOrders(pagination)
### 9. getMarginPosition(address,id)

This function retrieves information about a specific margin order by querying a CosmWasm contract on the blockchain.

#### Parameters

- `address` (String): The address associated with the margin order.
- `order_id` (String): The unique identifier for the order you want to retrieve.

#### Usage

```javascript
getMarginPosition("your_address", "your_order_id_here");
```

#### Exemple

```js
getMarginPosition("elys1x5fehwug2vtkyn4vpunwkfn9zxkpxl8jg0lwuu", "255");
```

### 10. getMarginPositions(pagination)

This function retrieves multiple margin orders by querying a CosmWasm contract on the blockchain.

Expand All @@ -246,16 +267,16 @@ This function retrieves multiple margin orders by querying a CosmWasm contract o
#### Usage

```javascript
getMarginOrders("pagination");
getMarginPositions("pagination");
```

#### Exemple

```js
getMarginOrders({ count_total: true, limit: 10, reverse: false, key: null });
getMarginPositions({ count_total: true, limit: 10, reverse: false, key: null });
```

### 10. SwapEstimationByDenom(amount, denom_in, denom_out)
### 11. SwapEstimationByDenom(amount, denom_in, denom_out)

This function retrieves an estimation of the value obtained by swapping one asset for another.

Expand Down
123 changes: 123 additions & 0 deletions front_end_script/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,126 @@ async function SwapEstimationByDenom(amount, denom_in, denom_out) {
);
console.log(`Result: `, result);
}

async function createMarginOrder(
position_type,
collateral,
leverage_value,
borrow_asset,
take_profit_price,
order_type,
trigger_price
) {
const gasPrice = GasPrice.fromString(GASPRICE);
const sender_wallet = await DirectSecp256k1HdWallet.fromMnemonic(
sender.mnemonic,
{ prefix: "elys" }
);
const sender_client = await SigningCosmWasmClient.connectWithSigner(
rpcEndpoint,
sender_wallet
);
const executeFee = calculateFee(300_000, gasPrice);
const msg = {
create_margin_order: {
position_type: position_type,
collateral: collateral,
leverage_value: leverage_value,
borrow_asset: borrow_asset,
take_profit_price: take_profit_price,
order_type: order_type,
trigger_price: trigger_price,
},
};

const create_margin_order_res = await sender_client.execute(
sender.address,
trade_shield_contract_addr,
msg,
executeFee,
"",
coins(amount_send, denom_send)
);
console.log("create_margin_order_res:", create_margin_order_res);
}

async function cancelMarginOrder(order_id) {
const gasPrice = GasPrice.fromString(GASPRICE);
const sender_wallet = await DirectSecp256k1HdWallet.fromMnemonic(
sender.mnemonic,
{ prefix: "elys" }
);
const sender_client = await SigningCosmWasmClient.connectWithSigner(
rpcEndpoint,
sender_wallet
);
const executeFee = calculateFee(300_000, gasPrice);
const msg = {
cancel_margin_order: {
order_id: order_id,
},
};

const create_margin_order_res = await sender_client.execute(
sender.address,
trade_shield_contract_addr,
msg,
executeFee,
""
);
console.log("create_margin_order_res:", create_margin_order_res);
}

async function getMarginOrder(order_id) {
const sender_wallet = await DirectSecp256k1HdWallet.fromMnemonic(
sender.mnemonic,
{ prefix: "elys" }
);
const sender_client = await SigningCosmWasmClient.connectWithSigner(
rpcEndpoint,
sender_wallet
);
const result = await sender_client.queryContractSmart(
trade_shield_contract_addr,
{
get_margin_order: { order_id: order_id },
}
);
console.log(`Result: `, result);
}

async function getMarginPosition(id, address) {
const sender_wallet = await DirectSecp256k1HdWallet.fromMnemonic(
sender.mnemonic,
{ prefix: "elys" }
);
const sender_client = await SigningCosmWasmClient.connectWithSigner(
rpcEndpoint,
sender_wallet
);
const result = await sender_client.queryContractSmart(
trade_shield_contract_addr,
{
get_margin_position: { id: id, address: address },
}
);
console.log(`Result: `, result);
}

async function getMarginPositions(pagination) {
const sender_wallet = await DirectSecp256k1HdWallet.fromMnemonic(
sender.mnemonic,
{ prefix: "elys" }
);
const sender_client = await SigningCosmWasmClient.connectWithSigner(
rpcEndpoint,
sender_wallet
);
const result = await sender_client.queryContractSmart(
trade_shield_contract_addr,
{
get_margin_positions: { pagination: pagination },
}
);
console.log(`Result: `, result);
}

0 comments on commit 9183f98

Please sign in to comment.