gemini-node-api
v4.3.0
Published
Gemini Node.js API
Downloads
58
Readme
Gemini Node.js API
Node.js library for Gemini.
Installation
npm install gemini-node-api
Usage
PublicClient
import { PublicClient } from "gemini-node-api";
const client = new PublicClient();
const symbols = await client.getSymbols();
const symbol = "ZECLTC";
const info = await client.getSymbol({ symbol });
const symbol = "zecltc";
const ticker = await client.getTicker({ symbol });
/**
* for V2
* @see https://docs.gemini.com/rest-api/#ticker-v2
*/
const v = "v2";
const tickerV2 = await client.getTicker({ symbol, v });
const symbol = "zecltc";
const time_frame = "30m";
const candles = await client.getCandles({ symbol, time_frame });
const symbol = "zecltc";
const limit_bids = 25;
const limit_asks = 20;
const book = await client.getOrderBook({
symbol,
limit_bids,
limit_asks,
});
const symbol = "zecltc";
const timestamp = 1547146811;
const limit_trades = 100;
const include_breaks = true;
const trades = await client.getTradeHistory({
symbol,
timestamp,
limit_trades,
include_breaks,
});
const symbol = "zecltc";
const auction = await client.getCurrentAuction({ symbol });
const symbol = "zecltc";
const timestamp = 1547146811;
const limit_auction_results = 100;
const include_indicative = true;
const history = await client.getAuctionHistory({
symbol,
timestamp,
limit_auction_results,
include_indicative,
});
const priceFeed = await client.getPriceFeed();
AuthenticatedClient
import { AuthenticatedClient } from "gemini-node-api";
const key = "gemini-api-key";
const secret = "gemini-api-secret";
const client = new AuthenticatedClient({ key, secret });
const symbol = "zecltc";
const client_order_id = "d0c5340b-6d6c-49d9-b567-48c4bfca13d2";
const amount = 1;
const price = 0.9;
const side = "buy";
const options = ["maker-or-cancel"];
const order = await client.newOrder({
symbol,
client_order_id,
amount,
price,
side,
options,
});
const symbol = "zecltc";
const amount = 1;
const price = 0.9;
const account = "primary";
const type = "exchange limit";
const order = await client.buy({ symbol, amount, price, account, type });
const symbol = "zecltc";
const amount = 0.99;
const price = 0.99;
const stop_price = 1;
const type = "exchange stop limit";
const order = await client.sell({ symbol, amount, price, stop_price, type });
const order_id = 106817811;
const account = "primary";
const order = await client.cancelOrder({ order_id, account });
const account = "primary";
const response = await client.cancelSession({ account });
const account = "primary";
const response = await client.cancelAll({ account });
const order_id = 44375901;
const account = "primary";
const include_trades = true;
const order = await client.getOrderStatus({
order_id,
account,
include_trades,
});
const account = "primary";
const orders = await client.getActiveOrders({ account });
const symbol = "bcheth";
const limit_trades = 10;
const timestamp = 1547232911;
const account = "primary";
const trades = await client.getPastTrades({
symbol,
limit_trades,
timestamp,
account,
});
const account = "primary";
const volume = await client.getNotionalVolume({ account });
const volume = await client.getTradeVolume();
const counterparty_id = "OM9VNL1G";
const expires_in_hrs = 24;
const symbol = "btcusd";
const amount = 100;
const price = 9500;
const side = "buy";
const order = await client.newClearingOrder({
counterparty_id,
expires_in_hrs,
symbol,
amount,
price,
side,
});
const source_counterparty_id = "R485E04Q";
const target_counterparty_id = "Z4929ZDY";
const expires_in_hrs = 1;
const symbol = "ethusd";
const amount = 175;
const price = 200;
const side = "sell";
const order = await client.newBrokerOrder({
source_counterparty_id,
target_counterparty_id,
expires_in_hrs,
symbol,
amount,
price,
side,
});
const clearing_id = "OM9VNL1G";
const order = await client.getClearingOrderStatus({ clearing_id });
const clearing_id = "OM9VNL1G";
const order = await client.cancelClearingOrder({ clearing_id });
const clearing_id = "OM9VNL1G";
const symbol = "btcusd";
const amount = 100;
const price = 9500;
const side = "sell";
const order = await client.confirmClearingOrder({
clearing_id,
symbol,
amount,
price,
side,
});
const account = "primary";
const balances = await client.getAvailableBalances({ account });
const account = "primary";
const currency = "gbp";
const balances = await client.getNotionalBalances({ account, currency });
const timestamp = 1495127793;
const limit_transfers = 12;
const account = "primary";
const transfers = await client.getTransfers({
timestamp,
limit_transfers,
account,
});
const network = "bitcoincash";
const account = "primary";
const addresses = await client.getDepositAddresses({ network, account });
const currency = "ltc";
const label = "New LTC deposit address";
const legacy = true;
const account = "primary";
const address = await client.getNewAddress({
currency,
label,
legacy,
account,
});
const currency = "btc";
const address = "mi98Z9brJ3TgaKsmvXatuRahbFRUFKRUdR";
const amount = 10;
const account = "primary";
const withdrawal = await client.withdrawCrypto({
currency,
address,
account,
amount,
});
const currency = "btc";
const sourceAccount = "primary";
const targetAccount = "secondary";
const amount = "100";
const transfer = await client.internalTransfer({
currency,
sourceAccount,
targetAccount,
amount,
});
const accountnumber = "account-number-string";
const routing = "routing-number-string";
const type = "checking";
const name = "Satoshi Nakamoto Checking";
const result = await client.addBank({
accountnumber,
routing,
type,
name,
});
const account = "primary";
const methods = await client.getPaymentMethods({ account });
const account = "primary";
const amount = "893484.26";
const bankId = "97631a24-ca40-4277-b3d5-38c37673d029";
const response = await client.withdrawSEN({ account, amount, bankId });
const account = "primary";
const details = await client.getAccountDetails({ account });
const name = "My Secondary Account";
const type = "custody";
const result = await client.createAccount({ name, type });
const accounts = await client.getAccounts();
const address = "0x0F2B20Acb2fD7EEbC0ABc3AEe0b00d57533b6bD1";
const amount = "500";
const account = "primary";
const withdrawal = await client.withdrawGUSD({ address, amount, account });
const heartbeat = await client.heartbeat();
WebsocketClient
import { WebsocketClient } from "gemini-node-api";
const key = "gemini-api-key";
const secret = "gemini-api-secret";
const websocket = new WebsocketClient({ key, secret });
websocket.on("error", (error, market) => {
console.error(error);
});
websocket.on("open", (market) => {
console.log("The connection is open", market);
});
websocket.on("close", (market) => {
console.log("The connection is closed", market);
});
websocket.on("message", (message, market) => {
console.info("New message from", market);
console.info(message);
});
const heartbeat = true;
const top_of_book = false;
const bids = true;
const offers = true;
const trades = true;
const auctions = false;
const symbol = "zecltc";
websocket.on("open", (market) => console.log("Open:", market));
await websocket.connectMarket({
symbol,
heartbeat,
top_of_book,
bids,
offers,
trades,
auctions,
});
await websocket.connectMarket({ symbol: "btcusd" });
const symbol = "zecltc";
websocket.once("close", (market) => console.log("Closed:", market));
await websocket.disconnectMarket({ symbol });
websocket.on("open", (market) => console.log("Open:", market));
await websocket.connect();
websocket.once("close", (market) => console.log("Closed:", market));
await websocket.disconnect();
const subscriptions = [
{ name: "l2", symbols: ["BTCUSD", "ETHUSD"] },
{ name: "candles_1m", symbols: ["BTCUSD"] },
];
await websocket.connect();
await websocket.subscribe(subscriptions);
const subscriptions = [{ name: "l2", symbols: ["BTCUSD", "ETHUSD"] }];
await websocket.unsubscribe(subscriptions);
const symbolFilter = "zecltc";
const apiSessionFilter = "UI";
const eventTypeFilter = ["accepted", "rejected"];
const account = "primary";
websocket.on("message", (message, market) => {
if (market === "orders") {
console.log("New message:", message);
}
});
await websocket.connectOrders({
account,
symbolFilter,
apiSessionFilter,
eventTypeFilter,
});
websocket.once("close", (market) => {
if (market === "orders") {
console.log("Closed");
}
});
await websocket.disconnectOrders();
Test
npm test