Bitcoin Forum
December 16, 2017, 04:19:32 AM *
News: Latest stable version of Bitcoin Core: 0.15.1  [Torrent].
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: traidor.py - command-driven text-mode trading client (mtgox)  (Read 2249 times)
molecular
Donator
Legendary
*
Offline Offline

Activity: 2436



View Profile
July 02, 2011, 08:56:34 PM
 #1

I made a simple trading client for the mtgox trading api a while back: https://github.com/molecular/traidor

I gave it an overhaul and I thought I'd share it, maybe someone likes it. Features:

  • display market depth and recent trades
  • display mtgox balances (BTC, USD)
  • manage own orders (view, buy, sell, cancel)



To get started, first checkout the code:

Quote
#> git clone git://github.com/molecular/traidor.git
#> cd traidor

then prepare config-file and start traidor:

Quote
#> cp traidor.conf.sample traidor.conf
#> edit traidor.conf
#> python traidor.py

The most important commands:
Quote
-----------command-----------------------action------------
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
atoggle auto-update on/off
b <amount> <price>enter order to buy <amount> btc at <price>
s <amount> <price>enter order to sell <amount> btc at <price>
oview your order book
d <index>delete order at <index> from orderbook

Note: you must use a decimal point (".") when entering the <price> of an order. If you dont, <price> is interpreted as an index in the depth table (1st column "[IDX]") and the order is placed just above/below the price at that index.

If you use and like it, consider a small donation to 1Ct1vCN6idU1hKrRcmR96G4NgAgrswPiCn


PGP key molecular F9B70769 fingerprint 9CDD C0D3 20F8 279F 6BE0  3F39 FC49 2362 F9B7 0769
1513397972
Hero Member
*
Offline Offline

Posts: 1513397972

View Profile Personal Message (Offline)

Ignore
1513397972
Reply with quote  #2

1513397972
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1513397972
Hero Member
*
Offline Offline

Posts: 1513397972

View Profile Personal Message (Offline)

Ignore
1513397972
Reply with quote  #2

1513397972
Report to moderator
molecular
Donator
Legendary
*
Offline Offline

Activity: 2436



View Profile
August 08, 2011, 08:23:03 AM
 #2

during the last weeks I made quite a few improvements to traidor:

  • use websocket implementation made by Giel (more stable)
  • avoid queue-up of websocket messages by using asynchronous display thread
  • be able to set market depth display precision (key "p")
  • many small bugfixes
  • improve connection trouble handling (catch exceptions, retry)

Any suggestions or bug reports always welcome.

PGP key molecular F9B70769 fingerprint 9CDD C0D3 20F8 279F 6BE0  3F39 FC49 2362 F9B7 0769
GamblingPurveyor
Member
**
Offline Offline

Activity: 75



View Profile
August 09, 2011, 06:04:54 PM
 #3

Storing the password in traidor.conf is insecure. An alternative is needed. Perhaps the password could be read from the TTY if the user doesn't provide it in traidor.conf.


Also, the program should check the $LINES and $COLUMNS environment variables every time it updates the screen, instead of having to set it manually with the d menu option.
molecular
Donator
Legendary
*
Offline Offline

Activity: 2436



View Profile
August 09, 2011, 08:31:26 PM
 #4

Storing the password in traidor.conf is insecure. An alternative is needed. Perhaps the password could be read from the TTY if the user doesn't provide it in traidor.conf.

True. I will switch to using api-key, like goxsh does, with encrypted secret. Password authentication will be switched off for the api at some point anyhow. Your suggestion is a good way to deal with it in the meantime. If I get around, I'll implement that.

Also, the program should check the $LINES and $COLUMNS environment variables every time it updates the screen, instead of having to set it manually with the d menu option.

That's a good suggestion. Will probably implement that.

Thanks for your feedback!


PGP key molecular F9B70769 fingerprint 9CDD C0D3 20F8 279F 6BE0  3F39 FC49 2362 F9B7 0769
ffuentes
Member
**
Offline Offline

Activity: 70


Only a curious passer-by / FirstBits: 13zsc1


View Profile WWW
August 09, 2011, 08:42:42 PM
 #5

I hope this script don't betray me!

Listen Radio Libre (Electronica) Donate. (click for details).

