SubmitOrder
SubmitOrder creates a new ask or bid order and submits for the given account and submits it to the auction server for matching.
Source: poolrpc/trader.proto
gRPC
rpc SubmitOrder (SubmitOrderRequest) returns (SubmitOrderResponse);
REST
HTTP Method | Path |
---|---|
POST | /v1/pool/orders |
Code Samples
- gRPC
- REST
- Shell
- Javascript
- Python
const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const GRPC_HOST = 'localhost:12010'
const MACAROON_PATH = 'POOL_DIR/regtest/pool.macaroon'
const TLS_PATH = 'POOL_DIR/tls.cert'
const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true,
};
const packageDefinition = protoLoader.loadSync('poolrpc/trader.proto', loaderOptions);
const poolrpc = grpc.loadPackageDefinition(packageDefinition).poolrpc;
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const tlsCert = fs.readFileSync(TLS_PATH);
const sslCreds = grpc.credentials.createSsl(tlsCert);
const macaroon = fs.readFileSync(MACAROON_PATH).toString('hex');
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let client = new poolrpc.Trader(GRPC_HOST, creds);
let request = {
ask: <Ask>,
bid: <Bid>,
initiator: <string>,
};
client.submitOrder(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// "invalid_order": <InvalidOrder>,
// "accepted_order_nonce": <bytes>,
// "updated_sidecar_ticket": <string>,
// }
import codecs, grpc, os
# Generate the following 2 modules by compiling the poolrpc/trader.proto with the grpcio-tools.
# See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
import trader_pb2 as poolrpc, trader_pb2_grpc as traderstub
GRPC_HOST = 'localhost:12010'
MACAROON_PATH = 'POOL_DIR/regtest/pool.macaroon'
TLS_PATH = 'POOL_DIR/tls.cert'
# create macaroon credentials
macaroon = codecs.encode(open(MACAROON_PATH, 'rb').read(), 'hex')
def metadata_callback(context, callback):
callback([('macaroon', macaroon)], None)
auth_creds = grpc.metadata_call_credentials(metadata_callback)
# create SSL credentials
os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
cert = open(TLS_PATH, 'rb').read()
ssl_creds = grpc.ssl_channel_credentials(cert)
# combine macaroon and SSL credentials
combined_creds = grpc.composite_channel_credentials(ssl_creds, auth_creds)
# make the request
channel = grpc.secure_channel(GRPC_HOST, combined_creds)
stub = traderstub.TraderStub(channel)
request = poolrpc.SubmitOrderRequest(
ask=<Ask>,
bid=<Bid>,
initiator=<string>,
)
response = stub.SubmitOrder(request)
print(response)
# {
# "invalid_order": <InvalidOrder>,
# "accepted_order_nonce": <bytes>,
# "updated_sidecar_ticket": <string>,
# }
- Javascript
- Python
const fs = require('fs');
const request = require('request');
const REST_HOST = 'localhost:8281'
const MACAROON_PATH = 'POOL_DIR/regtest/pool.macaroon'
let requestBody = {
ask: <object>, // <Ask>
bid: <object>, // <Bid>
initiator: <string>, // <string>
};
let options = {
url: `https://${REST_HOST}/v1/pool/orders`,
// Work-around for self-signed certificates.
rejectUnauthorized: false,
json: true,
headers: {
'Grpc-Metadata-macaroon': fs.readFileSync(MACAROON_PATH).toString('hex'),
},
form: JSON.stringify(requestBody),
}
request.post(options, function(error, response, body) {
console.log(body);
});
// Console output:
// {
// "invalid_order": <object>, // <InvalidOrder>
// "accepted_order_nonce": <string>, // <bytes>
// "updated_sidecar_ticket": <string>, // <string>
// }
import base64, codecs, json, requests
REST_HOST = 'localhost:8281'
MACAROON_PATH = 'POOL_DIR/regtest/pool.macaroon'
TLS_PATH = 'POOL_DIR/tls.cert'
url = f'https://{REST_HOST}/v1/pool/orders'
macaroon = codecs.encode(open(MACAROON_PATH, 'rb').read(), 'hex')
headers = {'Grpc-Metadata-macaroon': macaroon}
data = {
'ask': <Ask>,
'bid': <Bid>,
'initiator': <string>,
}
r = requests.post(url, headers=headers, data=json.dumps(data), verify=TLS_PATH)
print(r.json())
# {
# "invalid_order": <InvalidOrder>,
# "accepted_order_nonce": <bytes>,
# "updated_sidecar_ticket": <string>,
# }
$ pool orders submit --help
NAME:
pool orders submit -
Submit a new order in the given market. Currently, Pool supports two
types of orders: asks, and bids. In Pool, market participants buy/sell
liquidity in _units_. A unit is 100,000 satoshis.
In the *inbound* market, the bidder pays the asker a premium for a
channel with 50% to 100% of inbound liquidity. The premium amount is
calculated using the funding amount of the asker.
In the outbound market, the bidder pays the asker a premium for
a channel with outbound liquidity.
To participate in the outbound market the asker needs to create an order
with '--amt=100000' (one unit) and the '--min_chan_amt' equals to
the minimum channel size that is willing to accept.
The bidder needs to create an order with '--amt=100000' (one unit)
and '--self_chan_balance' equals to the funds that is willing to commit
in a channel. The premium amount is calculated using the funding amount
of the bidder ('--self_chan_balance').
USAGE:
pool orders submit command [command options] [arguments...]
COMMANDS:
ask offer channel liquidity
bid obtain channel liquidity
OPTIONS:
--help, -h show help
Messages
poolrpc.SubmitOrderRequest
Source: poolrpc/trader.proto
Field | gRPC Type | REST Type | REST Placement |
---|---|---|---|
ask | Ask | object | body |
bid | Bid | object | body |
initiator | string | string | body |
poolrpc.SubmitOrderResponse
Source: poolrpc/trader.proto
Field | gRPC Type | REST Type |
---|---|---|
invalid_order | InvalidOrder | object |
accepted_order_nonce | bytes | string |
updated_sidecar_ticket | string | string |
Nested Messages
poolrpc.Ask
Field | gRPC Type | REST Type |
---|---|---|
details | Order | object |
lease_duration_blocks | uint32 | integer |
version | uint32 | integer |
announcement_constraints | ChannelAnnouncementConstraints | string |
confirmation_constraints | ChannelConfirmationConstraints | string |
poolrpc.Bid
Field | gRPC Type | REST Type |
---|---|---|
details | Order | object |
lease_duration_blocks | uint32 | integer |
version | uint32 | integer |
min_node_tier | NodeTier | string |
self_chan_balance | uint64 | string |
sidecar_ticket | string | string |
unannounced_channel | bool | boolean |
zero_conf_channel | bool | boolean |
poolrpc.InvalidOrder
Field | gRPC Type | REST Type |
---|---|---|
order_nonce | bytes | string |
fail_reason | FailReason | string |
fail_string | string | string |
poolrpc.MatchEvent
Field | gRPC Type | REST Type |
---|---|---|
match_state | MatchState | string |
units_filled | uint32 | integer |
matched_order | bytes | string |
reject_reason | MatchRejectReason | string |
poolrpc.Order
Field | gRPC Type | REST Type |
---|---|---|
trader_key | bytes | string |
rate_fixed | uint32 | integer |
amt | uint64 | string |
max_batch_fee_rate_sat_per_kw | uint64 | string |
order_nonce | bytes | string |
state | OrderState | string |
units | uint32 | integer |
units_unfulfilled | uint32 | integer |
reserved_value_sat | uint64 | string |
creation_timestamp_ns | uint64 | string |
events | OrderEvent[] | array |
min_units_match | uint32 | integer |
channel_type | OrderChannelType | string |
allowed_node_ids | bytes[] | array |
not_allowed_node_ids | bytes[] | array |
auction_type | AuctionType | string |
is_public | bool | boolean |
poolrpc.OrderEvent
Field | gRPC Type | REST Type |
---|---|---|
timestamp_ns | int64 | string |
event_str | string | string |
state_change | UpdatedEvent | object |
matched | MatchEvent | object |
poolrpc.UpdatedEvent
Field | gRPC Type | REST Type |
---|---|---|
previous_state | OrderState | string |
new_state | OrderState | string |
units_filled | uint32 | integer |
Enums
poolrpc.AuctionType
Name | Number |
---|---|
AUCTION_TYPE_BTC_INBOUND_LIQUIDITY | 0 |
AUCTION_TYPE_BTC_OUTBOUND_LIQUIDITY | 1 |
poolrpc.ChannelAnnouncementConstraints
Name | Number |
---|---|
ANNOUNCEMENT_NO_PREFERENCE | 0 |
ONLY_ANNOUNCED | 1 |
ONLY_UNANNOUNCED | 2 |
poolrpc.ChannelConfirmationConstraints
Name | Number |
---|---|
CONFIRMATION_NO_PREFERENCE | 0 |
ONLY_CONFIRMED | 1 |
ONLY_ZEROCONF | 2 |
poolrpc.InvalidOrder.FailReason
Name | Number |
---|---|
INVALID_AMT | 0 |
poolrpc.MatchRejectReason
Name | Number |
---|---|
NONE | 0 |
SERVER_MISBEHAVIOR | 1 |
BATCH_VERSION_MISMATCH | 2 |
PARTIAL_REJECT_COLLATERAL | 3 |
PARTIAL_REJECT_DUPLICATE_PEER | 4 |
PARTIAL_REJECT_CHANNEL_FUNDING_FAILED | 5 |
poolrpc.MatchState
Name | Number |
---|---|
PREPARE | 0 |
ACCEPTED | 1 |
REJECTED | 2 |
SIGNED | 3 |
FINALIZED | 4 |
poolrpc.NodeTier
Name | Number |
---|---|
TIER_DEFAULT | 0 |
TIER_0 | 1 |
TIER_1 | 2 |
poolrpc.OrderChannelType
Name | Number |
---|---|
ORDER_CHANNEL_TYPE_UNKNOWN | 0 |
ORDER_CHANNEL_TYPE_PEER_DEPENDENT | 1 |
ORDER_CHANNEL_TYPE_SCRIPT_ENFORCED | 2 |
ORDER_CHANNEL_TYPE_SIMPLE_TAPROOT | 3 |
poolrpc.OrderState
Name | Number |
---|---|
ORDER_SUBMITTED | 0 |
ORDER_CLEARED | 1 |
ORDER_PARTIALLY_FILLED | 2 |
ORDER_EXECUTED | 3 |
ORDER_CANCELED | 4 |
ORDER_EXPIRED | 5 |
ORDER_FAILED | 6 |