Skip to content

ODEX web client library for trading bots or custom trading interfaces

License

Notifications You must be signed in to change notification settings

byteball/odex-client-browser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ODEX client browser library

Use this library to trade on ODEX from a browser. It's a web version of headless odex client.

JS bundle

The library can be used as a javascript bundle included in your webpage.

Build the bundle

Install Node 8 or superior

git clone https://github.com/byteball/odex-client-browser.git
cd odex-client-browser
npm install
npm run build

The created bundle ocb.min.js will be found in dist folder. Check example.html for its usage.

Library

The library can be included in a project using webpack (like vuejs or react-js)

Installation

Add odex-client-browser as a dependency in your package.json:

	"dependencies": {
		"odex-client-browser": "git+https://github.com/byteball/odex-client-browser.git"
	}

Usage

Same functions as in headless odex client are available. The main difference is that the account is not generated automatically but private key is to be provided in WIF format. See https://obytejs.com/utils/generate-wallet for instructions.

const ocb = require('odex-client-browser');
let { orders, ws_api, rest_api, exchange, account } = ocb;

async function start() {
	await ocb.start({
		wif: "92miJ9H6AnWFVSoRbtNgzwRbzAesWEPrMRdDkCsXoxwddBYGA71"
	});

	// subscribe to new orders and trades on a pair
	await ws_api.subscribeOrdersAndTrades('GBYTE/USDC');
	ws_api.on('orders', (type, payload) => {
		console.error('received orders', type, payload);
	});
	ws_api.on('trades', (type, payload) => {
		console.error('received trades', type, payload);
	});

	// this will automatically update orders.assocMyOrders object which holds all my orders keyed by order hash. New orders will be automatically added, filled and cancelled orders will be automatically removed
	await orders.trackMyOrders();

	// place a new order, side is 'BUY' or 'SELL'
	await orders.createAndSendOrder('GBYTE/USDC', side, amount, price);

	// cancel an order
	await orders.createAndSendCancel(order_hash);
}

start();

Trading balances

The library includes an Obyte wallet that holds your trading balances. You need to deposit funds to this wallet before trading. The wallet address is returned by ocb.account.getAddress()

Use these functions for balances management:

Deposit to Odex AA

ocb.account.deposit(asset, amount)

Withdraw from Odex AA

ocb.account.withdraw(asset, amount)

Help

#tech channel on discord https://discord.obyte.org.

About

ODEX web client library for trading bots or custom trading interfaces

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published