Chilean peso VS BTC ahora: http://irage.ca/2btc.php?a=1&c=CLP&r=1

My bitcoin address
GamblingPurveyor
Member
**
Offline Offline

Activity: 75



View Profile
August 09, 2011, 09:07:17 PM
 #6

WTF? I just noticed that this program uses the sound card to make strange "ticking" noises.
molecular
Donator
Legendary
*
Offline Offline

Activity: 2436



View Profile
August 09, 2011, 10:24:02 PM
 #7

I hope this script don't betray me!

The source code is right there to check. I'm sure if I inserted malicious code, it'd be reported here quite quickly.

PGP key molecular F9B70769 fingerprint 9CDD C0D3 20F8 279F 6BE0  3F39 FC49 2362 F9B7 0769
molecular
Donator
Legendary
*
Offline Offline

Activity: 2436



View Profile
August 10, 2011, 09:24:42 AM
 #8

WTF? I just noticed that this program uses the sound card to make strange "ticking" noises.

Yeah, that's the "ClickBot". I should probably make that optional or start it by command.

btw, you can also set an alarm using the TriggerBot:

Quote
mtgox | x BTC | y USD #> tb >= 12.5 ps alarm.wav

PGP key molecular F9B70769 fingerprint 9CDD C0D3 20F8 279F 6BE0  3F39 FC49 2362 F9B7 0769
molecular
Donator
Legendary
*
Offline Offline

Activity: 2436



View Profile
August 10, 2011, 09:25:36 AM
 #9

Storing the password in traidor.conf is insecure. An alternative is needed. Perhaps the password could be read from the TTY if the user doesn't provide it in traidor.conf.


Also, the program should check the $LINES and $COLUMNS environment variables every time it updates the screen, instead of having to set it manually with the d menu option.


Hmm, I tried reading $LINES from os.environ, it's not in there. while "echo $LINES" in bash works, "env | grep LINES" doesn't show it either.

Any hint for me?

PGP key molecular F9B70769 fingerprint 9CDD C0D3 20F8 279F 6BE0  3F39 FC49 2362 F9B7 0769
GamblingPurveyor
Member
**
Offline Offline

Activity: 75



View Profile
August 10, 2011, 11:27:02 PM
 #10

After leaving this program running for 6-8 hours, I found this:

Code:
mtgox | 0 BTC | 0.00458 USD | [h]elp #> Fatal Python error: (pygame parachute) Segmentation Fault
Aborted
gambler@irony:~/src/traidor$
infested999
Hero Member
*****
Offline Offline

Activity: 630



View Profile
August 15, 2011, 12:35:04 PM
 #11

What version of python should I be using?

Code:
jonny@netbook:~/traidor$ python traidor.py
Traceback (most recent call last):
  File "traidor.py", line 21, in <module>
    from wxgui import *
  File "/home/jonny/traidor/wxgui.py", line 4, in <module>
    import wx
ImportError: No module named wx
jonny@netbook:~/traidor$ python
python       python2.6    python3.2    python3.2mu 
jonny@netbook:~/traidor$ python --version
Python 2.6.7

                                                                                                   ▄███████████▄
     ▄▄████████████▄▄        █████████████████    █████████████████▄        █████████████████    ▄██▀         ▀██▄
   ▄██▀▀          ▀▀██▄                           ██              ▀▀██                           ▄▄▄           ▄▄▄
  ██▀                ▀██▄                         ██                 ██                           ▀██▄       ▄██▀
 ██                    ██                         ██                  ██                            ▀██▄   ▄██▀
██▀                                               ██                   ██                             ▀██▄██▀
██                           ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄     ██                   ██   ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄            ▀█▀
██                           ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀     ██                   ██   ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀             ▄
██▄                    ██                         ██                   ██                              ▄███▄
 ██                    ██                         ██                  ██                             ▄██▀ ▀██▄
  ██▄                ▄██▀                         ██                 ██                            ▄██▀     ▀██▄
   ▀██▄▄          ▄▄██▀                           ██              ▄▄██                           ▄██▀         ▀██▄
     ▀▀████████████▀▀        █████████████████    █████████████████▀        █████████████████  ▄██▀             ▀██▄

    ▄██████████████▄
   ▄████████████████▄
  ▄██████████████████▄
 ▄████████████████████▄
