Module: TridentAssistant::API::Order
- Included in:
- TridentAssistant::API
- Defined in:
- lib/trident_assistant/api/order.rb
Overview
api for order
Constant Summary collapse
- EXCHANGE_ASSET_ID =
"965e5c6e-434c-3fa9-b780-c50f43cd955c"
- MINIMUM_AMOUNT =
0.000_000_01
Instance Method Summary collapse
- #ask_order(collection, token, **kwargs) ⇒ Object
- #auction_order(collection, token, **kwargs) ⇒ Object
- #bid_order(collection, token, **kwargs) ⇒ Object
- #cancel_order(order_id) ⇒ Object
- #fill_order(order_id) ⇒ Object
- #order(id) ⇒ Object
- #orders(**kwargs) ⇒ Object
Instance Method Details
#ask_order(collection, token, **kwargs) ⇒ Object
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 |
# File 'lib/trident_assistant/api/order.rb', line 39 def ask_order(collection, token, **kwargs) raise ArgumentError, "price cannot be blank" if kwargs[:price].blank? raise ArgumentError, "asset_id cannot be blank" if kwargs[:asset_id].blank? trace_id = SecureRandom.uuid token_id = MixinBot::Utils::Nfo.new(collection: collection, token: token).unique_token_id memo = TridentAssistant::Utils::Memo .new( type: "A", order_id: trace_id, token_id: token_id, price: kwargs[:price], asset_id: kwargs[:asset_id], expire_at: kwargs[:expire_at] ) mixin_bot.create_multisig_transaction( keystore[:pin], asset_id: EXCHANGE_ASSET_ID, trace_id: trace_id, amount: MINIMUM_AMOUNT, memo: memo.encode, receivers: TridentAssistant::Utils::TRIDENT_MTG[:members], threshold: TridentAssistant::Utils::TRIDENT_MTG[:threshold] ) end |
#auction_order(collection, token, **kwargs) ⇒ Object
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 |
# File 'lib/trident_assistant/api/order.rb', line 67 def auction_order(collection, token, **kwargs) raise ArgumentError, "price cannot be blank" if kwargs[:price].blank? raise ArgumentError, "asset_id cannot be blank" if kwargs[:asset_id].blank? trace_id = SecureRandom.uuid token_id = MixinBot::Utils::Nfo.new(collection: collection, token: token).unique_token_id memo = TridentAssistant::Utils::Memo .new( type: "AU", order_id: trace_id, token_id: token_id, price: kwargs[:price], reserve_price: kwargs[:reserve_price], asset_id: kwargs[:asset_id], expire_at: kwargs[:expire_at] ) mixin_bot.create_multisig_transaction( keystore[:pin], asset_id: EXCHANGE_ASSET_ID, trace_id: trace_id, amount: MINIMUM_AMOUNT, memo: memo.encode, receivers: TridentAssistant::Utils::TRIDENT_MTG[:members], threshold: TridentAssistant::Utils::TRIDENT_MTG[:threshold] ) end |
#bid_order(collection, token, **kwargs) ⇒ Object
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 |
# File 'lib/trident_assistant/api/order.rb', line 96 def bid_order(collection, token, **kwargs) raise ArgumentError, "price cannot be blank" if kwargs[:price].blank? raise ArgumentError, "asset_id cannot be blank" if kwargs[:asset_id].blank? trace_id = SecureRandom.uuid token_id = MixinBot::Utils::Nfo.new(collection: collection, token: token).unique_token_id memo = TridentAssistant::Utils::Memo .new( type: "B", order_id: trace_id, token_id: token_id, asset_id: kwargs[:asset_id], expire_at: kwargs[:expire_at] ) mixin_bot.create_multisig_transaction( keystore[:pin], asset_id: kwargs[:asset_id], trace_id: trace_id, amount: kwargs[:price], memo: memo.encode, receivers: TridentAssistant::Utils::TRIDENT_MTG[:members], threshold: TridentAssistant::Utils::TRIDENT_MTG[:threshold] ) end |
#cancel_order(order_id) ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/trident_assistant/api/order.rb', line 141 def cancel_order(order_id) info = order order_id raise ForbiddenError, "Order maker: #{info["maker"]["id"]}" if info.dig("maker", "id") != mixin_bot.app_id raise ForbiddenError, "Order state: #{info["state"]}" if info["state"] != "open" memo = TridentAssistant::Utils::Memo.new(type: "C", order_id: order_id, token_id: info["token_id"]) trace_id = SecureRandom.uuid mixin_bot.create_multisig_transaction( keystore[:pin], asset_id: EXCHANGE_ASSET_ID, trace_id: trace_id, amount: MINIMUM_AMOUNT, memo: memo.encode, receivers: TridentAssistant::Utils::TRIDENT_MTG[:members], threshold: TridentAssistant::Utils::TRIDENT_MTG[:threshold] ) end |
#fill_order(order_id) ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/trident_assistant/api/order.rb', line 123 def fill_order(order_id) info = order order_id raise ForbiddenError, "Order state: #{info["state"]}" if info["state"] != "open" memo = TridentAssistant::Utils::Memo.new(type: "F", order_id: order_id, token_id: info["token_id"]) trace_id = SecureRandom.uuid mixin_bot.create_multisig_transaction( keystore[:pin], asset_id: info["type"] == "BidOrder" ? EXCHANGE_ASSET_ID : info["asset_id"], trace_id: trace_id, amount: info["type"] == "BidOrder" ? MINIMUM_AMOUNT : info["price"], memo: memo.encode, receivers: TridentAssistant::Utils::TRIDENT_MTG[:members], threshold: TridentAssistant::Utils::TRIDENT_MTG[:threshold] ) end |
#order(id) ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/trident_assistant/api/order.rb', line 28 def order(id) client .get( "api/orders/#{id}", nil, { Authorization: "Bearer #{mixin_bot.access_token("GET", "/me", "")}" } ) end |
#orders(**kwargs) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/trident_assistant/api/order.rb', line 10 def orders(**kwargs) = mixin_bot ? mixin_bot.access_token("GET", "/me", "") : "" client.get( "api/orders", { collection_id: kwargs[:collection_id], metahash: kwargs[:metahash], state: kwargs[:state], type: kwargs[:type], maker_id: kwargs[:maker_id], page: kwargs[:page] }, { Authorization: "Bearer #{}" } ) end |