# 磁力兑换做市商

# MOV-MMDK介绍

MOV Market Maker Develo pment Kit,基于MOV Server的RESTful API开发的Python SDK,提供获取市场深度、发送订单、取消订单、查询订单、查询账户余额等功能。

# MOV-MMDK安装

git clone https://github.com/Bytom/mov-mmdk
cd mov-mmdk/
pip3 install -r requirements.txt
python3 setup.py install

# 磁力兑换做市流程

磁力兑换是MOV协议下的核心产品之一,是将用户的资产通过合约的形式在链上完成挂单,撮合和成交的一种资产交易方式。通俗的说,磁力兑换实现的就是去中心化交易的功能,并且在去中心的同时具备了媲美中心化交易所的速度。

# 磁力做市架构

img

# 磁力做市原理

MOV Server只是提供订单与交易之间的相互转化,实际上所有的订单都是由用户签名后提交, 并最终由智能合约进行撮合的过程。 MOV Server提供了与中心化交易所接近一致的API接口,其交易时的API使用体验,基本与中心化交易所一致,但依然有一些不同,下面我们将会进行说明。

# 磁力做市教程

在代码中添加依赖,创建Api对象就可以调用MOV-MMDK提供的API参与磁力兑换做市商。

from mov_sdk.mov_api import MovApi

# 获取私钥并初始化

//通过助记词初始化
api = MovApi(secret_key="")
config = api.init_from_mnemonic("你的助记词")
print(api.main_address)
print(api.vapor_address)
print(api.public_key)

//通过私钥初始化
api = MovApi(secret_key="你的私钥")
print(api.main_address)
print(api.vapor_address)
print(api.public_key)

//以下两种方式会创建新地址并且初始化
api = MovApi("")
print(api.secret_key)
print(api.main_address)
print(api.vapor_address)
print(api.public_key)

api = MovApi("")
print(api.get_new_secret_key())
print(api.main_address)
print(api.vapor_address)

# 获得磁力交易对信息

返回MOV所有的交易对信息

>>> print(api.get_exchange_info())

{
	'code': 200,
	'msg': '',
	'data': [{
		'price_decimal': 4,
		'amount_decimal': 2,
		'base_asset': {
			'asset_id': 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
			'decimals': 8,
			'symbol': 'BTM'
		},
		'quote_asset': {
			'asset_id': '184e1cc4ee4845023888810a79eed7a42c02c544cf2c61ceac05e176d575bd46',
			'decimals': 6,
			'symbol': 'USDT'
		}
	}, {
		'price_decimal': 2,
		'amount_decimal': 4,
		'base_asset': {
			'asset_id': '78de44ffa1bce37b757c9eae8925b5f199dc4621b412ef0f3f46168865284a93',
			'decimals': 9,
			'symbol': 'ETH'
		},
		'quote_asset': {
			'asset_id': '184e1cc4ee4845023888810a79eed7a42c02c544cf2c61ceac05e176d575bd46',
			'decimals': 6,
			'symbol': 'USDT'
		}
	}, {
		'price_decimal': 8,
		'amount_decimal': 2,
		'base_asset': {
			'asset_id': 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
			'decimals': 8,
			'symbol': 'BTM'
		},
		'quote_asset': {
			'asset_id': '78de44ffa1bce37b757c9eae8925b5f199dc4621b412ef0f3f46168865284a93',
			'decimals': 9,
			'symbol': 'ETH'
		}
	}, {
		'price_decimal': 8,
		'amount_decimal': 2,
		'base_asset': {
			'asset_id': 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
			'decimals': 8,
			'symbol': 'BTM'
		},
		'quote_asset': {
			'asset_id': 'bda946b3110fa46fd94346ce3f05f0760f1b9de72e238835bc4d19f9d64f1742',
			'decimals': 8,
			'symbol': 'BTC'
		}
	}, {
		'price_decimal': 2,
		'amount_decimal': 4,
		'base_asset': {
			'asset_id': 'bda946b3110fa46fd94346ce3f05f0760f1b9de72e238835bc4d19f9d64f1742',
			'decimals': 8,
			'symbol': 'BTC'
		},
		'quote_asset': {
			'asset_id': '184e1cc4ee4845023888810a79eed7a42c02c544cf2c61ceac05e176d575bd46',
			'decimals': 6,
			'symbol': 'USDT'
		}
	}, {
		'price_decimal': 6,
		'amount_decimal': 4,
		'base_asset': {
			'asset_id': '78de44ffa1bce37b757c9eae8925b5f199dc4621b412ef0f3f46168865284a93',
			'decimals': 9,
			'symbol': 'ETH'
		},
		'quote_asset': {
			'asset_id': 'bda946b3110fa46fd94346ce3f05f0760f1b9de72e238835bc4d19f9d64f1742',
			'decimals': 8,
			'symbol': 'BTC'
		}
	}, {
		'price_decimal': 2,
		'amount_decimal': 8,
		'base_asset': {
			'asset_id': '47fcd4d7c22d1d38931a6cd7767156babbd5f05bbbb3f7d3900635b56eb1b67e',
			'decimals': 8,
			'symbol': 'SUP'
		},
		'quote_asset': {
			'asset_id': 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
			'decimals': 8,
			'symbol': 'BTM'
		}
	}, {
		'price_decimal': 4,
		'amount_decimal': 8,
		'base_asset': {
			'asset_id': '47fcd4d7c22d1d38931a6cd7767156babbd5f05bbbb3f7d3900635b56eb1b67e',
			'decimals': 8,
			'symbol': 'SUP'
		},
		'quote_asset': {
			'asset_id': '184e1cc4ee4845023888810a79eed7a42c02c544cf2c61ceac05e176d575bd46',
			'decimals': 6,
			'symbol': 'USDT'
		}
	}]
}