▄██
████████████████████▄
 ▀████████████████████▀
  ▀██████████████████▀
    ▀██████████████▀
      ████████████
       ▀████████▀
        ▀██████▀
          ▀██▀
          
The 1st Ever Certified Blockchain
Based Diamond Exchange ❱ ❱ ❱ ❱


█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
  █
  █
 
  █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ 
molecular
Donator
Legendary
*
Offline Offline

Activity: 2436



View Profile
August 15, 2011, 05:32:28 PM
 #12

What version of python should I be using?

Code:
jonny@netbook:~/traidor$ python traidor.py
Traceback (most recent call last):
  File "traidor.py", line 21, in <module>
    from wxgui import *
  File "/home/jonny/traidor/wxgui.py", line 4, in <module>
    import wx
ImportError: No module named wx
jonny@netbook:~/traidor$ python
python       python2.6    python3.2    python3.2mu 
jonny@netbook:~/traidor$ python --version
Python 2.6.7

The problem is you're missing wx tooklit, which I don't actually use currently anyways, so I commented out the import. Do a "git pull" and try again.

Python 2.6.7 should work, 3.2 also, probably. I have 2.6.6

PGP key molecular F9B70769 fingerprint 9CDD C0D3 20F8 279F 6BE0  3F39 FC49 2362 F9B7 0769
infested999
Hero Member
*****
Offline Offline

Activity: 630



View Profile
August 15, 2011, 07:22:17 PM
 #13

What version of python should I be using?

Code:
jonny@netbook:~/traidor$ python traidor.py
Traceback (most recent call last):
  File "traidor.py", line 21, in <module>
    from wxgui import *
  File "/home/jonny/traidor/wxgui.py", line 4, in <module>
    import wx
ImportError: No module named wx
jonny@netbook:~/traidor$ python
python       python2.6    python3.2    python3.2mu 
jonny@netbook:~/traidor$ python --version
Python 2.6.7

The problem is you're missing wx tooklit, which I don't actually use currently anyways, so I commented out the import. Do a "git pull" and try again.

Python 2.6.7 should work, 3.2 also, probably. I have 2.6.6


Thanks, that worked.

When I use the "gui" command I get this.

Code:
mtgox | 0 BTC | x.xxxxx USD | [h]elp #> gui
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python2.6/threading.py", line 532, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.6/threading.py", line 484, in run
    self.__target(*self.__args, **self.__kwargs)
  File "traidor.py", line 714, in __call__
    S.cmd(key)
  File "traidor.py", line 576, in cmd
    wx = TraidorApp(t)
NameError: global name 'TraidorApp' is not defined

Is this error just for me, or is the feature just not implemented yet?

                                                                                                   ▄███████████▄
     ▄▄████████████▄▄        █████████████████    █████████████████▄        █████████████████    ▄██▀         ▀██▄
   ▄██▀▀          ▀▀██▄                           ██              ▀▀██                           ▄▄▄           ▄▄▄
  ██▀                ▀██▄                         ██                 ██                           ▀██▄       ▄██▀
 ██                    ██                         ██                  ██                            ▀██▄   ▄██▀
██▀                                               ██                   ██                             ▀██▄██▀
██                           ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄     ██                   ██   ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄            ▀█▀
██                           ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀     ██                   ██   ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀             ▄
██▄                    ██                         ██                   ██                              ▄███▄
 ██                    ██                         ██                  ██                             ▄██▀ ▀██▄
  ██▄                ▄██▀                         ██                 ██                            ▄██▀     ▀██▄
   ▀██▄▄          ▄▄██▀                           ██              ▄▄██                           ▄██▀         ▀██▄
     ▀▀████████████▀▀        █████████████████    █████████████████▀        █████████████████  ▄██▀             ▀██▄

    ▄██████████████▄
   ▄████████████████▄
  ▄██████████████████▄
 ▄████████████████████▄
▄██
████████████████████▄
 ▀████████████████████▀
  ▀██████████████████▀
    ▀██████████████▀
      ████████████
       ▀████████▀
        ▀██████▀
          ▀██▀
          
The 1st Ever Certified Blockchain
Based Diamond Exchange ❱ ❱ ❱ ❱


█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
  █
  █
 
  █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ 
molecular
Donator
Legendary
*
Offline Offline

Activity: 2436



