挂单类交易¶
获得某个账号的挂单¶
Node.JS Example¶
var Remote = require('jingtu-lib').Remote;
var remote = new Remote({server: 'ws://ts5.jingtum.com:5020', local_sign:true});
remote.connect(function (err, result) {
if(err) return console.log('err: ', err);
var options = {account: 'jB7r...Y2xLZ', limit: 10};
var req = remote.requestAccountOffers(options);
req.submit(function(err, result) {
if(err) {return console.log('err:',err);}
console.log('get account orders:', result);
});
});
C# Example¶
var remote = new Remote(@"ws://ts5.jingtum.com:5020", true);
remote.Connec(result =>
{
if (result.Exception != null)
{
Console.Write(result.Exception.Message);
}
else
{
var req = remote.RequestAccountOffers(new AccountOffersOptions
{
Account = "j9FGhAW9dSzL3RjbXkyW6Z6bHGxFk8cmB1"
});
req.Submit(reqResult =>
{
Console.Write(reqResult.Message);
// get result from reqResult.Result
});
}
});
挂单¶
Node.JS Example¶
参数:
参数 | 类型 | 说明 | |||
---|---|---|---|---|---|
type | String | 挂单类型,固定的两个值:buy、sell | |||
account | String | 挂单方账号 | |||
platform | String | APP平台标识账号,可选 | |||
taker_gets | Object | 对方得到的,即挂单方支付的 | |||
value | String | 数量 | |||
currency | String | 货币种类 | |||
issuer | String | 货币发行方 | |||
taker_pays | Object | 对方支付的,即挂单方获得的 | |||
value | String | 数量 | |||
currency | String | 货币种类 | |||
issuer | String | 货币发行方 |
var Remote = require('jingtum-lib').Remote;
var remote = new Remote({server: 'ws://ts5.jingtum.com:5020', local_sign:true});
remote.connect(function (err, result) {
if(err) return console.log('err: ', err);
var options = {
type: 'Sell',
account: 'jB7r...2xLZ',
taker_gets: {
value: '0.01',
currency: 'CNY',
issuer: 'jBciDE8Q3uJjf111VeiUNM775AMKHEbBLS'
},
taker_pays: {
value: '1',
currency: 'SWT',
issuer: ''
}
};
var tx = remote.buildOfferCreateTx(options);
tx.setSecret('sn37...jXUWd');
tx.submit(function(err, result) {
if(err) {return console.log('err:',err);}
console.log('build order result:', result);
});
});
C# Example¶
var remote = new Remote(@"ws://ts5.jingtum.com:5020", true);
remote.Connect(result =>
{
if (result.Exception != null)
{
Console.Write(result.Exception.Message);
}
else
{
var tx = remote.BuildOfferCreateTx(new OfferCreateTxOptions
{
Account = "j9FGhAW9dSzL3RjbXkyW6Z6bHGxFk8cmB1",
Type = OfferType.Sell,
TakerGets = new Amount
{
Value = "0.01",
Currency = "SWT",
Issuer = ""
},
TakerPays = new Amount
{
Value = "1",
Currency = "CNY",
Issuer = "jBciDE8Q3uJjf111VeiUNM775AMKHEbBLS"
}
});
tx.SetSecret("ssG......dNi");
tx.Submit(txResult => {
Console.Write(txResult.Message);
//get result from txResult.Result
});
}
});
获得市场挂单¶
Node.JS Example¶
var Remote = require('jingtum-lib').Remote;
var remote = new Remote({server: 'ws://ts5.jingtum.com:5020', local_sign:true});
remote.connect(function (err, result) {
if(err) return console.log('err: ', err);
var options = {
gets: { currency: 'SWT', issuer: '' },
pays: { currency: 'CNY', issuer: 'jBciDE8Q3uJjf111VeiUNM775AMKHEbBLS'}};
var req = remote.requestOrderBook(options);
req.submit(function(err, result) {
if(err) {return console.log('err:', err);}
console.log('get market orders:', result);
});
});
C# Example¶
var remote = new Remote(@"wss://ts5.jingtum.com:5020", true);
remote.Connect(result =>
{
if (result.Exception != null)
{
Console.Write(result.Exception.Message);
}
else
{
var req = remote.RequestOrderBook(new OrderBookOptions
{
Gets = new Amount ("SWT", ""),
Pays = new Amount ("CNY", "jBciDE8Q3uJjf111VeiUNM775AMKHEbBLS")
});
req.Submit(reqResult =>
{
Console.Write(reqResult.Message);
});
}
});
取消挂单¶
Node.JS Example¶
var Remote = require('jingtum-lib').Remote;
var remote = new Remote({server: 'ws://ts5.jingtum.com:5020', local_sign:true});
remote.connect(function (err, result) {
if(err) return console.log('err: ', err);
var options = {account: 'jB7r...Y2xLZ', sequence: 688};
var tx = remote.buildOfferCancelTx(options);
tx.setSecret('sn37...FjXUWd');
tx.submit(function(err, result) {
if(err) {return console.log('err:',err);}
console.log('cancel order result:', result);
});
});
C# Example¶
var remote = new Remote(@"ws://ts5.jingtum.com:5020", true);
remote.Connect(result =>
{
if (result.Exception != null)
{
Console.Write(result.Exception.Message);
}
else
{
var tx = remote.BuildOfferCancelTx(new OfferCancelTxOptions
{
Account = "j9FGhAW9dSzL3RjbXkyW6Z6bHGxFk8cmB1",
Sequence = 8
});
tx.SetSecret("ssG......dNi");
rx.Submit(txResult => {
Console.Write(rxResult.Message);
//get result from txRresult.Result
});
}
});
获得挂单佣金设置信息¶
首先通过本方法返回一个Request对象,然后通过submit方法获得市场挂单列表信息。
方法:remote.requestBrokerage({});
参数:
参数 | 类型 | 说明 |
---|---|---|
account | String | 设置挂单佣金的账号 |
返回:Request对象
例子:
var jlib = require('jingtum-lib');
var Remote = jlib.Remote;
var remote = new Remote({server: 'ws://xxx:port', local_sign:true});
remote.connect(function(err, result) {
if (err) {
return console.log('err:',err);
}
var options = {
account: 'jHb9CJAWyB4jr91VRWn96DkukG4bwdtyTh'};
var req = remote.requestBrokerage(options);
req.submit(function(err, result) {
if(err) {console.log('err:',err);}
else if(result){
console.log('res:', result);
}
});
});
返回结果:
{
account: 'jHb9CJAWyB4jr91VRWn96DkukG4bwdtyTh',
brokerages:
[ { FeeCurrency: 'AAA',
FeeCurrencyIssuer: 'jBciDE8Q3uJjf111VeiUNM775AMKHEbBLS',
OfferFeeRateDen: '1000',
OfferFeeRateNum: '5',
Platform: 'jHb9CJAWyB4jr91VRWn96DkukG4bwdtyTh',
fee_account: 'jzTx4CRUZJT1ZsBhGHi7Wqikada63xRVv' } ],
ledger_hash: 'EEEECA6766A17D4113CDF2FC6DA05C2B735EDFB437EF2546DEDBA127AF63B2BE',
ledger_index: 1633,
validated: true
}
返回结果说明:
参数 | 类型 | 说明 | |||
---|---|---|---|---|---|
account | String | 设置佣金的账号或银关 | |||
brokerages | Array | 设置的所有佣金详情 | |||
FeeCurrency | String | 收费币种 | |||
FeeCurrencyIssuer | String | 货币发行方 | |||
OfferFeeRateDen | String | 分母 | |||
OfferFeeRateNum | String | 分子 | |||
Platform | String | 平台标识账号 | |||
fee_account | String | 收费账号 | |||
ledger_hash | String | 当前hash | |||
ledger_index | Integer | 当前账本号 | |||
validated | Boolean | 交易是否通过验证 |
设置挂单佣金¶
首先通过buildBrokerageTx方法返回一个Transaction对象,然后通过setSecret传入密钥,最后通过submit方法设置平台手续费。
创建挂单佣金对象¶
方法:remote.buildBrokerageTx({});
参数:
参数 | 类型 | 说明 | |||
---|---|---|---|---|---|
account | String | APP平台账号 | |||
feeAccount | String | 收费账号,必须为激活账号 | |||
mol | Integer | 分子(0和正整数) | |||
den | Intege | 分母(正整数) | |||
amount | Object | 币种对象 | |||
value | String | 数量,这里只是占位,没有实际意义。 | |||
currency | String | 货币种类 | |||
issuer | String | 货币发行方 |
返回:Transaction对象
设置挂单佣金¶
方法:tx.submit(callback); 参数:无
设置挂单佣金完整例子:
var jlib = require('jingtum-lib');
var Remote = jlib.Remote;
var remote = new Remote({server: 'ws://xxx:port', local_sign:true});
remote.connect(function (err, result) {
if (err) {
return console.log('err:', err);
}
var v = {
secret: 's...UTb',
address: 'j...yTh'
};
var tx = remote.buildBrokerageTx({account: v.address, mol: 1, den: 1000, feeAccount:'jzTx4CRUZJT1ZsBhGHi7Wqikada63xRVv',
amount: {
"value": "3",
"currency": "TES",
"issuer": "jBciDE8Q3uJjf111VeiUNM775AMKHEbBLS"
}});
tx.setSecret(v.secret);
tx.submit(function (err, result) {
if (err) {
console.log('err:', err);
}
else if (result) {
console.log('res:', result);
}
});
});
返回结果:
{
engine_result: 'tesSUCCESS',
engine_result_code: 0,
engine_result_message: 'The transaction was applied. Only final in a validated ledger.',
tx_blob: '1200CD220000000024000000012025000000013900000000000000013A00000000000003E861D38AA87BEE53800000000000000000000000005445535400000000007478E561645059399B334448F7544F2EF308ED3268400000000000271073210330E7FC9D56BB25D6893BA3F317AE5BCF33B3291BD63DB32654A313222F7FD02074473045022100FE513087425A863D1FB0004B29C6656E1B4C237F57F193FC5707317257926787022070AA7125CB5383F5B53000903BDAF9926CBE74F732DF7E09BE3EC581FEF5E7C08114B5F762798A53D543A014CAF8B297CFF8F2F937E8',
tx_json:
{ Account: 'jHb9CJAWyB4jr91VRWn96DkukG4bwdtyTh',
Amount:
{ currency: 'TEST',
issuer: 'jBciDE8Q3uJjf111VeiUNM775AMKHEbBLS',
value: '3' },
Fee: '10000',
FeeAccountID: 'jzTx4CRUZJT1ZsBhGHi7Wqikada63xRVv',
Flags: 0,
OfferFeeRateDen: '00000000000003E8',
OfferFeeRateNum: '0000000000000001',
Sequence: 1,
SigningPubKey: '0330E7FC9D56BB25D6893BA3F317AE5BCF33B3291BD63DB32654A313222F7FD020',
TransactionType: 'Brokerage',
TxnSignature: '3045022100FE513087425A863D1FB0004B29C6656E1B4C237F57F193FC5707317257926787022070AA7125CB5383F5B53000903BDAF9926CBE74F732DF7E09BE3EC581FEF5E7C0',
hash: '3260743D0233EA5B8E2963F00D35B4198BA9EC6BE7638E84C9375A3CBE2172A3' }
}
返回结果说明:
参数 | 类型 | 说明 | |||
---|---|---|---|---|---|
engine_result | String | 请求结果 | |||
engine_result_code | Array | 请求结果编码 | |||
engine_result_message | String | 请求结果message信息 | |||
tx_blob | String | 16进制签名后的交易 | |||
tx_json | Object | 交易内容 | |||
Account | String | APP平台账号地址 | |||
Amount | Object | 收交易手续费的币种信息 | |||
Fee | String | 网络费 | |||
feeAccountID | String | 收费账号 | |||
Flags | Integer | 交易标记 | |||
OfferFeeRateDen | String | 分母 | |||
OfferFeeRateNum | String | 分子 | |||
Sequence | Integer | 单子序列 | |||
SigningPubKey | String | 签名公钥 | |||
TransactionType | String | 交易类型:Brokerage设置交易手续费类 | |||
TxnSignature | String | 交易签名 | |||
hash | String | 交易hash |