Bitcoin Forum
November 08, 2024, 07:00:29 AM *
News: Latest Bitcoin Core release: 28.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Intersango API python interface  (Read 2234 times)
phantomcircuit (OP)
Sr. Member
****
Offline Offline

Activity: 463
Merit: 252


View Profile
September 23, 2011, 08:51:01 PM
Last edit: October 13, 2011, 11:28:35 PM by phantomcircuit
 #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)
ThiagoCMC
Legendary
*
Offline Offline

Activity: 1204
Merit: 1000

฿itcoin: Currency of Resistance!


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

Hi!!

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

Best!
Thiago
runeks
Legendary
*
Offline Offline

Activity: 980
Merit: 1008



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

Activity: 463
Merit: 252


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: 980
Merit: 1008



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

Activity: 463
Merit: 252


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
Merit: 1076


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: 980
Merit: 1008



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
Merit: 1076


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

Activity: 463
Merit: 252


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: 980
Merit: 1008



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
Merit: 1076


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

Activity: 463
Merit: 252


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
Merit: 1000


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

Activity: 463
Merit: 252


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: 408
Merit: 261



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

Activity: 463
Merit: 252


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
Merit: 1000


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:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!