View Profile
August 15, 2011, 07:56:22 PM
 #14

When I use the "gui" command I get this.

Is this error just for me, or is the feature just not implemented yet?

No, gui is not implemented and doesn't have high priority at all. First comes support for other exchanges, then probably some bots.

PGP key molecular F9B70769 fingerprint 9CDD C0D3 20F8 279F 6BE0  3F39 FC49 2362 F9B7 0769
GamblingPurveyor
Member
**
Offline Offline

Activity: 75



View Profile
August 18, 2011, 03:56:31 AM
 #15

Storing the password in traidor.conf is insecure. An alternative is needed. Perhaps the password could be read from the TTY if the user doesn't provide it in traidor.conf.


Also, the program should check the $LINES and $COLUMNS environment variables every time it updates the screen, instead of having to set it manually with the d menu option.


Hmm, I tried reading $LINES from os.environ, it's not in there. while "echo $LINES" in bash works, "env | grep LINES" doesn't show it either.

Any hint for me?

It turns out that $LINES and $COLUMNS are internal to BASH. The way you really get the size of the terminal is by sending the string "\x1b[18t" (hex: 1b, 5b, 31, 38, 74) to stdout. You'll get a response in the form of "\x1b[8;L;Ct" on stdin, where L and C are the lines and columns, respectively.

To allow you to avoid having to send this sequence before every screen update, xterm will send your program the SIGWINCH signal every time the size of the window changes.
m3ta
Sr. Member
****
Offline Offline

Activity: 422



View Profile WWW
August 22, 2011, 04:15:16 AM
 #16

$ python -V
Python 2.7.1+

$ python traidor.py
Traceback (most recent call last):
  File "./traidor.py", line 17, in <module>
    from websocket import WebSocket
ImportError: Bad magic number in /btc/traidor/websocket/__init__.pyc

Why the frell so many retards spell "ect" as an abbreviation of "Et Cetera"? "ETC", DAMMIT! http://en.wikipedia.org/wiki/Et_cetera

Host:/# rm -rf /var/forum/trolls
molecular
Donator
Legendary
*
Offline Offline

Activity: 2436



View Profile
December 04, 2012, 08:50:19 PM
 #17

$ python -V
Python 2.7.1+

$ python traidor.py
Traceback (most recent call last):
  File "./traidor.py", line 17, in <module>
    from websocket import WebSocket
ImportError: Bad magic number in /btc/traidor/websocket/__init__.pyc


dude, didn't even see this. try "git pull".

PGP key molecular F9B70769 fingerprint 9CDD C0D3 20F8 279F 6BE0  3F39 FC49 2362 F9B7 0769
supert
Full Member
***
Offline Offline

Activity: 160



View Profile
April 04, 2013, 01:55:32 PM
 #18

OS X 10.6.8
stock python, macports simplejson and pygame. Couldn't find a websockets in macports, assuming already there?

I get

Code:
:~/data/bitcoin/bots/traidor$ python traidor.py
show_depth()-thread started
 starting exchanges...
request_info()
Exception in thread Thread-2:
Traceback (most recent call last):
  File "/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/threading.py", line 551, in __bootstrap_inner
    self.run()
  File "/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/threading.py", line 504, in run
    self.__target(*self.__args, **self.__kwargs)
  File "traidor.py", line 189, in __call__
    x.start()
  File "/Users/co1ass/data/bitcoin/bots/traidor/mtgox.py", line 100, in start
    S.request_info()
  File "/Users/co1ass/data/bitcoin/bots/traidor/mtgox.py", line 348, in request_info
    S.info = S.request_json_authed('/api/1/generic/private/info')['return']
  File "/Users/co1ass/data/bitcoin/bots/traidor/mtgox.py", line 313, in request_json_authed
    rc = S.request_json(url, params);
  File "/Users/co1ass/data/bitcoin/bots/traidor/mtgox.py", line 308, in request_json
    return json.load(response, use_decimal=True, object_hook=convert_certain_json_objects_to_decimal)
  File "/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/json/__init__.py", line 278, in load
    **kw)
  File "/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/json/__init__.py", line 339, in loads
    return cls(encoding=encoding, **kw).decode(s)
TypeError: __init__() got an unexpected keyword argument 'use_decimal'


Any ideas?
Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!