挂单类交易

提交挂单

挂单是用户资产交换的意愿表达,用于用一种资产置换另一种资产。在挂单中,需要标明挂单的资产对,例如AAA/BBB,其中AAA为基准资产,BBB为目标资产,基准资产是用户挂单的操作资产,目标资产是用户挂单的被动资产。

用户在挂单的时候,需要表达挂单的类型,分别是买单或者卖单,挂单类型指的是对基准货币的操作,例如买单AAA/BBB, 表示买AAA;卖单AAA/BBB,表示卖AAA。

用户挂单之后,系统根据用户的挂单信息,自动撮合用户的挂单。如果不能立即成交则用户的单子,用户的挂单处于未成交状态。

Java Example

// construct source wallet
Wallet wallet1 = new Wallet("snqFcH......pQYzxEEbW");

// create offer operation
OrderOperation op = new OrderOperation(wallet1);
op.setType(Order.SELL);
op.setPair("SWT/CNY:janxMdr...GewMMeHa9f");
op.setAmount(1000.00);
op.setPrice(0.0005);
op.setValidate(true);

// submit offer
op.submit(new OfferListener() {
    @override
    public void onComplete(result) {
        // process result
    }
});

Python Example

# construct source wallet
wallet1 = Wallet("shVC2gdG......gijqk4EsuqDF");

# create offer operation
op = OrderOperation(wallet1);
op.setType(Order.SELL);
op.setPair("SWT/CNY:janxMdr...GewMMeHa9f");
op.setAmount(1000.00);
op.setPrice(0.0005);
op.setValidate(true);

# submit payment
op.submit(callback);

PHP Example

// construct source wallet
$wallet1 = new Wallet('snwjtucx9......MbVz8hFiK9');

// create offer operation
$op = new OrderOperation($wallet1);
$op->setType($op->SELL)
$op->setPair("SWT/CNY:janxMdr...GewMMeHa9f");
$op->setAmount(1000.00);
$op->setPrice(0.0005);
// sync mode
$op->setValidate(true);

// submit payment
$res = $op->submit();

Node.JS Example

// construct source wallet
var JingtumSDK = require('jingtum-sdk');
var Wallet = JingtumSDK.Wallet;

var wallet1 = new Wallet('shNK......y5W5kK');

// create offer operation
var op = new JingtumSDK.OrderOperation(wallet1);
op.setType(op.SELL);
op.setPair("SWT/CNY:janxMdr...GewMMeHa9f");
op.setAmount(1000.00);
op.setPrice(0.0005);
// sync mode
op.setValidate(true);

// submit payment
op.submit(function (err, res) {
    if(err) { console.log(err); return; }
    console.log(res);
});

取消挂单

当井通账号提交挂单后,在挂单未完全成交前,账号可以取消未完成的挂单。取消的依据是未完成的单子的序号, 在提交挂单时由系统返回的一个大于零的整数值。每个账号做的每笔交易都有个序号,只有挂单交易的序号用于操作。

Java Example

// construct source wallet
Wallet wallet1 = new Wallet("snqFcH......pQYzxEEbW");

// create offer cancel operation
CancelOrderOperation op = new CancelOrderOperation(wallet1);
op.setSequence(54);
op.setValidate(true);

// submit offer cancel
op.submit(new OfferCancelListener() {
    @override
    public void onComplete(result) {
        // process result
    }
});

Python Example

# construct source wallet
wallet1 = Wallet("shVC2gdG......gijqk4EsuqDF");

# create offer cancel operation
op = CancelOrderOperation(wallet1);
op.setSequence(54);
op.setValidate(true);

# submit offer cancel
op.submit(callback);

PHP Example

// construct source wallet
$wallet1 = new Wallet('snwjtucx9......MbVz8hFiK9');

// create offer cancel operation
$op = new CancelOrderOperation($wallet);
$op->setSequence(54);
$op->setValidate(true);

// submit offer cancel
$ret = $op->submit();

Node.JS Example

// construct source wallet
var JingtumSDK = require('jingtum-sdk');
var Wallet = JingtumSDK.Wallet;

