Author Topic: api call error  (Read 2407 times)

0 Members and 1 Guest are viewing this topic.

Offline alt

  • Hero Member
  • *****
  • Posts: 2821
    • View Profile
  • BitShares: baozi
Here is another solution:

http://stackoverflow.com/questions/18936554/disable-scientific-notation-in-python-json-dumps-output
I have try this but failed,
please let me know if it can work, thanks.

来自我的 HUAWEI P7-L00 上的 Tapatalk



Offline alt

  • Hero Member
  • *****
  • Posts: 2821
    • View Profile
  • BitShares: baozi
The feed scripts use float() with %g to format the number .. maybe thats the issue ...

Have a sample code?

I think xeroc is correct, it looks like the exponent at the end of "1.2028997179833209e-05" might be causing the failure.
I don't know where it convert price  from type float to type string
from the output above, it's still float when I call requests.post()
Anyway encoded HTTP post data is a String. You have this in the data:
Code: [Select]
['ask_order', ['fund.btsbots', 11429.350384438114, 'BTS', 1.202899717
9833209e-05, 'GOLD']]

generated by
Code: [Select]
json.dumps(payload)
thank you,json.dumps  convert float to scientific notation,
I don't know how to change that,
so I have to replace scientific notation to fixed point with string replace.
here is the code to replace scientific notation to fixed point
Code: [Select]
import re
def to_fixed_point(match):
    """Return the fixed point form of the matched number.

    Parameters:
        match is a MatchObject that matches exp_regex or similar.

    If you wish to make match using your own regex, keep the following in mind:
        group 1 should be the coefficient
        group 3 should be the sign
        group 4 should be the exponent

    """
    sign = -1 if match.group(3) == "-" else 1
    coefficient = float(match.group(1))
    exponent = sign * float(match.group(4))
    return "%.16f" % (coefficient * 10**exponent)

class BTS():
.....
        exp_regex = re.compile(r"(\d+(\.\d+)?)[Ee](\+|-)(\d+)")
        response = requests.post(self.url, data=exp_regex.sub(to_fixed_point,json.dumps(payload)), headers=headers)
......

Offline abit

  • Committee member
  • Hero Member
  • *
  • Posts: 4664
    • View Profile
    • Abit's Hive Blog
  • BitShares: abit
  • GitHub: abitmore
The feed scripts use float() with %g to format the number .. maybe thats the issue ...

Have a sample code?

I think xeroc is correct, it looks like the exponent at the end of "1.2028997179833209e-05" might be causing the failure.
I don't know where it convert price  from type float to type string
from the output above, it's still float when I call requests.post()
Anyway encoded HTTP post data is a String. You have this in the data:
Code: [Select]
['ask_order', ['fund.btsbots', 11429.350384438114, 'BTS', 1.202899717
9833209e-05, 'GOLD']]

generated by
Code: [Select]
json.dumps(payload)
« Last Edit: January 09, 2015, 08:36:43 am by abit »
BitShares committee member: abit
BitShares witness: in.abit

Offline alt

  • Hero Member
  • *****
  • Posts: 2821
    • View Profile
  • BitShares: baozi
The feed scripts use float() with %g to format the number .. maybe thats the issue ...

Have a sample code?

I think xeroc is correct, it looks like the exponent at the end of "1.2028997179833209e-05" might be causing the failure.
I don't know where it convert price  from type float to type string
from the output above, it's still float when I call requests.post()

Offline vikram

The feed scripts use float() with %g to format the number .. maybe thats the issue ...

Have a sample code?

I think xeroc is correct, it looks like the exponent at the end of "1.2028997179833209e-05" might be causing the failure.

Offline alt

  • Hero Member
  • *****
  • Posts: 2821
    • View Profile
  • BitShares: baozi
this is the python code
Code: [Select]
    def request(self, method, *args):
        payload = {
            "method": method,
            "params": list(*args),
            "jsonrpc": "2.0",
            "id": 0,
        }
        headers = {
          'content-type': 'application/json',
          'Authorization': "Basic YTph"
        }
        response = requests.post(self.url, data=json.dumps(payload), headers=headers)
        return response
here is the output for print(list(*args)),and the type for price is double
Code: [Select]
[['03f052d0ed733c2326ca0026999525cbc43009a6', 'bbc8047182eb8d6a632d19a8849a21060a641b48', '06c600653b6dd28d23ae99ec2893887c2b388c88', 'd472fef4e17f3f5df812ebfa9f13234d5
aa44dfd', 'a45ad4cf7ecef2d07fce548d951a8c1083c425fc', 'ba239ae148638286a970aa56261d881b1a9c0086', '06f5ce2e019fc42122423fc998cdae0ba1fbd3d2', 'c7dbd100a6c8e5661939a29a0
0cb57ecc1302da5', 'bd708faa685ff4a69c2982c827381691afaa103f', '646b66a5d5e2a9f55bcc4af33d8ee6f22c0c7a61', 'efd72a3fd0c5edc2cadb23380a3c75798a5a1779', 'b53c5dabe9f6ec70a
d589f24a5d405736f09a6b0', 'c02a77833680603242beaaacdf836bee3c441ce8'], [['bid_order', ['fund.btsbots', 54130.18416381963, 'BTS', 0.08766984456010969, 'CNY']], ['ask_ord
er', ['fund.btsbots', 57146.75192219057, 'BTS', 0.08968609775813902, 'CNY']], ['bid_order', ['fund.btsbots', 226561.9201900809, 'BTS', 0.014206686512333885, 'USD']], ['
ask_order', ['fund.btsbots', 44464.34984026416, 'BTS', 0.015139738236806663, 'USD']], ['bid_order', ['fund.btsbots', 229579.10807175457, 'BTS', 0.9207852670294966, 'BTS
BOTS']], ['ask_order', ['fund.btsbots', 63449.95534834854, 'BTS', 0.9468123420229522, 'BTSBOTS']], ['ask_order', ['fund.btsbots', 11429.350384438114, 'BTS', 1.202899717
9833209e-05, 'GOLD']], ['bid_order', ['fund.btsbots', 20734.845623422014, 'BTS', 0.000873644149803378, 'SILVER']], ['ask_order', ['fund.btsbots', 6722.500212938591, 'BT
S', 0.0009074410160000001, 'SILVER']], ['ask_order', ['fund.btsbots', 8718.544540465993, 'BTS', 0.012189673113103268, 'EUR']], ['bid_order', ['fund.btsbots', 5048.55346
1016416, 'CNY', 10.46800147619338, 'BTSBOTS']], ['ask_order', ['fund.btsbots', 790.9308052753629, 'CNY', 10.584346022961434, 'BTSBOTS']], ['bid_order', ['fund.btsbots',
 635.4423479952087, 'USD', 62.05683755900157, 'BTSBOTS']], ['ask_order', ['fund.btsbots', 938.2919722265211, 'USD', 65.31628397641072, 'BTSBOTS']]], True]

