7
7
use Ratchet \RFC6455 \Messaging \Frame ;
8
8
use MessagePack \MessagePack ;
9
9
10
- const EXIN_BOT = "61103d28-3ac2-44a2-ae34-bd956070dab1 " ;
11
-
10
+ const EXIN_BOT = "61103d28-3ac2-44a2-ae34-bd956070dab1 " ;
11
+ const MASTER_UUID = "0b4f49dc-8fb4-4539-9a89-fb3afc613747 " ;
12
+ const BTC_ASSET_ID = "c6d0c728-2624-429b-8e0d-d9d19b6592fa " ;
13
+ const EOS_ASSET_ID = "6cfe566e-4aad-470b-8c9a-2fd35b49c68d " ;
14
+ const USDT_ASSET_ID = "815b0b1a-2764-3736-8faa-42d694fa620a " ;
12
15
$ loop = \React \EventLoop \Factory::create ();
13
16
$ reactConnector = new \React \Socket \Connector ($ loop , [
14
17
'timeout ' => 15
@@ -54,22 +57,19 @@ public function __construct()
54
57
$ msgData = sendAppButtons ($ jsMsg );
55
58
$ msg = new Frame (gzencode (json_encode ($ msgData )),true ,Frame::OP_BINARY );
56
59
$ conn ->send ($ msg );
57
- }//end of pay1
58
-
59
- elseif ($ isCmd === '2 ' ) {
60
+ } elseif ($ isCmd === '2 ' ) {
60
61
// print($callTrait->config['client_id']);
61
62
$ msgData = sendAppCard ($ jsMsg );
62
63
$ msg = new Frame (gzencode (json_encode ($ msgData )),true ,Frame::OP_BINARY );
63
64
$ conn ->send ($ msg );
64
- }//end of pay2
65
- elseif ($ isCmd === '3 ' ) {
66
- $ marketInfo = getExchangeCoins ("c6d0c728-2624-429b-8e0d-d9d19b6592fa " );
65
+ } elseif ($ isCmd === '3 ' ) {
66
+ $ marketInfo = getExchangeCoins (BTC_ASSET_ID );
67
67
echo $ marketInfo ;
68
68
$ msgData = sendPlainText ($ jsMsg ->data ->conversation_id , $ marketInfo );
69
69
$ msg = new Frame (gzencode (json_encode ($ msgData )),true ,Frame::OP_BINARY );
70
70
$ conn ->send ($ msg );
71
71
} elseif ($ isCmd === '4 ' ) {
72
- $ marketInfo = getExchangeCoins (" 815b0b1a-2764-3736-8faa-42d694fa620a " );
72
+ $ marketInfo = getExchangeCoins (USDT_ASSET_ID );
73
73
echo $ marketInfo ;
74
74
$ msgData = sendPlainText ($ jsMsg ->data ->conversation_id , $ marketInfo );
75
75
$ msg = new Frame (gzencode (json_encode ($ msgData )),true ,Frame::OP_BINARY );
@@ -78,6 +78,14 @@ public function __construct()
78
78
$ msgData = sendAppCardBuyUSDTSellBTC ($ jsMsg );
79
79
$ msg = new Frame (gzencode (json_encode ($ msgData )),true ,Frame::OP_BINARY );
80
80
$ conn ->send ($ msg );
81
+ } elseif ($ isCmd === '7 ' ) {
82
+ coinExchange (BTC_ASSET_ID ,"0.0001 " ,USDT_ASSET_ID );
83
+ } elseif ($ isCmd === '8 ' ) {
84
+ $ mixinSdk = new MixinSDK (require './config.php ' );
85
+ $ asset_info = $ mixinSdk ->Wallet ()->readAsset (BTC_ASSET_ID );
86
+ print_r ("Bitcoin wallet balance is : " .$ asset_info ["balance " ]."\n" );
87
+ $ asset_info = $ mixinSdk ->Wallet ()->readAsset (USDT_ASSET_ID );
88
+ print_r ("USDT wallet balance is : " .$ asset_info ["balance " ]."\n" );
81
89
} else {
82
90
$ msgData = sendPlainText ($ jsMsg ->data ->conversation_id ,
83
91
base64_decode ($ jsMsg ->data ->data ));
@@ -87,12 +95,17 @@ public function __construct()
87
95
} //end of PLAIN_TEXT
88
96
if ($ jsMsg ->data ->category === 'SYSTEM_ACCOUNT_SNAPSHOT ' ) {
89
97
// refundInstant
90
- echo "user id: " .$ jsMsg ->data ->user_id ;
98
+ echo "user id: " .$ jsMsg ->data ->user_id . PHP_EOL ;
91
99
$ dtPay = json_decode (base64_decode ($ jsMsg ->data ->data ));
92
- // print_r($dtPay);
93
100
if ($ dtPay ->amount > 0 ) {
94
- echo "paid! " .$ dtPay ->asset_id ;
95
- refundInstant ($ dtPay ->asset_id ,$ dtPay ->amount ,$ jsMsg ->data ->user_id );
101
+ echo "paid! " .$ dtPay ->asset_id . PHP_EOL ;
102
+ if ( $ dtPay ->opponent_id == MASTER_UUID ) {
103
+ // refundInstant($dtPay->asset_id,$dtPay->amount,$jsMsg->data->user_id);
104
+ } else {
105
+ echo "------------MEMO:-coin--exchange-------------- " ;
106
+ // print_r($dtPay->memo);
107
+ print_r (base64_decode ($ dtPay ->memo ));
108
+ }
96
109
}
97
110
} //end of SYSTEM_ACCOUNT_SNAPSHOT
98
111
} //end of CREATE_MESSAGE
@@ -130,6 +143,7 @@ function sendUsage($conversation_id):Array {
130
143
3x : Buy USDT sell BTC \n
131
144
4x : Buy BTC sell USDT \n
132
145
6 : Buy USDT sell BTC Directly \n
146
+ 7 : Bot 0.0001 BTC exchange \n
133
147
EOF ;
134
148
return sendPlainText ($ conversation_id ,$ msgHelp );
135
149
}
@@ -271,6 +285,17 @@ function refundInstant($_assetID,$_amount,$_opponent_id) {
271
285
print_r ($ BotInfo );
272
286
}
273
287
288
+ function coinExchange ($ _assetID ,$ _amount ,$ _targetAssetID ) {
289
+ $ mixinSdk = new MixinSDK (require './config.php ' );
290
+ // print_r();
291
+ $ memo = base64_encode (MessagePack::pack ([
292
+ 'A ' => Uuid::fromString ($ _targetAssetID )->getBytes (),
293
+ ]));
294
+ $ BotInfo = $ mixinSdk ->Wallet ()->transfer ($ _assetID ,EXIN_BOT ,
295
+ $ mixinSdk ->getConfig ()['default ' ]['pin ' ],$ _amount ,$ memo );
296
+ print_r ($ BotInfo );
297
+ }
298
+
274
299
function getExchangeCoins ($ base_coin ) :string {
275
300
$ client = new GuzzleHttp \Client ();
276
301
$ res = $ client ->request ('GET ' , 'https://exinone.com/exincore/markets?base_asset= ' .$ base_coin , [
0 commit comments