var wallet1 = new Wallet('shNK......y5W5kK');

// create offer cancel operation
var op = new JingtumSDK.CancelOrderOperation(wallet1);
op.setSequence(54);
op.setValidate(true);

// submit offer cancel
op.submit(function (err, res) {
    if(err) { console.log(err); return; }
    console.log(res);
});

查询挂单信息

当井通账号对所属资产挂单成功后,可以通过挂单返回的Hash值查询单个挂单信息。 井通账号如果有多个挂单挂出,在挂单未成交时,也可以获得这些挂单的信息。 如果挂单成交,则通过查询交易可以得知挂单成交的信息。

此外,井通区块链系统中也可以查询某一对资产的挂单信息,比如使用用户通A置换用户通B。

Java Example

// construct source wallet
Wallet wallet1 = new Wallet("snqFcH......pQYzxEEbW");

// get one offer info
Order order = wallet1.getOrder("52AED741BF.....FB2F14");

// get all un-funded offers
OrderCollection orders = wallet1.getOrderList();

Python Example

# construct source wallet
Wallet wallet1 = new Wallet("snqFcH......pQYzxEEbW");

# get one offer info
order = wallet1.getOrder('52AED741BF.....FB2F14');

# get all un-funded offers
orders = wallet1.getOrderList();

PHP Example

// construct source wallet
$wallet1 = new Wallet('jfCiWtSt4ju......NYxakm5yP9S','snwjtucx9......MbVz8hFiK9');

// get one offer info
$hash_id = '52AED741BF.....FB2F14';
$ret = $wallet1->getOrder($hash_id);

// get all un-funded offers
$ret = $wallet1->getOrderList();

Node.JS Example

// construct source wallet
var Wallet = require('jingtum-sdk').Wallet;
Wallet wallet1 = new Wallet("snqFcH......pQYzxEEbW");

// get one offer info
wallet1.getOrder('3E0E7444449A0656......69FBF67115FE20', function (err, data) {
    if(err) console.log(err);
    else console.log(data);
});

// get all un-funded offers
wallet1.getOrderList(function (err, data) {
    if(err) console.log(err);
    else console.log(JSON.stringify(data));
});

查询市场深度

市场深度是市场里面对于某个货币对的所有挂单,通过市场深度功能,可以获得卖单和买单列表的结果,结果中的信息字段如下:

pair,货币对 bids,买单列表,列表里的每一项如下

order_maker,挂单账号 sequence,挂单序号 funed,单子实际可成交的金额 total,单子声明可成交的金额 price,单子的价格

asks,卖单列表,列表里的每一项和bids里面一样

Java Example

// 1. prepare a order book pair String pair = new String(“CNY:jBciDE8Q3uJjf111VeiUNM775AMKHEbBLS/USD:jBciDE8Q3uJjf111VeiUNM775AMKHEbBLS”);

// 2. get orderbook by fingate FinGate.getOrderBook(pair, new OrderBookListener() {

@override public void onComplete(result) {

// process result

}

});

Python Example

// 1. prepare a order book pair
pair = "CNY:jBciDE8Q3uJjf111VeiUNM775AMKHEbBLS/USD:jBciDE8Q3uJjf111VeiUNM775AMKHEbBLS";

// 2. get orderbook by fingate
FinGate.getOrderBook(pair, callback);

PHP Example

// 1. prepare a order book pair
$pair = "CNY:jBciDE8Q3uJjf111VeiUNM775AMKHEbBLS/USD:jBciDE8Q3uJjf111VeiUNM775AMKHEbBLS";

// 2. get orderbook by fingate
$FinGate->getOrderBook($pair, 'call_back_func');

Node.JS Example

// 1. prepare a order book pair var pair = “CNY:jBciDE8Q3uJjf111VeiUNM775AMKHEbBLS/USD:jBciDE8Q3uJjf111VeiUNM775AMKHEbBLS”;

// 2. get orderbook by fingate FinGate.getOrderBook(pair, function(err, data) {

// process result

});