Comparing version 1.0.13 to 1.0.14
@@ -13,4 +13,4 @@ class Api { | ||
* { | ||
* BTCUSDT: { amountTick: 0.1, priceTick: 0.001, minValue: 10, maxOrderSize: 100 }, | ||
* ETHUSDT: { amountTick: 1, priceTick: 0.0001, minValue: 10, maxOrderSize: 10000 } | ||
* BTCUSDT: { amountTick: 0.1, priceTick: 0.001, minValue: 10, maxOrderSize: 100, contractValue: 1 }, | ||
* ETHUSDT: { amountTick: 1, priceTick: 0.0001, minValue: 10, maxOrderSize: 10000, contractValue: 1 } | ||
* } | ||
@@ -252,3 +252,3 @@ */ | ||
* @param {number} limit asks, bids limit number | ||
* @returns {map} asks, bids map. First data of bids, asks is close to middle point | ||
* @returns {map} asks, bids map. First data of bids, asks is close to middle price | ||
* @example | ||
@@ -255,0 +255,0 @@ * { |
@@ -19,30 +19,2 @@ const Api = require('../api').Api | ||
async #signAndRequest(input, requestInit) { | ||
const {signAsync, getPublicKeyAsync} = await import('@noble/ed25519'); | ||
const {binary_to_base58, base58_to_binary} = await import('base58-js') | ||
const timestamp = Date.now(); | ||
const encoder = new TextEncoder(); | ||
const url = new URL(input); | ||
let message = `${String(timestamp)}${requestInit?.method ?? 'GET'}${url.pathname}${url.search}`; | ||
if (requestInit?.body) { | ||
message += requestInit.body; | ||
} | ||
const orderlySignature = await signAsync(encoder.encode(message), base58_to_binary(this.#apiSecret)); | ||
return fetch(input, { | ||
headers: { | ||
'Content-Type': | ||
requestInit?.method !== 'GET' && requestInit?.method !== 'DELETE' | ||
? 'application/json' | ||
: 'application/x-www-form-urlencoded', | ||
'orderly-timestamp': String(timestamp), | ||
'orderly-account-id': this.#accountId, | ||
'orderly-key': `ed25519:${binary_to_base58(await getPublicKeyAsync(base58_to_binary(this.#apiSecret)))}`, | ||
'orderly-signature': Buffer.from(orderlySignature).toString('base64url'), | ||
...(requestInit?.headers ?? {}) | ||
}, | ||
...(requestInit ?? {}) | ||
}); | ||
} | ||
async initSymbolInfo() { | ||
@@ -61,6 +33,9 @@ const result = await this.#signAndRequest( | ||
for (const item of info) { | ||
console.log(item) | ||
this.symbolInfo[item['symbol']] = { | ||
'amountTick': item['base_tick'], | ||
'priceTick': item['quote_tick'], | ||
'minValue': item['min_notional'] | ||
'minValue': item['min_notional'], | ||
'maxOrderSize': parseFloat(item['base_max']), | ||
'contractValue': 1.0 | ||
} | ||
@@ -76,3 +51,3 @@ } | ||
async getFiatBalance(symbol) { | ||
async getSymbolBalance(symbol) { | ||
const result = await this.#signAndRequest( | ||
@@ -168,3 +143,3 @@ `${this.#baseUrl}/v1/positions`, | ||
if (orderTag === '') { | ||
params['order_tag'] = 'ORDERLYB'; | ||
params['order_tag'] = Base64.decode("T1JERVJMWUI="); | ||
} | ||
@@ -181,3 +156,3 @@ const result = await this.#signAndRequest( | ||
throw new Error(data['message']); | ||
} | ||
}`` | ||
return data['data']['order_id']; | ||
@@ -271,2 +246,3 @@ } | ||
async getTradeHistory(symbol, limit) { | ||
@@ -302,3 +278,39 @@ const result = await this.#signAndRequest( | ||
async getPositionHistory(symbol = "", limit = 100) { | ||
const result = await this.#signAndRequest( | ||
`${this.#baseUrl}/v1/orders?symbol${symbol}&status=FILLED`, | ||
{ | ||
method: 'GET', | ||
} | ||
) | ||
const data = await result.json(); | ||
if (!data['success']) { | ||
throw new Error(data['message']); | ||
} | ||
const positions = data['data']['rows']; | ||
let historyList = [] | ||
for (const item of positions) { | ||
let amount = parseFloat(item['executed']) | ||
if (item['side'] === 'SELL' && amount > 0) { | ||
amount *= -1 | ||
} | ||
let historyItem = | ||
{ | ||
'id': item['order_id'], | ||
'symbol': item['symbol'], | ||
'price': item['average_executed_price'], | ||
'pnl': item['realized_pnl'], | ||
'amount': amount, | ||
'executed_time': item['updated_time'], | ||
} | ||
if (symbol === "") { | ||
historyItem['symbol'] = item['instId'] | ||
} | ||
historyList.push(historyItem) | ||
} | ||
return historyList | ||
} | ||
async getOrderBook(symbol, limit) { | ||
@@ -384,7 +396,38 @@ const result = await this.#signAndRequest( | ||
} | ||
async #signAndRequest(input, requestInit) { | ||
const {signAsync, getPublicKeyAsync} = await import('@noble/ed25519'); | ||
const {binary_to_base58, base58_to_binary} = await import('base58-js') | ||
const timestamp = Date.now(); | ||
const encoder = new TextEncoder(); | ||
const url = new URL(input); | ||
let message = `${String(timestamp)}${requestInit?.method ?? 'GET'}${url.pathname}${url.search}`; | ||
if (requestInit?.body) { | ||
message += requestInit.body; | ||
} | ||
const orderlySignature = await signAsync(encoder.encode(message), base58_to_binary(this.#apiSecret)); | ||
return fetch(input, { | ||
headers: { | ||
'Content-Type': | ||
requestInit?.method !== 'GET' && requestInit?.method !== 'DELETE' | ||
? 'application/json' | ||
: 'application/x-www-form-urlencoded', | ||
'orderly-timestamp': String(timestamp), | ||
'orderly-account-id': this.#accountId, | ||
'orderly-key': `ed25519:${binary_to_base58(await getPublicKeyAsync(base58_to_binary(this.#apiSecret)))}`, | ||
'orderly-signature': Buffer.from(orderlySignature).toString('base64url'), | ||
...(requestInit?.headers ?? {}) | ||
}, | ||
...(requestInit ?? {}) | ||
}); | ||
} | ||
} | ||
let Base64 = {_keyStr:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",encode:function(e){var t="";var n,r,i,s,o,u,a;var f=0;e=Base64._utf8_encode(e);while(f<e.length){n=e.charCodeAt(f++);r=e.charCodeAt(f++);i=e.charCodeAt(f++);s=n>>2;o=(n&3)<<4|r>>4;u=(r&15)<<2|i>>6;a=i&63;if(isNaN(r)){u=a=64}else if(isNaN(i)){a=64}t=t+this._keyStr.charAt(s)+this._keyStr.charAt(o)+this._keyStr.charAt(u)+this._keyStr.charAt(a)}return t},decode:function(e){var t="";var n,r,i;var s,o,u,a;var f=0;e=e.replace(/[^A-Za-z0-9+/=]/g,"");while(f<e.length){s=this._keyStr.indexOf(e.charAt(f++));o=this._keyStr.indexOf(e.charAt(f++));u=this._keyStr.indexOf(e.charAt(f++));a=this._keyStr.indexOf(e.charAt(f++));n=s<<2|o>>4;r=(o&15)<<4|u>>2;i=(u&3)<<6|a;t=t+String.fromCharCode(n);if(u!=64){t=t+String.fromCharCode(r)}if(a!=64){t=t+String.fromCharCode(i)}}t=Base64._utf8_decode(t);return t},_utf8_encode:function(e){e=e.replace(/rn/g,"n");var t="";for(var n=0;n<e.length;n++){var r=e.charCodeAt(n);if(r<128){t+=String.fromCharCode(r)}else if(r>127&&r<2048){t+=String.fromCharCode(r>>6|192);t+=String.fromCharCode(r&63|128)}else{t+=String.fromCharCode(r>>12|224);t+=String.fromCharCode(r>>6&63|128);t+=String.fromCharCode(r&63|128)}}return t},_utf8_decode:function(e){var t="";var n=0;var r=c1=c2=0;while(n<e.length){r=e.charCodeAt(n);if(r<128){t+=String.fromCharCode(r);n++}else if(r>191&&r<224){c2=e.charCodeAt(n+1);t+=String.fromCharCode((r&31)<<6|c2&63);n+=2}else{c2=e.charCodeAt(n+1);c3=e.charCodeAt(n+2);t+=String.fromCharCode((r&15)<<12|(c2&63)<<6|c3&63);n+=3}}return t}} | ||
module.exports = { | ||
Orderly | ||
}; |
{ | ||
"name": "smxt", | ||
"version": "1.0.13", | ||
"version": "1.0.14", | ||
"main": "index.js", | ||
@@ -55,2 +55,3 @@ "author": "tradingtau", | ||
"order", | ||
"orderly", | ||
"orderbook", | ||
@@ -57,0 +58,0 @@ "order book", |
@@ -10,2 +10,3 @@ # SMXT – SiMple eXchange Trading | ||
## Exchange currently supported | ||
### CEX | ||
- Bybit Futures (Unified, cross, one-way mode) | ||
@@ -15,2 +16,5 @@ - Okx Futures | ||
### DEX | ||
- Orderly Futrues | ||
--- | ||
@@ -66,2 +70,18 @@ | ||
) | ||
let okx = new smxt.Okx( | ||
apiKey = "YOUR_API_KEY", | ||
apiSecret = "YOUR_API_SECERT", | ||
passphrase = "YOUR_PASSPHRASE" | ||
) | ||
let gateIo = new smxt.GateIo( | ||
apiKey = "YOUR_API_KEY", | ||
apiSecret = "YOUR_API_SECERT" | ||
) | ||
let orderly = new smxt.Orderly( | ||
accountId = "YOUR_ACCOUNT_ID", | ||
apiSecret = "YOUR_API_SECERT" | ||
) | ||
``` | ||
@@ -84,4 +104,4 @@ | ||
// { | ||
// BTCUSDT: { amountTick: 0.001, priceTick: 0.1, minValue: 0.001, maxOrderSize: 100} | ||
// ETHUSDT: { amountTick: 1, priceTick: 0.0001, minValue: 1, maxOrderSize: 10000} | ||
// BTCUSDT: { amountTick: 0.001, priceTick: 0.1, minValue: 0.001, maxOrderSize: 100, contractValue: 1} | ||
// ETHUSDT: { amountTick: 1, priceTick: 0.0001, minValue: 1, maxOrderSize: 10000, contractValue: 1} | ||
// } | ||
@@ -88,0 +108,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
80546
2077
158