Offline vikram

What is the input give to the RPC call?

Offline xeroc

  • Board Moderator
  • Hero Member
  • *****
  • Posts: 12922
  • ChainSquad GmbH
    • View Profile
    • ChainSquad GmbH
  • BitShares: xeroc
  • GitHub: xeroc
The feed scripts use float() with %g to format the number .. maybe thats the issue ...

Have a sample code?

Offline alt

  • Hero Member
  • *****
  • Posts: 2821
    • View Profile
  • BitShares: baozi
when I want to submit an ask order for GOLD/BTS at price 1.2028997179833209e-05 from python script,
api call returned error, here is the  message

Code: [Select]
{'error': {'code': 10,
           'detail': '10 assert_exception: Assert Exception\n'
                     'quote_asset_id > base_asset_id: 0 > 0\n'
                     '    {"quote":0,"base":0}\n'
                     '    th_a  asset.cpp:85 price\n'
                     '\n'
                     '    {}\n'
                     '    th_a  asset.cpp:86 price\n'
                     '\n'
                     '    '
                     '{"price_string":"1.2028997179833209e-05","base_symbol":"BTS","quote_symbol":"GOLD"}\n'
                     '    th_a  chain_interface.cpp:347 to_ugly_price\n'
                     '\n'
                     '    '
                     '{"cancel_order_ids":["03f052d0ed733c2326ca0026999525cbc43009a6","bbc8047182eb8d6a632d19a8849a21060a641b48","06c600653b6dd28d23ae99ec2893887c2b388c88","d472fef4e17f3f5df812ebfa9f13234d5aa44dfd","a45ad4cf7ecef2d07fce548d951a8c1083c425fc","ba239ae148638286a970aa56261d881b1a9c0086","06f5ce2e019fc42122423fc998cdae0ba1fbd3d2","c7dbd100a6c8e5661939a29a00cb57ecc1302da5","bd708faa685ff4a69c2982c827381691afaa103f","646b66a5d5e2a9f55bcc4af33d8ee6f22c0c7a61","efd72a3fd0c5edc2cadb23380a3c75798a5a1779","b53c5dabe9f6ec70ad589f24a5d405736f09a6b0","c02a77833680603242beaaacdf836bee3c441ce8"],"new_orders":[["bid_order",["fund.btsbots","54130.184163819627","BTS","0.087669844560","CNY"]],["ask_order",["fund.btsbots","57146.751922190568","BTS","0.089686097758","CNY"]],["bid_order",["fund.btsbots","226561.920190080913","BTS","0.014206686512","USD"]],["ask_order",["fund.btsbots","44464.349840264164","BTS","0.015139738237","USD"]],["bid_order",["fund.btsbots","229579.108071754570","BTS","0.920785267029","BTSBOTS"]],["ask_order",["fund.btsbots","63449.955348348543","BTS","0.946812342023","BTSBOTS"]],["ask_order",["fund.btsbots","11429.350384438114","BTS","1.2028997179833209e-05","GOLD"]],["bid_order",["fund.btsbots","20734.845623422014","BTS","0.000873644150","SILVER"]],["ask_order",["fund.btsbots","6722.500212938591","BTS","0.000907441016","SILVER"]],["ask_order",["fund.btsbots","8718.544540465993","BTS","0.012189673113","EUR"]],["bid_order",["fund.btsbots","5048.553461016416","CNY","10.468001476193","BTSBOTS"]],["ask_order",["fund.btsbots","790.930805275363","CNY","10.584346022961","BTSBOTS"]],["bid_order",["fund.btsbots","635.442347995209","USD","62.056837559002","BTSBOTS"]],["ask_order",["fund.btsbots","938.291972226521","USD","65.316283976411","BTSBOTS"]]]}\n'
                     '    th_a  wallet.cpp:3373 batch_market_update\n'
                     '\n'
                     '    {}\n'
                     '    th_a  common_api_client.cpp:5240 '
                     'wallet_market_batch_update',
           'message': 'Assert Exception (10)\n'
                      'quote_asset_id > base_asset_id: 0 > 0\n'
                      '\n'
                      '\n'
                      '\n'
                      '\n'},
 'id': 0}