# 获得磁力兑换深度

获取市场指定交易对的深度

>>> print(api.get_depth("BTC/USDT", 5))

{
	'code': 200,
	'msg': '',
	'data': {
		'symbol': 'BTC/USDT',
		'fee_rate': '',
		'asks': [
			['17951.94', '0.0022'],
			['17954.80', '0.2183'],
			['17956.60', '0.0124'],
			['17958.40', '0.0742'],
			['17961.11', '0.1758']
		],
		'bids': [
			['17908.50', '0.0317'],
			['17903.69', '0.0428'],
			['17901.90', '0.0184'],
			['17900.11', '0.0166'],
			['17898.32', '0.0011']
		],
		'timestamp': 1605754831534
	}
}

# 发送磁力交易订单

调用SDK发送订单,send order封装了build和submit过程

>>> print(api.send_order(symbol="BTM/USDT", side="sell", price=888, volume=1))

{
	'code': 200,
	'msg': '',
	'data': {
		'tx_hash': '1335845f53c7e0f72b709b659c1db69f60a42adcdb3dd2b0c7bbedc2be1d73f7',
		'order': {
			'symbol': 'BTM/USDT',
			'side': 'sell',
			'order_id': 6688061,
			'open_price': '888.00000000000000000000',
			'deal_price': '0',
			'amount': '1.00',
			'filled_amount': '0.00',
			'fee_amount': '0.000000',
			'status': 'submitted',
			'type': 'mov',
			'client_id': '',
			'order_txs': [{
				'hash': '1335845f53c7e0f72b709b659c1db69f60a42adcdb3dd2b0c7bbedc2be1d73f7',
				'type': 'mov_place_order',
				'timestamp': 1605755145
			}],
			'order_timestamp': 1605755145,
			'update_timestamp': 1605755145
		}
	}
}

# 查询所有未成交的磁力订单

调用SDK查询所有未成交的磁力订单

>>> print(api.query_open_orders("BTM/USDT"))

{
	'code': 200,
	'msg': '',
	'data': [{
		'symbol': 'BTM/USDT',
		'side': 'sell',
		'order_id': 6688061,
		'open_price': '888.0000000000',
		'deal_price': '0.0000000000',
		'amount': '1.00',
		'filled_amount': '0.00',
		'fee_amount': '0.000000',
		'status': 'open',
		'type': 'mov',
		'client_id': '',
		'order_txs': [{
			'hash': '1335845f53c7e0f72b709b659c1db69f60a42adcdb3dd2b0c7bbedc2be1d73f7',
			'type': 'mov_place_order',
			'timestamp': 1605755145
		}],
		'order_timestamp': 1605755145,
		'update_timestamp': 1605755146
	}],
	'pagination': {
		'start': 0,
		'limit': 1000,
		'_links': {}
	}
}

# 通过订单号查询磁力订单

>>> print(api.query_list_orders([6688061]))

{
	'code': 200,
	'msg': '',
	'data': [{
		'symbol': 'BTM/USDT',
		'side': 'sell',
		'order_id': 6688061,
		'open_price': '888.0000000000',
		'deal_price': '0.0000000000',
		'amount': '1.00',
		'filled_amount': '0.00',
		'fee_amount': '0.000000',
		'status': 'open',
		'type': 'mov',
		'client_id': '',
		'order_txs': [{
			'hash': '1335845f53c7e0f72b709b659c1db69f60a42adcdb3dd2b0c7bbedc2be1d73f7',
			'type': 'mov_place_order',
			'timestamp': 1605755145
		}],
		'order_timestamp': 1605755145,
		'update_timestamp': 1605755146
	}],
	'pagination': {
		'start': 0,
		'limit': 1000,
		'_links': {}
	}
}

# 磁力撤单

通过sdk撤销指定订单号的订单

>>> print(api.cancel_order(710924))

