-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbitcoin_wallet-ruby.rb
696 lines (685 loc) · 31.5 KB
/
bitcoin_wallet-ruby.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
require 'openssl'
require '../mixin_bot/lib/mixin_bot'
require 'yaml'
require 'csv'
require './utils'
require 'msgpack'
require 'base64'
require 'uuid'
require 'cgi'
WALLET_NAME = "./mybitcoin_wallet.csv"
DEFAULT_PIN = "123456"
EXIN_BOT = "61103d28-3ac2-44a2-ae34-bd956070dab1"
OCEANONE_BOT = "aaff5bef-42fb-4c9f-90e0-29f69176b7d4"
BTC_ASSET_ID = "c6d0c728-2624-429b-8e0d-d9d19b6592fa"
EOS_ASSET_ID = "6cfe566e-4aad-470b-8c9a-2fd35b49c68d"
USDT_ASSET_ID = "815b0b1a-2764-3736-8faa-42d694fa620a"
# private static final String ETC_ASSET_ID = "2204c1ee-0ea2-4add-bb9a-b3719cfff93a";
# private static final String XRP_ASSET_ID = "23dfb5a5-5d7b-48b6-905f-3970e3176e27";
# private static final String XEM_ASSET_ID = "27921032-f73e-434e-955f-43d55672ee31";
ETH_ASSET_ID = "43d61dcd-e413-450d-80b8-101d5e903357"
# private static final String DASH_ASSET_ID = "6472e7e3-75fd-48b6-b1dc-28d294ee1476";
# private static final String DOGE_ASSET_ID = "6770a1e5-6086-44d5-b60f-545f9d9e8ffd";
# private static final String LTC_ASSET_ID = "76c802a2-7c88-447f-a93e-c29c9e5dd9c8";
# private static final String SIA_ASSET_ID = "990c4c29-57e9-48f6-9819-7d986ea44985";
# private static final String ZEN_ASSET_ID = "a2c5d22b-62a2-4c13-b3f0-013290dbac60";
# private static final String ZEC_ASSET_ID = "c996abc9-d94e-4494-b1cf-2a3fd3ac5714";
# private static final String BCH_ASSET_ID = "fd11b6e3-0b87-41f1-a41f-f0e9b49e5bf0";
XIN_ASSET_ID = "c94ac88f-4671-3976-b60a-09064f1811e8"
CNB_ASSET_ID = "965e5c6e-434c-3fa9-b780-c50f43cd955c"
ERC20_BENZ = "2b9c216c-ef60-398d-a42a-eba1b298581d"
BTC_WALLET_ADDR = "14T129GTbXXPGXXvZzVaNLRFPeHXD1C25C"
USDT_WALLET_ADDR = "1PaXk8etFpWdxMJNmDuVh8kFts2HWGwhC3"
MASTER_UUID = "0b4f49dc-8fb4-4539-9a89-fb3afc613747"
# private static final String WALLET_FILANAME = "./mybitcoin_wallet.csv";
EOS_THIRD_EXCHANGE_NAME = "huobideposit"
EOS_THIRD_EXCHANGE_TAG = "1872050"
PromptMsg = "1: Create Bitcoin Wallet and update PIN\n2: Read Bitcoin balance & address \n3: Read USDT balance & address\n4: Read EOS balance & address\n" +
"tbb:Transfer BTC from Bot to Wallet\ntbm:Transfer BTC from Wallet to Master\n" +
"teb:Transfer EOS from Bot to Wallet\ntem:Transfer EOS from Wallet to Master\n" +
"tub:Transfer USDT from Bot to Wallet\ntum:Transfer USDT from Wallet to Master\n" +
"tcb:Transfer CNB from Bot to Wallet\ntcm:Transfer CNB from Wallet to Master\n" +
"txb:Transfer XIN from Bot to Wallet\ntxm:Transfer XIN from Wallet to Master\n" +
"tbb:Transfer ETH from Bot to Wallet\nttm:Transfer ETH from Wallet to Master\n" +
"trb:Transfer ERC20 from Bot to Wallet\ntrm:Transfer ERC20 from Wallet to Master\n" +
"5: Pay All BTC to ExinCore exchange USDT\n6: Pay All USDT to ExinCore buy BTC\n" +
"10: Pay all XIN to ExinCore exchange USDT\n" +
"11: Pay all ETH to ExinCore exchange USDT\n" +
"12: Pay all EOS to ExinCore exchange USDT\n" +
"7: Read Snapshots\n8: Fetch market price(USDT)\n9: Fetch market price(BTC)\n" +
"v: Verify Wallet Pin\nwb: Withdraw BTC\nwb: Withdraw USDT\nwe: WitchDraw EOS\nab: Read Bot Assets\naw: Read Wallet Assets\n" +
"o: OceanOne Exchange\n" +
"q: Exit \nMake your choose(eg: q for Exit!): "
yaml_hash = YAML.load_file('./config.yml')
bot_config = {
client_id: yaml_hash["MIXIN_CLIENT_ID"],
session_id: yaml_hash["MIXIN_SESSION_ID"],
client_secret: yaml_hash["MIXIN_CLIENT_SECRET"],
pin_token: yaml_hash["MIXIN_PIN_TOKEN"],
private_key: yaml_hash["MIXIN_PRIVATE_KEY"]
}
botAccount = MixinBot.new(bot_config)
if File.file?(WALLET_NAME)
table = CSV.read(WALLET_NAME)
wallet_config = {
client_id: table[0][3],
session_id: table[0][2],
client_secret: '',
pin_token: table[0][1],
private_key: table[0][0]
}
walletAccount = MixinBot.new(wallet_config)
wallet_userid = table[0][3]
end
loop do
puts "-------------------------------------------------------------------------"
puts PromptMsg
cmd = gets.chomp
if cmd == "1"
if File.file?(WALLET_NAME)
p "mybitcoin_wallet.csv has already existed !"
next
end
rsa_key = OpenSSL::PKey::RSA.new(1024)
private_key = rsa_key.to_pem()
p private_key
public_key = rsa_key.public_key.to_pem
secret_client = public_key.sub("-----BEGIN PUBLIC KEY-----\n","").sub("\n-----END PUBLIC KEY-----\n","")
reqInfo = botAccount.create_user("ruby bot",secret_client)
p reqInfo["data"]["pin_token"]
p reqInfo["data"]["user_id"]
p reqInfo["data"]["session_id"]
CSV.open(WALLET_NAME, "wb") do |csv|
csv << [private_key, reqInfo["data"]["pin_token"], reqInfo["data"]["session_id"], reqInfo["data"]["user_id"]]
end
if File.file?(WALLET_NAME)
table = CSV.read(WALLET_NAME)
wallet_config = {
client_id: table[0][3],
session_id: table[0][2],
client_secret: '',
pin_token: table[0][1],
private_key: table[0][0]
}
walletAccount = MixinBot.new(wallet_config)
wallet_userid = table[0][3]
pinInfo = walletAccount.update_pin('',DEFAULT_PIN)
p pinInfo
end
end
if cmd == "aw"
assetsInfo = walletAccount.read_assets()
p "--------The Wallet Assets List-----------------"
assetsInfo["data"].each { |x| puts x["symbol"] + " " +
x["balance"] + " " + x["public_key"] +
x["account_name"] + " " + x["account_tag"]}
p "----------End of Wallet Assets --------------"
end
if cmd == "ab"
assetsInfo = botAccount.read_assets()
p "--------The Bot Assets List-----------------"
assetsInfo["data"].each { |x| puts x["symbol"] + " " +
x["balance"] + " " + x["public_key"] +
x["account_name"] + " " + x["account_tag"]}
p "----------End of Bot Assets --------------"
# pinInfo = MixinBot.api.update_pin('',DEFAULT_PIN)
# p pinInfo
end
if cmd == "2"
assetsInfo = walletAccount.read_asset(BTC_ASSET_ID)
p "The BTC wallet address is " + assetsInfo["data"]["public_key"]
p "The BTC wallet balance is " + assetsInfo["data"]["balance"]
end
if cmd == "3"
assetsInfo = walletAccount.read_asset(BTC_ASSET_ID)
p "The EOS wallet address is " + assetsInfo["data"]["account_name"] + " " + assetsInfo["data"]["account_tag"]
p "The EOS wallet balance is " + assetsInfo["data"]["balance"]
end
if cmd == "wb"
addressInfo = walletAccount.create_withdraw_address(BTC_ASSET_ID,
DEFAULT_PIN,
BTC_WALLET_ADDR,
"","",
"from ruby")
p addressInfo
p "The address id is " + addressInfo["data"]["address_id"] + " it is needed by read fee!"
# addressInfo2 = MixinBot.api.del_withdraw_address(addressInfo["data"]["address_id"], DEFAULT_PIN)
# p addressInfo2
# withdrawInfo = walletAccount.withdrawals(addressInfo["data"]["address_id"],
# DEFAULT_PIN,
# "0.1",
# SecureRandom.uuid,"from ruby")
# p withdrawInfo
end
if cmd == "wu"
addressInfo = walletAccount.create_withdraw_address(USDT_ASSET_ID,
DEFAULT_PIN,
USDT_WALLET_ADDR,
"","",
"from ruby")
p addressInfo
p "The address id is " + addressInfo["data"]["address_id"] + " it is needed by read fee!"
# addressInfo2 = MixinBot.api.del_withdraw_address(addressInfo["data"]["address_id"], DEFAULT_PIN)
# p addressInfo2
# withdrawInfo = walletAccount.withdrawals(addressInfo["data"]["address_id"],
# DEFAULT_PIN,
# "0.1",
# SecureRandom.uuid,"from ruby")
# p withdrawInfo
end
if cmd == "we"
addressInfo = walletAccount.create_withdraw_address(EOS_ASSET_ID,
DEFAULT_PIN,
"",
EOS_THIRD_EXCHANGE_NAME,
EOS_THIRD_EXCHANGE_TAG,
"from ruby")
p addressInfo
p "The address id is " + addressInfo["data"]["address_id"] + " it is needed by read fee!"
# addressInfo2 = MixinBot.api.del_withdraw_address(addressInfo["data"]["address_id"], DEFAULT_PIN)
# p addressInfo2
withdrawInfo = walletAccount.withdrawals(addressInfo["data"]["address_id"],
DEFAULT_PIN,
"0.1",
SecureRandom.uuid,"from ruby")
p withdrawInfo
end
if cmd == "teb"
botAssetsInfo = botAccount.read_asset(EOS_ASSET_ID)
if botAssetsInfo["data"]["balance"].to_f > 0
transInfo = botAccount.create_transfer(botAccount.encrypt_pin(yaml_hash["MIXIN_PIN_CODE"]),
{
asset_id: EOS_ASSET_ID,
opponent_id: wallet_userid,
amount: botAssetsInfo["data"]["balance"],
trace_id: SecureRandom.uuid,
memo: "from ruby"
})
p transInfo
end
end
if cmd == "tcb"
botAssetsInfo = botAccount.read_asset(CNB_ASSET_ID)
if botAssetsInfo["data"]["balance"].to_f > 0
transInfo = botAccount.create_transfer(botAccount.encrypt_pin(yaml_hash["MIXIN_PIN_CODE"]),
{
asset_id: CNB_ASSET_ID,
opponent_id: wallet_userid,
amount: botAssetsInfo["data"]["balance"],
trace_id: SecureRandom.uuid,
memo: "from ruby"
})
p transInfo
end
end
if cmd == "tcm"
assetsInfo = walletAccount.read_asset(CNB_ASSET_ID)
if assetsInfo["data"]["balance"].to_f > 0
transInfo = walletAccount.create_transfer(walletAccount.encrypt_pin(DEFAULT_PIN),
{
asset_id: CNB_ASSET_ID,
opponent_id: MASTER_UUID,
amount: assetsInfo["data"]["balance"],
trace_id: SecureRandom.uuid,
memo: "from ruby"
})
p transInfo
end
end
if cmd == "txb"
botAssetsInfo = botAccount.read_asset(XIN_ASSET_ID)
if botAssetsInfo["data"]["balance"].to_f > 0
transInfo = botAccount.create_transfer(botAccount.encrypt_pin(yaml_hash["MIXIN_PIN_CODE"]),
{
asset_id: XIN_ASSET_ID,
opponent_id: wallet_userid,
amount: botAssetsInfo["data"]["balance"],
trace_id: SecureRandom.uuid,
memo: "from ruby"
})
p transInfo
end
end
if cmd == "txm"
assetsInfo = walletAccount.read_asset(XIN_ASSET_ID)
if assetsInfo["data"]["balance"].to_f > 0
transInfo = walletAccount.create_transfer(walletAccount.encrypt_pin(DEFAULT_PIN),
{
asset_id: XIN_ASSET_ID,
opponent_id: MASTER_UUID,
amount: assetsInfo["data"]["balance"],
trace_id: SecureRandom.uuid,
memo: "from ruby"
})
p transInfo
end
end
if cmd == "ttb"
botAssetsInfo = botAccount.read_asset(ETH_ASSET_ID)
if botAssetsInfo["data"]["balance"].to_f > 0
transInfo = botAccount.create_transfer(botAccount.encrypt_pin(yaml_hash["MIXIN_PIN_CODE"]),
{
asset_id: ETH_ASSET_ID,
opponent_id: wallet_userid,
amount: botAssetsInfo["data"]["balance"],
trace_id: SecureRandom.uuid,
memo: "from ruby"
})
p transInfo
end
end
if cmd == "ttm"
assetsInfo = walletAccount.read_asset(ETH_ASSET_ID)
if assetsInfo["data"]["balance"].to_f > 0
transInfo = walletAccount.create_transfer(walletAccount.encrypt_pin(DEFAULT_PIN),
{
asset_id: ETH_ASSET_ID,
opponent_id: MASTER_UUID,
amount: assetsInfo["data"]["balance"],
trace_id: SecureRandom.uuid,
memo: "from ruby"
})
p transInfo
end
end
if cmd == "tub"
botAssetsInfo = botAccount.read_asset(USDT_ASSET_ID)
if botAssetsInfo["data"]["balance"].to_f > 0
transInfo = botAccount.create_transfer(botAccount.encrypt_pin(yaml_hash["MIXIN_PIN_CODE"]),
{
asset_id: USDT_ASSET_ID,
opponent_id: wallet_userid,
amount: botAssetsInfo["data"]["balance"],
trace_id: SecureRandom.uuid,
memo: "from ruby"
})
p transInfo
end
end
if cmd == "tum"
assetsInfo = walletAccount.read_asset(USDT_ASSET_ID)
if assetsInfo["data"]["balance"].to_f > 0
transInfo = walletAccount.create_transfer(walletAccount.encrypt_pin(DEFAULT_PIN),
{
asset_id: USDT_ASSET_ID,
opponent_id: MASTER_UUID,
amount: assetsInfo["data"]["balance"],
trace_id: SecureRandom.uuid,
memo: "from ruby"
})
p transInfo
end
end
if cmd == "tbb"
botAssetsInfo = botAccount.read_asset(BTC_ASSET_ID)
if botAssetsInfo["data"]["balance"].to_f > 0
transInfo = botAccount.create_transfer(botAccount.encrypt_pin(yaml_hash["MIXIN_PIN_CODE"]),
{
asset_id: BTC_ASSET_ID,
opponent_id: wallet_userid,
amount: botAssetsInfo["data"]["balance"],
trace_id: SecureRandom.uuid,
memo: "from ruby"
})
p transInfo
end
end
if cmd == "tbm"
assetsInfo = walletAccount.read_asset(BTC_ASSET_ID)
if assetsInfo["data"]["balance"].to_f > 0
transInfo = walletAccount.create_transfer(walletAccount.encrypt_pin(DEFAULT_PIN),
{
asset_id: BTC_ASSET_ID,
opponent_id: MASTER_UUID,
amount: assetsInfo["data"]["balance"],
trace_id: SecureRandom.uuid,
memo: "from ruby"
})
p transInfo
end
end
if cmd == "trb"
botAssetsInfo = botAccount.read_asset(ERC20_BENZ)
if botAssetsInfo["data"]["balance"].to_f > 0
transInfo = botAccount.create_transfer(botAccount.encrypt_pin(yaml_hash["MIXIN_PIN_CODE"]),
{
asset_id: ERC20_BENZ,
opponent_id: wallet_userid,
amount: botAssetsInfo["data"]["balance"],
trace_id: SecureRandom.uuid,
memo: "from ruby"
})
p transInfo
end
end
if cmd == "trm"
assetsInfo = walletAccount.read_asset(ERC20_BENZ)
if assetsInfo["data"]["balance"].to_f > 0
transInfo = walletAccount.create_transfer(walletAccount.encrypt_pin(DEFAULT_PIN),
{
asset_id: ERC20_BENZ,
opponent_id: MASTER_UUID,
amount: assetsInfo["data"]["balance"],
trace_id: SecureRandom.uuid,
memo: "from ruby"
})
p transInfo
end
end
if cmd == "8"
Utils.ExinCoreMarketPriceRequest(USDT_ASSET_ID)
end
if cmd == "9"
Utils.ExinCoreMarketPriceRequest(BTC_ASSET_ID)
end
if cmd == "5"
memo1 = Base64.encode64(MessagePack.pack({
'A' => UUID.parse(USDT_ASSET_ID).to_raw
}))
memo = memo1.sub("\n","")
p memo
assetsInfo = walletAccount.read_asset(BTC_ASSET_ID)
if assetsInfo["data"]["balance"].to_f > 0
transInfo = walletAccount.create_transfer(walletAccount.encrypt_pin(DEFAULT_PIN),
{
asset_id: BTC_ASSET_ID,
opponent_id: EXIN_BOT,
amount: assetsInfo["data"]["balance"],
trace_id: SecureRandom.uuid,
memo: memo
})
p transInfo
end
end
if cmd == "10"
memo1 = Base64.encode64(MessagePack.pack({
'A' => UUID.parse(USDT_ASSET_ID).to_raw
}))
memo = memo1.sub("\n","")
p memo
assetsInfo = walletAccount.read_asset(XIN_ASSET_ID)
if assetsInfo["data"]["balance"].to_f > 0
transInfo = walletAccount.create_transfer(walletAccount.encrypt_pin(DEFAULT_PIN),
{
asset_id: XIN_ASSET_ID,
opponent_id: EXIN_BOT,
amount: assetsInfo["data"]["balance"],
trace_id: SecureRandom.uuid,
memo: memo
})
p transInfo
end
end
if cmd == "11"
memo1 = Base64.encode64(MessagePack.pack({
'A' => UUID.parse(USDT_ASSET_ID).to_raw
}))
memo = memo1.sub("\n","")
p memo
assetsInfo = walletAccount.read_asset(ETH_ASSET_ID)
if assetsInfo["data"]["balance"].to_f > 0
transInfo = walletAccount.create_transfer(walletAccount.encrypt_pin(DEFAULT_PIN),
{
asset_id: ETH_ASSET_ID,
opponent_id: EXIN_BOT,
amount: assetsInfo["data"]["balance"],
trace_id: SecureRandom.uuid,
memo: memo
})
p transInfo
end
end
if cmd == "12"
memo1 = Base64.encode64(MessagePack.pack({
'A' => UUID.parse(USDT_ASSET_ID).to_raw
}))
memo = memo1.sub("\n","")
p memo
assetsInfo = walletAccount.read_asset(EOS_ASSET_ID)
if assetsInfo["data"]["balance"].to_f > 0
transInfo = walletAccount.create_transfer(walletAccount.encrypt_pin(DEFAULT_PIN),
{
asset_id: EOS_ASSET_ID,
opponent_id: EXIN_BOT,
amount: assetsInfo["data"]["balance"],
trace_id: SecureRandom.uuid,
memo: memo
})
p transInfo
end
end
if cmd == "6"
memo1 = Base64.encode64(MessagePack.pack({
'A' => UUID.parse(BTC_ASSET_ID).to_raw
}))
memo = memo1.sub("\n","")
p memo
assetsInfo = walletAccount.read_asset(USDT_ASSET_ID)
if assetsInfo["data"]["balance"].to_f > 0
transInfo = walletAccount.create_transfer(walletAccount.encrypt_pin(DEFAULT_PIN),
{
asset_id: USDT_ASSET_ID,
opponent_id: EXIN_BOT,
amount: assetsInfo["data"]["balance"],
trace_id: SecureRandom.uuid,
memo: memo
})
p transInfo
end
end
if cmd == "7"
if wallet_userid == "5e4ad097-21e8-3f6b-98f7-9dc74dd99f77"
dt = "2019-05-23T09:48:04.582099Z"
else
puts "Input the snapshots datetime: "
dt = gets.chomp
end
p CGI.escape(dt)
snaps = walletAccount.read_snapshots({
limit: "10",
offset: CGI.escape(dt),
asset: BTC_ASSET_ID,
order: "ASC"
})
snaps["data"].each { |x|
if x["amount"].to_f > 0
if x["data"] != nil
uData = MessagePack.unpack(Base64.decode64(x["data"]))
p uData
p "The code is " + uData["C"].to_s + " Price is " + uData["P"] + " Fee is " +
uData["F"]
p "Fee is Asset UUID is " + UUID.parse(uData["FA"]).to_s
p "Order id is " + UUID.parse(uData["O"]).to_s
end
end
}
end
if cmd == "o"
loop do
oMsg = "1: Fetch BTC/USDT Order Book\n2: Fetch XIN/USDT Order Book\n" +
"3: Fetch ERC20/USDT Order Book\n" +
"s1: Sell BTC/USDT\n" + "b1: Buy BTC/USDT\n" +
"s2: Sell XIN/USDT\n" + "b2: Buy XIN/USDT\n" +
"s3: Sell ERC20/USDT\n" + "s3: Buy ERC20/USDT\n" +
"c: Cancel the order\n" +
"q: Exit \nMake your choose(eg: q for Exit!): "
puts oMsg
ocmd = gets.chomp
if ocmd == "q"
break
end
if ocmd == "1"
Utils.OceanOneMarketPriceRequest(BTC_ASSET_ID, USDT_ASSET_ID)
end
if ocmd == "2"
Utils.OceanOneMarketPriceRequest(XIN_ASSET_ID, USDT_ASSET_ID)
end
if ocmd == "3"
Utils.OceanOneMarketPriceRequest(ERC20_BENZ, USDT_ASSET_ID)
end
if ocmd == "s1"
p "Input the price of BTC/USDT: "
bprice = gets.chomp
p "Input the amount of BTC: "
amount = gets.chomp
memo = Utils.GenerateOceanMemo(USDT_ASSET_ID,"A",bprice)
p memo
assetsInfo = walletAccount.read_asset(BTC_ASSET_ID)
if assetsInfo["data"]["balance"].to_f > 0 && assetsInfo["data"]["balance"].to_f >= amount.to_f
transInfo = walletAccount.create_transfer(walletAccount.encrypt_pin(DEFAULT_PIN),
{
asset_id: BTC_ASSET_ID,
opponent_id: OCEANONE_BOT,
amount: amount,
trace_id: SecureRandom.uuid,
memo: memo
})
p transInfo
p "The Order id is " + transInfo["data"]["trace_id"] + " It's needed by cancel-order!"
else
p "Not enough BTC"
end
end
if ocmd == "b1"
p "Input the price of BTC/USDT: "
bprice = gets.chomp
p "Input the amount of USDT: "
amount = gets.chomp
memo = Utils.GenerateOceanMemo(BTC_ASSET_ID,"B",bprice)
p memo
assetsInfo = walletAccount.read_asset(USDT_ASSET_ID)
if assetsInfo["data"]["balance"].to_f >= 1 && assetsInfo["data"]["balance"].to_f >= amount.to_f
transInfo = walletAccount.create_transfer(walletAccount.encrypt_pin(DEFAULT_PIN),
{
asset_id: USDT_ASSET_ID,
opponent_id: OCEANONE_BOT,
amount: amount,
trace_id: SecureRandom.uuid,
memo: memo
})
p transInfo
p "The Order id is " + transInfo["data"]["trace_id"] + " It's needed by cancel-order!"
else
p "Not enough USDT"
end
end
if ocmd == "s2"
p "Input the price of XIN/USDT: "
bprice = gets.chomp
p "Input the amount of XIN: "
amount = gets.chomp
memo = Utils.GenerateOceanMemo(USDT_ASSET_ID,"A",bprice)
p memo
assetsInfo = walletAccount.read_asset(XIN_ASSET_ID)
if assetsInfo["data"]["balance"].to_f > 0 && assetsInfo["data"]["balance"].to_f >= amount.to_f
transInfo = walletAccount.create_transfer(walletAccount.encrypt_pin(DEFAULT_PIN),
{
asset_id: XIN_ASSET_ID,
opponent_id: OCEANONE_BOT,
amount: amount,
trace_id: SecureRandom.uuid,
memo: memo
})
p transInfo
p "The Order id is " + transInfo["data"]["trace_id"] + " It's needed by cancel-order!"
else
p "Not enough XIN"
end
end
if ocmd == "b2"
p "Input the price of XIN/USDT: "
bprice = gets.chomp
p "Input the amount of USDT: "
amount = gets.chomp
memo = Utils.GenerateOceanMemo(XIN_ASSET_ID,"B",bprice)
p memo
assetsInfo = walletAccount.read_asset(USDT_ASSET_ID)
if assetsInfo["data"]["balance"].to_f >= 1 && assetsInfo["data"]["balance"].to_f >= amount.to_f
transInfo = walletAccount.create_transfer(walletAccount.encrypt_pin(DEFAULT_PIN),
{
asset_id: USDT_ASSET_ID,
opponent_id: OCEANONE_BOT,
amount: amount,
trace_id: SecureRandom.uuid,
memo: memo
})
p transInfo
p "The Order id is " + transInfo["data"]["trace_id"] + " It's needed by cancel-order!"
else
p "Not enough USDT"
end
end
if ocmd == "s3"
p "Input the price of ERC/USDT: "
bprice = gets.chomp
p "Input the amount of ERC20_BENZ: "
amount = gets.chomp
memo = Utils.GenerateOceanMemo(USDT_ASSET_ID,"A",bprice)
p memo
assetsInfo = walletAccount.read_asset(ERC20_BENZ)
if assetsInfo["data"]["balance"].to_f > 0 && assetsInfo["data"]["balance"].to_f >= amount.to_f
transInfo = walletAccount.create_transfer(walletAccount.encrypt_pin(DEFAULT_PIN),
{
asset_id: ERC20_BENZ,
opponent_id: OCEANONE_BOT,
amount: amount,
trace_id: SecureRandom.uuid,
memo: memo
})
p transInfo
p "The Order id is " + transInfo["data"]["trace_id"] + " It's needed by cancel-order!"
else
p "Not enough ERC20_BENZ"
end
end
if ocmd == "b3"
p "Input the price of ERC20/USDT: "
bprice = gets.chomp
p "Input the amount of USDT: "
amount = gets.chomp
memo = Utils.GenerateOceanMemo(ERC20_BENZ,"B",bprice)
p memo
assetsInfo = walletAccount.read_asset(USDT_ASSET_ID)
if assetsInfo["data"]["balance"].to_f >= 1 && assetsInfo["data"]["balance"].to_f >= amount.to_f
transInfo = walletAccount.create_transfer(walletAccount.encrypt_pin(DEFAULT_PIN),
{
asset_id: USDT_ASSET_ID,
opponent_id: OCEANONE_BOT,
amount: amount,
trace_id: SecureRandom.uuid,
memo: memo
})
p transInfo
p "The Order id is " + transInfo["data"]["trace_id"] + " It's needed by cancel-order!"
else
p "Not enough USDT"
end
end
if ocmd == "c"
p "Input the Order ID: "
orderid = gets.chomp
memo1 = Base64.encode64(MessagePack.pack({
'O' => UUID.parse(orderid).to_raw
}))
memo = memo1.sub("\n","")
assetsInfo = walletAccount.read_asset(CNB_ASSET_ID)
if assetsInfo["data"]["balance"].to_f > 0
transInfo = walletAccount.create_transfer(walletAccount.encrypt_pin(DEFAULT_PIN),
{
asset_id: CNB_ASSET_ID,
opponent_id: OCEANONE_BOT,
amount: "0.00000001",
trace_id: SecureRandom.uuid,
memo: memo
})
p transInfo
else
p "Not enough CNB!"
end
end
end
end
if cmd == "q"
break
end
end