Bitcoin Forum

Bitcoin => Bitcoin Discussion => Topic started by: phantomcircuit on September 23, 2011, 08:51:01 PM



Title: Intersango API python interface
Post by: phantomcircuit on September 23, 2011, 08:51:01 PM
This is a very basic framework for the intersango API in python.

Edit: updated to support states filter for orders
Edit: added support for fill or kill and immediate or cancel orders

Code:
import httplib
import urllib
import json
import decimal
import threading
import socket

class intersango:
    version = "0.1"
   
    good_til_cancelled = 'gtc'
    fill_or_kill = 'fok'
    immediate_or_cancel = 'ioc'
   
    def __init__(self,api_key):
        self.api_key=api_key
        self.connection = None
   
    def connect(self):
        if self.connection is None:
            self.connection = httplib.HTTPSConnection('intersango.com')
   
    def make_request(self,call_name,params):
        params.append(('api_key',self.api_key))
        body = urllib.urlencode(params)
       
        self.connect()
       
        try:
            self.connection.putrequest('POST','/api/authenticated/v'+self.version+'/'+call_name+'.php')
            self.connection.putheader('Connection','Keep-Alive')
            self.connection.putheader('Keep-Alive','30')
            self.connection.putheader('Content-type','application/x-www-form-urlencoded')
            self.connection.putheader('Content-length',len(body))
            self.connection.endheaders()
           
            self.connection.send(body)
           
            response = self.connection.getresponse()
           
            return json.load(response)
        except httplib.HTTPException:
            self.connection = None
            return False
        except socket.error:
            self.connection = None
            return False
       
    def list_accounts(self):
        return self.make_request('listAccounts',dict())
   
    def list_orders(self,account_id,last_order_id=None,states=None):
        params = [('account_id',account_id)]
       
        if last_order_id is not None:
            params.append(('last_order_id',last_order_id))
       
        if states is not None:
            for state in states:
                params.append(('states[]',state))
       
        return self.make_request('listOrders',params)
   
    def list_deposits(self,account_id):
        return self.make_request('listDeposits',[('account_id',account_id)])
   
    def list_withdrawal_requests(self,account_id):
        return self.make_request('listWithdrawalRequests',[('account_id',account_id)])
   
    def place_limit_order(self,quantity,rate,selling,base_account_id,quote_account_id,order_type=good_til_cancelled):
        params = []
        assert type(quantity) == decimal.Decimal
        assert type(rate) == decimal.Decimal
       
        params.append(('quantity',quantity))
        params.append(('rate',rate))
        params.append(('selling',str(selling).lower()))
        params.append(('base_account_id',base_account_id))
        params.append(('quote_account_id',quote_account_id))
        params.append(('type',order_type))
       
        return self.make_request('placeLimitOrder',params)
   
    def request_cancel_order(self,account_id,order_id):
        return self.make_request('requestCancelOrder',[('account_id',account_id),('order_id',order_id)])

b = intersango('your api key goes here')
b.place_limit_order(decimal.Decimal('10'),decimal.Decimal('2.49051'),True,1,2,intersango.immediate_or_cancel)


Title: Re: Intersango API python interface
Post by: ThiagoCMC on September 25, 2011, 06:23:50 AM
Hi!!

 This https://intersango.com/ is open sourced too?!?!?!

Best!
Thiago


Title: Re: Intersango API python interface
Post by: runeks on September 29, 2011, 04:27:03 AM
What is the account_id? Is it the e-mail address associated with an account?


Title: Re: Intersango API python interface
Post by: phantomcircuit on September 29, 2011, 04:42:35 AM
What is the account_id? Is it the e-mail address associated with an account?

account_id is the account number found on the accounts page, they're also available via the listAccounts.php API call.


Title: Re: Intersango API python interface
Post by: runeks on September 29, 2011, 04:47:01 AM
Ah, cool, thanks.

I assume you have something to do with Intersango because of your signature. So I'll ask you my important question.

I just transferred some Bitcoins to Intersango and purchased some US dollars for them. Now I have some US dollars in my account, but since I am not allowed to register an account at Dwolla (they only accept US citizens as account holders) I don't have a way to withdraw the money.

Is there no way for me to get my money back from you?


