Skip to content

Commit

Permalink
feat(): added examples, finished adding all types, minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
JJ-Cro committed May 22, 2024
1 parent b318dbb commit 1d004e8
Show file tree
Hide file tree
Showing 15 changed files with 417 additions and 126 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ bundleReport.html
.history/
dist
coverage
localtest.sh

25 changes: 25 additions & 0 deletions examples/futures/getBalances.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { RestClient } from '../../src';

const account = {
key: process.env.API_KEY || 'yourApiHere',
secret: process.env.API_SECRET || 'yourSecretHere',
};

const gateRestClient = new RestClient({
apiKey: account.key,
apiSecret: account.secret,
});

async function getFuturesBalances() {
try {
console.log('Using API keys:', account);

// GET specific ticker
const ticker = await gateRestClient.getFuturesAccount({ settle: 'usdt' });
console.log('Response: ', ticker);
} catch (e) {
console.error(`Error in execution: `, e);
}
}

getFuturesBalances();
35 changes: 35 additions & 0 deletions examples/futures/getOrders.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { RestClient } from '../../src';

const account = {
key: process.env.API_KEY || 'yourApiHere',
secret: process.env.API_SECRET || 'yourSecretHere',
};

const gateRestClient = new RestClient({
apiKey: account.key,
apiSecret: account.secret,
});

async function getFuturesOrders() {
try {
console.log('Using API keys:', account);

// get open orders
const orders = await gateRestClient.getFuturesOrders({
settle: 'usdt',
status: 'open',
});
console.log('Response: ', orders);

// get finished orders
const orders1 = await gateRestClient.getFuturesOrders({
settle: 'usdt',
status: 'finished',
});
console.log('Response: ', orders1);
} catch (e) {
console.error(`Error in execution: `, e);
}
}

getFuturesOrders();
34 changes: 34 additions & 0 deletions examples/futures/getTickers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { RestClient } from '../../src';

const account = {
key: process.env.API_KEY || 'yourApiHere',
secret: process.env.API_SECRET || 'yourSecretHere',
};

const gateRestClient = new RestClient({
apiKey: account.key,
apiSecret: account.secret,
});

async function getFuturesTicker() {
try {
console.log('Using API keys:', account);

// GET specific ticker
const ticker = await gateRestClient.getFuturesTickers({
settle: 'usdt',
});
console.log('Response: ', ticker);

/* GET all tickers */
const allTickers = await gateRestClient.getFuturesTickers({
settle: 'usdt',
contract: 'BTC_USDT',
});
console.log('Response: ', allTickers);
} catch (e) {
console.error(`Error in execution: `, e);
}
}

getFuturesTicker();
31 changes: 31 additions & 0 deletions examples/futures/submitLimitOrder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { RestClient } from '../../src';

const account = {
key: process.env.API_KEY || 'yourApiHere',
secret: process.env.API_SECRET || 'yourSecretHere',
};

const gateRestClient = new RestClient({
apiKey: account.key,
apiSecret: account.secret,
});

async function submitFuturesOrder() {
try {
console.log('Using API keys:', account);

const result = await gateRestClient.submitFuturesOrder({
settle: 'usdt',
contract: 'BTC_USDT',
size: 0.1, // positive for long, negative for short
price: '45000',
tif: 'gtc',
});

console.log('Response: ', result);
} catch (e) {
console.error(`Error in execution: `, e);
}
}

submitFuturesOrder();
29 changes: 29 additions & 0 deletions examples/futures/submitMarketOrder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { RestClient } from '../../src';

const account = {
key: process.env.API_KEY || 'yourApiHere',
secret: process.env.API_SECRET || 'yourSecretHere',
};

const gateRestClient = new RestClient({
apiKey: account.key,
apiSecret: account.secret,
});

async function submitFuturesOrder() {
try {
console.log('Using API keys:', account);

const result = await gateRestClient.submitFuturesOrder({
settle: 'usdt',
contract: 'BTC_USDT',
size: 0.1, // positive for long, negative for short
});

console.log('Response: ', result);
} catch (e) {
console.error(`Error in execution: `, e);
}
}

