Skip to content

Commit

Permalink
Add testnet examples to broadcast feed and call_order updates
Browse files Browse the repository at this point in the history
  • Loading branch information
svk31 committed Jul 10, 2018
1 parent f27f38e commit 3f882cd
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 0 deletions.
40 changes: 40 additions & 0 deletions examples/callOrderUpdate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import {Apis} from "bitsharesjs-ws";
import {TransactionBuilder, PrivateKey} from "../lib";

const wifKey = "5KBuq5WmHvgePmB7w3onYsqLM8ESomM2Ae7SigYuuwg8MDHW7NN";
const pKey = PrivateKey.fromWif(wifKey);

Apis.instance("wss://node.testnet.bitshares.eu", true).init_promise.then(
res => {
console.log("connected to:", res[0].network_name, "network");

let tr = new TransactionBuilder();
tr.add_type_operation("call_order_update", {
funding_account: "1.2.680",
delta_collateral: {
amount: 1000000,
asset_id: "1.3.0"
},
delta_debt: {
amount: 0,
asset_id: "1.3.1003"
},
extensions: {
target_collateral_ratio: 250
}
});

tr.set_required_fees().then(() => {
tr.add_signer(pKey, pKey.toPublicKey().toPublicKeyString());
console.log("serialized transaction:", tr.serialize().operations);
tr
.broadcast()
.then(() => {
console.log("Call order update success!");
})
.catch(err => {
console.error(err);
});
});
}
);
53 changes: 53 additions & 0 deletions examples/publishFeed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import {Apis} from "bitsharesjs-ws";
import {TransactionBuilder, PrivateKey} from "../lib";

const wifKey = "5KBuq5WmHvgePmB7w3onYsqLM8ESomM2Ae7SigYuuwg8MDHW7NN";
const pKey = PrivateKey.fromWif(wifKey);

Apis.instance("wss://node.testnet.bitshares.eu", true).init_promise.then(
res => {
console.log("connected to:", res[0].network_name, "network");
let tr = new TransactionBuilder();
tr.add_type_operation("asset_publish_feed", {
publisher: "1.2.680",
asset_id: "1.3.1003",
feed: {
settlement_price: {
quote: {
amount: 10,
asset_id: "1.3.0"
},
base: {
amount: 5,
asset_id: "1.3.1003"
}
},
maintenance_collateral_ratio: 1750,
maximum_short_squeeze_ratio: 1200,
core_exchange_rate: {
quote: {
amount: 10,
asset_id: "1.3.0"
},
base: {
amount: 5,
asset_id: "1.3.1003"
}
}
}
});

tr.set_required_fees().then(() => {
tr.add_signer(pKey, pKey.toPublicKey().toPublicKeyString());
console.log("serialized transaction:", tr.serialize().operations);
tr
.broadcast()
.then(() => {
console.log("Publish feed success!");
})
.catch(err => {
console.error(err);
});
});
}
);
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
"prepublish": "npm run build && npm run test",
"doc": "esdoc -c esdoc.json",
"example:transfer": "babel-node examples/transfer",
"example:feed": "babel-node examples/publishFeed",
"example:co-update": "babel-node examples/callOrderUpdate",
"example:chainStore": "babel-node examples/chainStore",
"example:privKey": "babel-node examples/privKey"
},
Expand Down

0 comments on commit 3f882cd

Please sign in to comment.