Title: Re: Intersango API python interface
Post by: phantomcircuit on September 29, 2011, 05:00:23 AM
We can probably accommodate you, of course it depends on what you can accept.

Make a proposal and we'll think about it.


Title: Re: Intersango API python interface
Post by: genjix on September 29, 2011, 05:08:35 AM
runeks, you should open a ticket on Intersango by emailing support@intersango.com and then someone will respond to solve your issue. It's better that way as we can better track tasks and assign them to the correct people appropriately.


Title: Re: Intersango API python interface
Post by: runeks on September 29, 2011, 06:13:25 AM
OK, I have done that. You might want to add a notice somewhere that your site is only designed (at the moment) for US customers, so others don't get in the same situation that I am in.


Title: Re: Intersango API python interface
Post by: genjix on September 29, 2011, 01:53:29 PM
OK, I have done that. You might want to add a notice somewhere that your site is only designed (at the moment) for US customers, so others don't get in the same situation that I am in.

Where did you get that idea? Our offices are in London, and we have accounts for British GBP, European EURO and Polish Zloty.

Info: https://intersango.com/fees.php

We aren't allowed to let people easily convert between funds as that's forex trading.


Title: Re: Intersango API python interface
Post by: phantomcircuit on September 29, 2011, 06:37:03 PM
I've updated the example to show filtering for the listOrders call


Title: Re: Intersango API python interface
Post by: runeks on October 01, 2011, 04:43:22 PM
OK, I have done that. You might want to add a notice somewhere that your site is only designed (at the moment) for US customers, so others don't get in the same situation that I am in.

Where did you get that idea? Our offices are in London, and we have accounts for British GBP, European EURO and Polish Zloty.

Info: https://intersango.com/fees.php

We aren't allowed to let people easily convert between funds as that's forex trading.
My mistake. I got the impression that withdrawals were only possible via Dwolla.

Is it possible for me to deposit USD (and not EUR) to my Intersango account via a European bank transfer (SEPA)?


Title: Re: Intersango API python interface
Post by: genjix on October 02, 2011, 03:36:34 AM
OK, I have done that. You might want to add a notice somewhere that your site is only designed (at the moment) for US customers, so others don't get in the same situation that I am in.

Where did you get that idea? Our offices are in London, and we have accounts for British GBP, European EURO and Polish Zloty.

Info: https://intersango.com/fees.php

We aren't allowed to let people easily convert between funds as that's forex trading.
My mistake. I got the impression that withdrawals were only possible via Dwolla.

Is it possible for me to deposit USD (and not EUR) to my Intersango account via a European bank transfer (SEPA)?

It should be possible, but you'll need to pay the bank's conversion fees. Email support@intersango.com and they'll fill you. List your country and bank name and they should be able to guide you through.

http://libbitcoin.org/intersango.png (https://intersango.com/)


Title: Re: Intersango API python interface
Post by: phantomcircuit on October 13, 2011, 11:30:54 PM
I have updated the example to include support for FOK and IOC orders.


Title: Re: Intersango API python interface
Post by: daybyter on June 13, 2012, 04:17:08 PM
Does anyone know the format of the last_trade_date parameter? microseconds since the GMT epoch (1.1.1970) , or so?


Title: Re: Intersango API python interface
Post by: phantomcircuit on June 14, 2012, 03:38:43 AM
Does anyone know the format of the last_trade_date parameter? microseconds since the GMT epoch (1.1.1970) , or so?

Seconds since epoch as an integer (no microsecond precision).


Title: Re: Intersango API python interface
Post by: toffoo on June 14, 2012, 03:34:55 PM
This is a very basic framework for the intersango API in python.

Cool ... maybe now someone can code up even more bots to outbid me by 0.0001 BTC every time I leave an order on that exchange


Title: Re: Intersango API python interface
Post by: phantomcircuit on June 15, 2012, 12:18:20 AM
This is a very basic framework for the intersango API in python.

Cool ... maybe now someone can code up even more bots to outbid me by 0.0001 BTC every time I leave an order on that exchange

lol..


Title: Re: Intersango API python interface
Post by: daybyter on June 15, 2012, 11:17:15 AM
Note to myself....must add a line: if( highest_bid( "Intersango").getUser().equals( "toffoo")) { break; } ... ;)