Bitcoin Forum
December 11, 2016, 02:07:15 PM *
News: To be able to use the next phase of the beta forum software, please ensure that your email address is correct/functional.
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: Intersango API python interface  (Read 2066 times)
phantomcircuit
Sr. Member
****
Offline Offline

Activity: 463


View Profile
September 23, 2011, 08:51:01 PM
 #1

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)
1481465235
Hero Member
*
Offline Offline

Posts: 1481465235

View Profile Personal Message (Offline)

Ignore
1481465235
Reply with quote  #2

1481465235
Report to moderator
1481465235
Hero Member
*
Offline Offline

Posts: 1481465235

View Profile Personal Message (Offline)

Ignore
1481465235
Reply with quote  #2

1481465235
Report to moderator
1481465235
Hero Member
*
Offline Offline

Posts: 1481465235

View Profile Personal Message (Offline)

Ignore
1481465235
Reply with quote  #2

1481465235
Report to moderator
"Apparently, so I am told, there exist "people" who prefer to wipe sitting down. From the front. Initial research indicates it could be up to half the population." -- benjamindees
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1481465235
Hero Member
*
Offline Offline

Posts: 1481465235

View Profile Personal Message (Offline)

Ignore
1481465235
Reply with quote  #2

1481465235
Report to moderator
1481465235
Hero Member
*
Offline Offline

Posts: 1481465235

View Profile Personal Message (Offline)

Ignore
1481465235
Reply with quote  #2

1481465235
Report to moderator
ThiagoCMC
Legendary
*
Offline Offline

Activity: 1190


฿itcoin: Currency of Resistance!


View Profile WWW
September 25, 2011, 06:23:50 AM
 #2

Hi!!

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

Best!
Thiago

Mercado Forex acessível para todos os Brasileiros que tenham Bitcoins! Cadastre-se hoje mesmo! Bastar acessar aqui: https://1broker.com/m/r.php?i=8879
runeks
Legendary
*
Offline Offline

Activity: 924



View Profile WWW
September 29, 2011, 04:27:03 AM
 #3

What is the account_id? Is it the e-mail address associated with an account?
phantomcircuit
Sr. Member
****
Offline Offline

Activity: 463


View Profile
September 29, 2011, 04:42:35 AM
 #4

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.
runeks
Legendary
*
Offline Offline

Activity: 924



View Profile WWW
September 29, 2011, 04:47:01 AM
 #5

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?
phantomcircuit
Sr. Member
****
Offline Offline

Activity: 463


View Profile
September 29, 2011, 05:00:23 AM
 #6

We can probably accommodate you, of course it depends on what you can accept.

Make a proposal and we'll think about it.
genjix
Legendary
*
Offline Offline

Activity: 1232


View Profile
September 29, 2011, 05:08:35 AM
 #7

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.
runeks
Legendary
*
Offline Offline

Activity: 924



View Profile WWW
September 29, 2011, 06:13:25 AM
 #8

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.
genjix
Legendary
*
Offline Offline

Activity: 1232


View Profile
September 29, 2011, 01:53:29 PM
 #9

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.
phantomcircuit
Sr. Member
****
Offline Offline

Activity: 463


View Profile
September 29, 2011, 06:37:03 PM
 #10

I've updated the example to show filtering for the listOrders call
runeks
Legendary
*
Offline Offline

Activity: 924



View Profile WWW
October 01, 2011, 04:43:22 PM
 #11

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)?
genjix
Legendary
*
Offline Offline

Activity: 1232


View Profile
October 02, 2011, 03:36:34 AM
 #12

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.

phantomcircuit
Sr. Member
****
Offline Offline

Activity: 463


View Profile
October 13, 2011, 11:30:54 PM
 #13

I have updated the example to include support for FOK and IOC orders.
daybyter
Legendary
*
Offline Offline

Activity: 965


View Profile
June 13, 2012, 04:17:08 PM
 #14

Does anyone know the format of the last_trade_date parameter? microseconds since the GMT epoch (1.1.1970) , or so?

phantomcircuit
Sr. Member
****
Offline Offline

Activity: 463


View Profile
June 14, 2012, 03:38:43 AM
 #15

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).
toffoo
Sr. Member
****
Offline Offline

Activity: 392



View Profile
June 14, 2012, 03:34:55 PM
 #16

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

phantomcircuit
Sr. Member
****
Offline Offline

Activity: 463


View Profile
June 15, 2012, 12:18:20 AM
 #17

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..
daybyter
Legendary
*
Offline Offline

Activity: 965


View Profile
June 15, 2012, 11:17:15 AM
 #18

Note to myself....must add a line: if( highest_bid( "Intersango").getUser().equals( "toffoo")) { break; } ... Wink

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!