submitFuturesOrder();
6 changes: 2 additions & 4 deletions examples/rest-private.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ import { RestClient } from '../src';
async function start() {
try {
const account = {
key: process.env.API_KEY || 'a4ed617b3c02b6a9d4900be5446f402d',
secret:
process.env.API_SECRET ||
'68151540a9808cd12bb57ed31e2fa868f5022879bf969eb27cfd7125c0dcea6e',
key: process.env.API_KEY || 'yourApiHere',
secret: process.env.API_SECRET || 'YourSecretHere',
};

console.log('using creds: ', account);
Expand Down
25 changes: 25 additions & 0 deletions examples/spot/getBalances.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { RestClient } from '../../src';

const account = {
key: process.env.API_KEY || 'yourApiHere',
secret: process.env.API_SECRET || 'yourSecretHere',
};

const gateRestClient = new RestClient({
apiKey: account.key,
apiSecret: account.secret,
});

async function getSpotBalances() {
try {
console.log('Using API keys:', account);

// GET specific ticker
const ticker = await gateRestClient.getSpotAccounts();
console.log('Response: ', ticker);
} catch (e) {
console.error(`Error in execution: `, e);
}
}

getSpotBalances();
35 changes: 35 additions & 0 deletions examples/spot/getOrders.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { RestClient } from '../../src';

const account = {
key: process.env.API_KEY || 'yourApiHere',
secret: process.env.API_SECRET || 'yourSecretHere',
};

const gateRestClient = new RestClient({
apiKey: account.key,
apiSecret: account.secret,
});

async function getSpotOrders() {
try {
console.log('Using API keys:', account);

// get open orders
const orders = await gateRestClient.getSpotOrders({
currency_pair: 'BTC_USDT',
status: 'open',
});
console.log('Response: ', orders);

// get finished orders
const orders1 = await gateRestClient.getSpotOrders({
currency_pair: 'BTC_USDT',
status: 'finished',
});
console.log('Response: ', orders1);
} catch (e) {
console.error(`Error in execution: `, e);
}
}

getSpotOrders();
31 changes: 31 additions & 0 deletions examples/spot/getTickers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { RestClient } from '../../src';

const account = {
key: process.env.API_KEY || 'yourApiHere',
secret: process.env.API_SECRET || 'yourSecretHere',
};

const gateRestClient = new RestClient({
apiKey: account.key,
apiSecret: account.secret,
});

async function getSpotTicker() {
try {
console.log('Using API keys:', account);

// GET specific ticker
const ticker = await gateRestClient.getSpotTicker({
currency_pair: 'BTC_USDT',
});
console.log('Response: ', ticker);

/* GET all tickers */
const allTickers = await gateRestClient.getSpotTicker();
console.log('Response: ', allTickers);
} catch (e) {
console.error(`Error in execution: `, e);
}
}

getSpotTicker();
32 changes: 32 additions & 0 deletions examples/spot/submitLimitOrder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { RestClient } from '../../src';

const account = {
key: process.env.API_KEY || 'yourApiHere',
secret: process.env.API_SECRET || 'yourSecretHere',
};

const gateRestClient = new RestClient({
apiKey: account.key,
apiSecret: account.secret,
});

async function submitSpotOrder() {
try {
console.log('Using API keys:', account);

const result = await gateRestClient.submitSpotOrder({
currency_pair: 'BTC_USDT',
side: 'buy',
type: 'limit',
amount: '0.10',
price: '45000',
time_in_force: 'gtc',
});

console.log('Response: ', result);
} catch (e) {
console.error(`Error in execution: `, e);
}
}

submitSpotOrder();
31 changes: 31 additions & 0 deletions examples/spot/submitMarketOrder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { RestClient } from '../../src';

const account = {
key: process.env.API_KEY || 'yourApiHere',
secret: process.env.API_SECRET || 'yourSecretHere',
};

const gateRestClient = new RestClient({
apiKey: account.key,
apiSecret: account.secret,
});

async function submitSpotOrder() {
try {
console.log('Using API keys:', account);

const result = await gateRestClient.submitSpotOrder({
currency_pair: 'BTC_USDT',
side: 'buy',
type: 'market',
amount: '10',
time_in_force: 'ioc',
});

console.log('Response: ', result);
} catch (e) {
console.error(`Error in execution: `, e);
}
}

submitSpotOrder();
Loading

0 comments on commit 1d004e8

Please sign in to comment.