123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- const addr1 = "foo";
- const addr2 = "bar";
- const fee = "fee";
- const percentage = 0.01;
- async function deposit(account, amount, asset) {
- const response = (await fetch("http://127.0.0.1:8080/deposit", {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- },
- body: JSON.stringify({
- memo: "deposit",
- account,
- amount: amount.toString(),
- status: 'settled',
- asset,
- })
- }));
- return response.json();
- }
- async function trade(amount, asset, from, to) {
- const response = (await fetch("http://127.0.0.1:8080/tx", {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- },
- body: JSON.stringify({
- memo: "trade",
- debit: [
- {
- account: from,
- amount: amount.toString(),
- asset,
- }
- ],
- credit: [
- {
- account: to,
- amount: (amount * (1 - percentage)).toString(),
- asset,
- },
- {
- account: fee,
- amount: (amount * percentage).toString(),
- asset,
- }
- ],
- status: 'settled',
- asset,
- })
- }));
- return response.json();
- }
- async function test() {
- console.log(await deposit(addr1, 100, "BTC"));
- console.log(await trade(10, "BTC", addr1, addr2))
- }
- test()
|