In the last lesson, we explained how to trade bitcoin in OceanOne. OceanOne supports the exchange of tokens on any Mixin Network, including all ERC20 and EOS tokens, with no formalities and no fees. Here’s how to hang up an ERC20 token for OceanOne transaction! After mastering the ERC20 token, you can buy and sell any token on Ocean.
Here we use an ERC20 token called Benz. This token has been charged to the Mixin Network, and you can see the total number and transactions of this token within the Mixin Network in the blockchain browser
Preliminary knowledge:
Deposit Your Benz coin in your wallet, then use the getAssets API to read its UUID.
Get the UUID of the coin
Calling the getAssets API returns JSON data, such as:
- UUID asset_id currency.
- Public_key Current wallet address of the coin.
- Symbol The name of a currency. Such as: Benz.
if ($line == 'aw') {
$mixinSdk_eachAccountInstance = GenerateWalletSDKFromCSV();
$asset_info = $mixinSdk_eachAccountInstance->Wallet()->readAssets();
foreach ($asset_info as $key => $asset) {
echo $asset["symbol"]."" . $asset["asset_id"]."". $asset["balance"]."". $asset["public_key"].PHP_EOL; }}Copy the code
The complete output of a call to the getAssets API is as follows:
Make your choose:aw
run...
client id is:26b20aa5-40c0-3e00-9de0-666cfb6f2daa
Benz 2b9c216c-ef60-398d-a42a-eba1b298581d 799 0x9A4F6c67444cd6558905ef5B04a4c429b9538A9d
EOS 6cfe566e-4aad-470b-8c9a-2fd35b49c68d 0
CNB 965e5c6e-434c-3fa9-b780-c50f43cd4.72599997 0 x9a4f6c67444 955 ccd6558905ef5B04a4c429b9538A9d
BTC c6d0c728-2624-429b-8e0d-d9 d19b6592fa 0 17 z1rq3vsyvvxvgwiht8yerjbofgnherb8 XIN c94ac88f - 4671-3976-0.01 0 x9a4f6c67444 f1811e8 b60a - 09064cd6558905ef5B04a4c429b9538A9d
Copy the code
Price are cancelled
- An order that is below or equal to the market price.
- Limit order An order higher than or equal to the market price.
OceanOne supports three base price categories: USDT, XIN, BTC, namely: Benz/USDT, Benz/XIN, Benz/BTC, Benz/USDT here.
Limit price hang sell order.
After the new currency is listed, we need to wait for about a minute for OceanOne to initialize the relevant data of the new currency.
if ( $ocmd == 's1') {
$p = readline("Input the Price of XIN/USDT: ");
$a = readline("Input the Amount of XIN: ");
$tMemo = GenerateOrderMemo("A",USDT_ASSET_ID,$p);
echo $tMemo . PHP_EOL;
$mixinSdk_WalletInstance = GenerateWalletSDKFromCSV();
$asset_info = $mixinSdk_WalletInstance->Wallet()->readAsset(XIN_ASSET_ID);
print_r($asset_info);
if ( (float) $asset_info["balance"] >= (float) $a ) {
$transInfos = $mixinSdk_WalletInstance->Wallet()->transfer(XIN_ASSET_ID,OCEANONE_BOT,
$mixinSdk_WalletInstance->getConfig()['default'] ['pin'],
$a,
$tMemo);
print_r($transInfos);
echo "The Order ID (trace_id) is: " . $transInfos["trace_id"] . PHP_EOL;
} else { echo "Not enough XIN! \n";}
}
Copy the code
Limit price hang buy.
After the new currency is listed, we need to wait for about a minute for OceanOne to initialize the relevant data of the new currency.
if ( $ocmd == 'b1') {
$p = readline("Input the Price of XIN/USDT: ");
$a = readline("Input the Amount of USDT: ");
$tMemo = GenerateOrderMemo("B",XIN_ASSET_ID,$p);
echo $tMemo . PHP_EOL;
$mixinSdk_WalletInstance = GenerateWalletSDKFromCSV();
$asset_info = $mixinSdk_WalletInstance->Wallet()->readAsset(USDT_ASSET_ID);
print_r($asset_info);
if ( ((float) $asset_info["balance"] > =1) && ( (float) $asset_info["balance"] >= (float) $a ) ) {
$transInfos = $mixinSdk_WalletInstance->Wallet()->transfer(USDT_ASSET_ID,OCEANONE_BOT,
$mixinSdk_WalletInstance->getConfig()['default'] ['pin'],
$a,
$tMemo);
print_r($transInfos);
echo "The Order ID (trace_id) is: " . $transInfos["trace_id"] . PHP_EOL;
} else { echo "Not enough USDT! \n";}
}
Copy the code
Read the price list of coins
Read the price list of coins to confirm whether the listing is successful!
if ( $ocmd == '2') { getOceanOneMarketInfos(ERC20_BENZ,USDT_ASSET_ID); }function getOceanOneMarketInfos($targetCoin, $baseCoin) {
$client = new GuzzleHttp\Client();
$baseUrl = "https://events.ocean.one/markets/".$targetCoin."-".$baseCoin."/book";
$res = $client->request('GET', $baseUrl, [
]);
if ($res->getStatusCode() == "200") {
// echo $res->getStatusCode() . PHP_EOL;
$resInfo = json_decode($res->getBody(), true);
echo "Side | Price | Amount | Funds" . PHP_EOL;
foreach ($resInfo["data"] ["data"] ["asks"] as $key => $exchange) {
echo $exchange["side"]."" . $exchange["price"]."" . $exchange["amount"]."" . $exchange["funds"] . PHP_EOL;
}
foreach ($resInfo["data"] ["data"] ["bids"] as $key => $exchange) {
echo $exchange["side"]."" . $exchange["price"]."" . $exchange["amount"]."" . $exchange["funds"] . PHP_EOL; }}}Copy the code
ERC20 related operation instructions
Commands list of this source code:
- trb:Transfer ERC20 from Bot to Wallet
- trm:Transfer ERC20 from Wallet to Master
- o: Ocean.One Exchange
Make your choose(eg: q for Exit!) :
- x: Orders-Book of ERC20/USDT
- x1: Buy ERC20 pay USDT
- x2: Sell ERC20 get USDT
- c: Cancel the order
- q: Exit
Complete code