{
	'code': 200,
	'msg': '',
	'data': {
		'tx_hash': '2387e1ab0c462b212fb2252708a8792ad57c5b1ad5857cadf1cce200ce6ab5d3'
	}
}

# 查询账户余额数据

>>> print(api.get_balance())

{
	'code': 200,
	'msg': '',
	'data': {
		'address': 'vp1quxu2u2m04stfc82v3ucgpr00vr0w8xuc2zqgu5',
		'label': 'byone',
		'balances': [{
			'asset': {
				'asset_id': 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
				'decimals': 0,
				'symbol': 'BTM',
				'name': 'Bytom',
				'type': 'BTM'
			},
			'balance': '0.97555',
			'available_balance': '0.97555',
			'unconfirmed_balance': '0',
			'total_received': '3.98355',
			'total_sent': '3.008',
			'in_usd': '0.06',
			'in_cny': '0.37',
			'in_btc': '0.000003'
		}, {
			'asset': {
				'asset_id': 'bda946b3110fa46fd94346ce3f05f0760f1b9de72e238835bc4d19f9d64f1742',
				'decimals': 0,
				'symbol': 'BTC',
				'name': 'Bitcoin',
				'type': 'BTC'
			},
			'balance': '0',
			'available_balance': '0',
			'unconfirmed_balance': '0',
			'total_received': '0',
			'total_sent': '0',
			'in_usd': '0.00',
			'in_cny': '0.00',
			'in_btc': '0.000000'
		}, {
			'asset': {
				'asset_id': '47fcd4d7c22d1d38931a6cd7767156babbd5f05bbbb3f7d3900635b56eb1b67e',
				'decimals': 0,
				'symbol': 'SUP',
				'name': 'SUP',
				'type': 'BTM'
			},
			'balance': '0',
			'available_balance': '0',
			'unconfirmed_balance': '0',
			'total_received': '0',
			'total_sent': '0',
			'in_usd': '0.00',
			'in_cny': '0.00',
			'in_btc': '0.000000'
		}, {
			'asset': {
				'asset_id': '78de44ffa1bce37b757c9eae8925b5f199dc4621b412ef0f3f46168865284a93',
				'decimals': 0,
				'symbol': 'ETH',
				'name': 'Ethereum',
				'type': 'ETH'
			},
			'balance': '0',
			'available_balance': '0',
			'unconfirmed_balance': '0',
			'total_received': '0',
			'total_sent': '0',
			'in_usd': '0.00',
			'in_cny': '0.00',
			'in_btc': '0.000000'
		}, {
			'asset': {
				'asset_id': '184e1cc4ee4845023888810a79eed7a42c02c544cf2c61ceac05e176d575bd46',
				'decimals': 0,
				'symbol': 'USDT',
				'name': 'USDT-ERC20',
				'type': 'ETH'
			},
			'balance': '0',
			'available_balance': '0',
			'unconfirmed_balance': '0',
			'total_received': '1.0593',
			'total_sent': '1.0593',
			'in_usd': '0.00',
			'in_cny': '0.00',
			'in_btc': '0.000000'
		}, {
			'asset': {
				'asset_id': '25f2069140fa3ff4d6e0dc1d0fcaa11ace01eb721f115f0f1a5a3782db597fb1',
				'decimals': 0,
				'symbol': 'DAI',
				'name': 'Dai Stablecoin',
				'type': 'ETH'
			},
			'balance': '0',
			'available_balance': '0',
			'unconfirmed_balance': '0',
			'total_received': '0',
			'total_sent': '0',
			'in_usd': '0.00',
			'in_cny': '0.00',
			'in_btc': '0.000000'
		}, {
			'asset': {
				'asset_id': 'c4644dd6643475d57ed624f63129ab815f282b61f4bb07646d73423a6e1a1563',
				'decimals': 0,
				'symbol': 'USDC',
				'name': 'USDC-ERC20',
				'type': 'ETH'
			},
			'balance': '0',
			'available_balance': '0',
			'unconfirmed_balance': '0',
			'total_received': '0',
			'total_sent': '0',
			'in_usd': '0.00',
			'in_cny': '0.00',
			'in_btc': '0.000000'
		}, {
			'asset': {
				'asset_id': '011a24f9da7551d4cd9ae0f194aa1d1691e22a173edf7d81aabd9a97ca386252',
				'decimals': 0,
				'symbol': 'LTC',
				'name': 'Litecoin',
				'type': 'LTC'
			},
			'balance': '0',
			'available_balance': '0',
			'unconfirmed_balance': '0',
			'total_received': '0',
			'total_sent': '0',
			'in_usd': '0.00',
			'in_cny': '0.00',
			'in_btc': '0.000000'
		}],
		'votes': []
	}
}
Last Updated: 12/16/2020, 1:49:21 PM